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

Floating-point nextUp and nextDown are unnecessarily slow for concrete types

    XMLWordPrintable

    Details

      Description

      As discussed on the Swift forums, implementations of nextUp and nextDown are unnecessarily slow for concrete types.

      For example, a specialized version of Float.nextUp that would be significantly faster is:

      extension Float {
        var nextUp: Float {
          //  Map -0 to +0, silence signaling NaNs.
          let x = self + 0.0
          if x < .infinity {
            let increment = Int32(bitPattern: x.bitPattern) >> 31 | 1
            return Float(bitPattern: x.bitPattern &+ UInt32(bitPattern: increment))
          }
          return x
        }
      }
      

      We should have efficient, specialized implementations such as this. Similar issues may apply to binade and ulp.

        Attachments

          Activity

            People

            Assignee:
            xwu Xiaodi Wu
            Reporter:
            xwu Xiaodi Wu
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: