Implementation of rational number arithmetics for .NET, written in C#
- implicit conversions - rationals integrate seamlessly with other number types
- unlimited precision - rationals use BigInteger inside
- canonical form - each rational can have its canonical form (irreducible fraction where denominator is always positive)
- separate whole and fractional part - any rational number can be separated into a whole part (integer quotient aka result of integer division) and fractional part (reminder of the integral division aka result of modulo operation)
- comparison & equality
- multiple formatting options - ToString("C") (canonical form), ToString("W") (whole + fractional part), or normal fraction format
- continued fraction expansion - expand rational numbers to continued fraction (sequence of coefficients), construct rational numbers from sequence of continued fraction coefficients
Rational left = (Rational) 1 / 2;
Rational right = (Rational) 1 / 4;
Rational sum = left + right; // equals to: 3 / 4
See the version list below for details.
Install-Package Rationals -Version 1.1.1
dotnet add package Rationals --version 1.1.1
<PackageReference Include="Rationals" Version="1.1.1" />
paket add Rationals --version 1.1.1
This package has no dependencies.
This package is not used by any popular GitHub repositories.