Uploaded image for project: 'Swift'
  1. Swift
  2. SR-1011

Fix Swift's min and max

    XMLWordPrintable

    Details

      Description

      In Swift, max and min of some number and nan will either give the number or nan depending on the order of the arguments.

      I'd expect Swift's min and max to follow IEEE-754, so all of the following should print 1.0, same as Darwin's fmin and fmax does:

      import Darwin
      print(min(1.0, Double.NaN)) // 1.0
      print(min(Double.NaN, 1.0)) // nan
      print(max(1.0, Double.NaN)) // 1.0
      print(max(Double.NaN, 1.0)) // nan
      
      print(fmin(1.0, Double.NaN)) // 1.0
      print(fmin(Double.NaN, 1.0)) // 1.0
      print(fmax(1.0, Double.NaN)) // 1.0
      print(fmax(Double.NaN, 1.0)) // 1.0
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              jens Jens Persson
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated: