BreakInfinity.cs icon indicating copy to clipboard operation
BreakInfinity.cs copied to clipboard

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

Open ThisIsNoZaku opened this issue 5 years ago • 0 comments

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.

ThisIsNoZaku avatar Mar 15 '20 08:03 ThisIsNoZaku