[swift-users] Generic math macros on Linux
Timothy Chagnon
tachagnon at gmail.com
Thu Jan 28 01:23:00 CST 2016
Hi folks,
I ran into this issue (or at least surprise) trying to compile some code
that uses math.h functions on both OSX and Linux. Here's an example:
#if os(Linux)
import Glibc
#else
import Darwin
#endif
let x = Float(1.2345)
let y = sin(x)
print(y)
Compiles and runs fine on OSX, but fails with the following error on Linux:
*MathTest.swift:8:13: error: cannot convert value of type 'Float' to
expected argument type 'Double'*
I think I tracked this down to the fact that Darwin includes the
additional tgmath
style macros
<https://github.com/apple/swift/blob/master/stdlib/public/SDK/Darwin/tgmath.swift.gyb#L44>
that provide the overloaded sin(x: Float) -> Float swift function. Glibc
only includes plain math.h functions:
double sin(double x);
float sinf(float x);
I can, of course, just use the explicit *f math.h functions on both
platforms. But I'm curious if this is a bug I should file or if this is
intentional to not have overloaded math functions in Swift. I couldn't
find much mention of it in the bug tracker.
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160128/43fced04/attachment.html>
More information about the swift-users
mailing list