Skip to content
ntysdd's blog

Archives

All the articles I've archived.

20264
November1
  • Two NaNs, One Expression: The Bits Nobody Promised

    Updated:

    `0.0 / 0.0` gives one NaN when `javac` folds it and a different one when the CPU divides it, on the same JVM. The JVM spec leaves the bit pattern to the hardware and IEEE 754 does not specify it either, so my port now only promises the finite results.

October3
  • One in 2^62: When `(int)(x + 0.5)` Rounds the Wrong Way

    Updated:

    `(int)(x + 0.5)` returns the wrong integer for exactly one non-negative double whose cast to `int` is defined, and for four million non-negative floats. The `long long` version is wrong for half of the nanosecond timestamps in one `2^52`-wide window.

  • How To Implement a Correctly-rounded powf(x, 3)

    Updated:

    `x * x * x` is wrong for about 8.5% of all positive finite float32 inputs, while there actually is an easy way to implement a correctly-rounded one.

  • One ULP Off: A Floating-Point Bug That Wasn't in the C Runtime I Blamed

    Some doubles came back one bit off when parsed, and the culprit was not the 30-year-old CRT I had linked against — it was the C99 stdio shim sitting on top of it, which parses floating point through 80-bit long double. A short story about double rounding, and about verifying which function you actually call.