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.
I am implementing a cap on a value using
BigInteger.Min
, usingPositiveInfinity
to essentially mean "no cap". However, I found that when the value reached 10 (which changed the exponent),Min
would return thatInfinity
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;
wherea
= 10 andb
= Infinity. Since the mantissa of a is 1 and larger than 0, the comparison isb.Mantissa < 0 (false) || a.Exponent (1) > b.Exponent (0)
orfalse || true
, thus, Infinity is smaller than 10.