Skip to content

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

@ThisIsNoZaku

Description

@ThisIsNoZaku

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions