[swift-users] Unsupported Float80 math functions and min/max behavior with Nan

Alex Blewitt alblue at apple.com
Fri May 26 05:58:28 CDT 2017


> On 26 May 2017, at 11:01, Antonino Ficarra via swift-users <swift-users at swift.org> wrote:
> 
> - Why Swift continues to not support Float80 math functions?
> Example:
> 
> print("\( log( Float( 1.0 ) ) )")
> print("\( log( Double( 1.0 ) ) )")
> // print("\( log( Float80( 1.0 ) ) )")	// don’t compile and logl is unavailable

In this case, it's because 'log' only is defined for Float and Double:

	log(Double) -> Double
	log(x: Double) -> Double
	log(x: Float) -> Float

The problem is that Float80 types are represented in C as long double, and currently the importer doesn't import things with long doubles. As a result, logl doesn't get imported which is why it's not seen:

     #include <math.h>

     double
     log(double x);

     long double
     logl(long double x);

The ones that do have Float80 support are done by hand, e.g.:

https://github.com/apple/swift/blob/19445cdb0e99eedf22390922e077d86f12123390/stdlib/public/SwiftShims/LibcShims.h#L138

The open bug is here, if you want to follow it:

https://bugs.swift.org/browse/SR-2046

> 
> - Why min and max continue to not act like fmin and fmax (IEEE 754 standard)?
> Example:
> 
> print("\( min( Double.nan,0.0 ) )")	// print nan (!)
> print("\( min( 0.0,Double.nan ) )")	// print 0.0
> print("\( max( Double.nan,0.0 ) )")	// print nan (!)
> print("\( max( 0.0,Double.nan ) )")	// print 0.0
> print("\n")
> 
> print("\( fmin( Double.nan,0.0 ) )")	// print 0.0
> print("\( fmin( 0.0,Double.nan ) )")	// print 0.0
> print("\( fmax( Double.nan,0.0 ) )")	// print 0.0
> print("\( fmax( 0.0,Double.nan ) )")	// print 0.0

There is another open bug here:

https://bugs.swift.org/browse/SR-1011 <https://bugs.swift.org/browse/SR-1011>

Can you add your observations to that?

Thanks,

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170526/400cb9f4/attachment.html>


More information about the swift-users mailing list