Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1431

Unary minus does not implement IEEE 754 standard

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: OTP 23
    • Fix Version/s: 24.0
    • Component/s: erts
    • Labels:
      None

      Description

      All operations seem to properly handle negative zeros. For example:

      1> <<(0.0 * -1)/float>>.
      <<128,0,0,0,0,0,0,0>>
      

      But not unary minus. That's because unary minus today is implemented as "0-value" but for floats "0-value" is not the same as "-value" (even though both positive and negative zeros are equal they have different representations).

      PS: I have attempted to fix this by implementing erts_unary_minus as a specialization of the current erts_mixed_minus. It seemed to work fine for floats but I messed something up and I got segfaults for bignums. In any case, it seems even the bignum implementation could be specialized by simply flipping the sign? Someone more competent than me will surely know the answer. Thank you!

        Attachments

          Activity

            People

            Assignee:
            bjorn Björn Gustavsson
            Reporter:
            josevalim José Valim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: