News for hackers. Stuff that matters.
Re:9999999999999999.0 – 9999999999999998.0 by dbaupp on Sunday January 06, 2019 @01:36AM (#18836940)
I believe IEEE754 floats have that subtraction/addition guarantee (as long as the hardware doesn't map subnormals to zero). The problem in this case is the input numbers are rounded when they are converted from text/decimal to a float, and so aren't exact.
Re:9999999999999999.0 – 9999999999999998.0 by int_19h on Sunday January 06, 2019 @09:00PM (#18842165)
> I believe IEEE754 floats have that subtraction/addition guarantee (as long as the hardware doesn't map subnormals to zero).

They don't - all 11 bits of the exponent (for float64) are in use, so you can have something like 1e300, and then you can't e.g. add 1 to it and get a different number.

   >>> x = 1e100
   >>> x
   1e+100

   >>> y = x + 1
   >>> y
   1e+100

   >>> x - y
   0.0
Re:9999999999999999.0 – 9999999999999998.0 by dbaupp on Tuesday January 08, 2019 @04:34PM (#18859944)
That's something else: x == y, so the difference must be 0. What you said above is

  if x != y, x - y != 0
which holds for all x and y, but is different to

  if dx != 0, x + dx != x
which fails for some (many!) x and dx.