Razenpok / BreakInfinity.cs

Double replacement for numbers that go over 1e308
MIT License
212 stars 33 forks source link

> comparison operator doesn't work when comparing finite number with exponent greater than 0 to positive infinity. #9

Open ThisIsNoZaku opened 4 years ago

ThisIsNoZaku commented 4 years ago

I am implementing a cap on a value using BigInteger.Min, using PositiveInfinity to essentially mean "no cap". However, I found that when the value reached 10 (which changed the exponent), Min would return that Infinity was the smaller value!

Min defers to the > operator, and the exponent for infinity is actually 0, where the line which perform the comparison is this: if (a.Mantissa > 0) return b.Mantissa < 0 || a.Exponent > b.Exponent; where a = 10 and b = Infinity. Since the mantissa of a is 1 and larger than 0, the comparison is b.Mantissa < 0 (false) || a.Exponent (1) > b.Exponent (0) or false || true, thus, Infinity is smaller than 10.