Comment by GeoAtreides

Comment by GeoAtreides a day ago

3 replies

I'm willing to bet it was was done for performance reasons, subtraction is cheaper than float point division. Probably the compiler also has some tricks to optimize this further.

There is absolutely no way this could turn into an infinite loop. It could underflow, but for that to happen angle would have to be less than the 2*pi, therefore exiting the loop.

auxiliarymoose a day ago

The article discusses how that turns into an infinite loop and causes a hang.

When you subtract a small float from a very large float, the value doesn't change. This is because the "steps" between float values increase with the size of the value (i.e. floats have coarser resolution for larger magnitudes)

To see this in action, try running the following in a JavaScript interpreter:

console.log(1_000_000_000_000_000_000 - 1);

  • MBCook a day ago

    But that’s “impossible”. It’s an angle between 0 and 2pi. When transformed it might go over a bit so they added the check.

    It will “never” become big.

    So why check? It’s unnecessary.

    Thus the bug.

mabster a day ago

If m_fBladeAngle is really large (>2.2e8 back of the envelope), the subtraction will have no effect, and that would be an infinite loop.