3 ms·
I mean, the point was probably to teach some complex analysis and topology along the way. You could just x += 2*sgn(x) if z < 0, sacrificing the least signific
by mike_hock 7y ago
I mean, the point was probably to teach some complex analysis and topology along the way.
You could just x += 2*sgn(x) if z < 0, sacrificing the least significant bit of x in a way that doesn't require any bit hacks (so on restoration, z < 0 iff abs(x) >= 2, and the excess +/-2 is easy to remove from x since the real x <= 1).
- gpm 7y agoIf we are using floats, couldn't we just store the sign of z in the sign bit of the exponent of x with no loss of precision since it should always be negative for a number in [-1, 1]. Which is only possible because storing a number in [-1, 1] in a float is wasting a bit of space, but everyone does it.