Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

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?

0 comments

rep_lodsb

Reply

No comments yet

Contribute on Hacker News ↗

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities