spire
spire copied to clipboard
Fast-path for rounding `Real`
https://github.com/typelevel/spire/blob/c0d1ca7809c7a78e9662e382cdb10bd7b96df6d2/core/src/main/scala/spire/math/Real.scala#L583
Pointed out by @s5bug on Discord.
hmm why does it do this instead of a bitshift? I assume it's something like 0b1.01 should round to 0b1.1, but you can just check a bit for that instead of having to do a whole GCD
I'm also guessing that a bitshift can be done in any place where a rational with a power-of-two denominator is used. Such as the division by four in addition.