Always false float comparisons
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 15 23:14:52 PDT 2016
On Sunday, 15 May 2016 at 22:34:24 UTC, Walter Bright wrote:
> So far, nobody has posted a legitimate one (i.e. not contrived).
Oh, so comparing the exact same calculation, using the exact same
binary executable function, is not a legitimate algorithm. It is
the most trivial thing to do and rather common. It should be
_very_ convincing.
But hey, here is another one:
const real x = f();
assert(0<=x && x<1);
x += 1;
const float f32 = cast(float)(x);
const real residue = x - cast(real)f32; // ZERO!!!!
output(dither(f32, residue)); // DITHERING IS FUBAR!!!
More information about the Digitalmars-d
mailing list