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

BinaryFloatingPoint._convert rounds differently from concrete floating-point initializers

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Standard Library
    • Labels:
      None

      Description

      Consider the following example:

      let a = Float.greatestFiniteMagnitude
      let b = a.ulp / 2
      let c = Double(a) + Double(b)
      print(Float.init(c))           // inf
      print(Float._convert(from: c)) // (value: 3.4028235e+38, exact: false)
      

      Similarly, there are other mismatched conversions:

      Found mismatched conversion (after 805306368 matching conversions):
       Double:   0_01111111111_0000000000000000000000110000000000000000000000000000 1.0000001788139343
       concrete: 0_01111111_00000000000000000000010 1.0000002
       generic:  0_01111111_00000000000000000000001 1.0000001
      Found mismatched conversion (after 1073741823 matching conversions):
       Double:   0_01111111111_0000000000000000000001110000000000000000000000000000 1.0000004172325134
       concrete: 0_01111111_00000000000000000000100 1.0000005
       generic:  0_01111111_00000000000000000000011 1.0000004
      Found mismatched conversion (after 1073741823 matching conversions):
       Double:   0_01111111111_0000000000000000000010110000000000000000000000000000 1.0000006556510925
       concrete: 0_01111111_00000000000000000000110 1.0000007
       generic:  0_01111111_00000000000000000000101 1.0000006
      

      (Thanks to Jens Persson for reporting this on Swift Forums)

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: