[swift-users] Generic math macros on Linux
Dmitri Gribenko
gribozavr at gmail.com
Thu Jan 28 01:35:13 CST 2016
On Wed, Jan 27, 2016 at 11:23 PM, Timothy Chagnon via swift-users
<swift-users at swift.org> wrote:
> 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 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.
Yes, Glibc module is lacking an overlay for tgmath. Please file a bug.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the swift-users
mailing list