F# PowerPack contains a numeric type BigRational
. It is implemented in F# and designed for F#, but the type should be perfectly usable from C# as well (including overloaded operators and stuff like that). PowerPack is an additional library with extra F# features, so it isn't a part of the .NET framework, but it's a supported product from Microsoft.
The BigRational
type supports all basic operators (+, /, -, *, >, <, >=, <=, ==, !=
) and I believe that it automatically keeps a normal form of the number. If you represented the number as two BigInteger
values, you'd have to implement comparison such that 1/2 equals 2/4.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…