Comment by rep_lodsb
2 hours ago
Possibly better solution:
let m = x.to_bits() & f32::MANTISSA_MASK;
return f32::from_bits(x.to_bits() ^ (m & (m-1));
Isolate mantissa, clear lowest bit in it, return bit difference as new float. Any problems with this?
No comments yet
Contribute on Hacker News ↗