spire icon indicating copy to clipboard operation
spire copied to clipboard

Fast-path for rounding `Real`

Open armanbilge opened this issue 4 years ago • 1 comments

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

armanbilge avatar Dec 10 '21 14:12 armanbilge

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.

s5bug avatar Dec 10 '21 17:12 s5bug