Rational
Represents a rational number with infinite precision, using BigInteger for both numerator and denominator.
This type is identical to BigRational based to compiler flag BIG_RATIONAL. Replace this with LONG_RATIONAL to change implementation to LongRational.
public struct Rational
Inheritance Object → ValueType → Rational
Implements IComparable, IComparable<Rational>, IEquatable<Rational>, IToCodeString
Properties
Zero
public static Rational Zero { get; }
Property Value
One
public static Rational One { get; }
Property Value
MinusOne
public static Rational MinusOne { get; }
Property Value
PlusInfinity
public static Rational PlusInfinity { get; }
Property Value
MinusInfinity
public static Rational MinusInfinity { get; }
Property Value
Sign
public int Sign { get; }
Property Value
Numerator
public BigInteger Numerator { get; private set; }
Property Value
Denominator
public BigInteger Denominator { get; private set; }
Property Value
IsFinite
public bool IsFinite { get; }
Property Value
IsInfinite
public bool IsInfinite { get; }
Property Value
IsPlusInfinite
public bool IsPlusInfinite { get; }
Property Value
IsMinusInfinite
public bool IsMinusInfinite { get; }
Property Value
IsZero
public bool IsZero { get; }
Property Value
IsPositive
public bool IsPositive { get; }
Property Value
IsNegative
public bool IsNegative { get; }
Property Value
Constructors
Rational(Int32, Int32)
Rational(int numerator, int denominator)
Parameters
numerator
Int32
denominator
Int32
Rational(BigInteger)
Rational(BigInteger numerator)
Parameters
numerator
BigInteger
Rational(Decimal)
Rational(decimal value)
Parameters
value
Decimal
Rational(BigInteger, BigInteger)
Rational(BigInteger numerator, BigInteger denominator)
Parameters
numerator
BigInteger
denominator
BigInteger
Rational(BigInteger, BigInteger, BigInteger)
Rational(BigInteger whole, BigInteger numerator, BigInteger denominator)
Parameters
whole
BigInteger
numerator
BigInteger
denominator
BigInteger
Methods
GetWholePart()
BigInteger GetWholePart()
Returns
GetFractionPart()
Rational GetFractionPart()
Returns
Floor()
BigInteger Floor()
Returns
Ceil()
BigInteger Ceil()
Returns
FastFloor()
int FastFloor()
Returns
FastCeil()
int FastCeil()
Returns
Equals(Object)
bool Equals(object obj)
Parameters
obj
Object
Returns
GetHashCode()
int GetHashCode()
Returns
CompareTo(Rational)
int CompareTo(Rational other)
Parameters
other
Rational
Returns
ToString()
string ToString()
Returns
ToCodeString(Boolean, Int32)
Returns a string containing C# code to create this Rational. Useful to copy and paste from a debugger into another test or notebook for further investigation.
string ToCodeString(bool formatted, int indentation)
Parameters
formatted
Boolean
indentation
Int32
Returns
Equals(Rational)
bool Equals(Rational other)
Parameters
other
Rational
Returns
Abs(Rational)
Rational Abs(Rational r)
Parameters
r
Rational
Returns
Negate(Rational)
Rational Negate(Rational r)
Parameters
r
Rational
Returns
Invert(Rational)
Rational Invert(Rational r)
Parameters
r
Rational
Returns
Add(Rational, Rational)
Rational Add(Rational x, Rational y)
Parameters
x
Rational
y
Rational
Returns
Subtract(Rational, Rational)
Rational Subtract(Rational x, Rational y)
Parameters
x
Rational
y
Rational
Returns
Multiply(Rational, Rational)
Rational Multiply(Rational x, Rational y)
Parameters
x
Rational
y
Rational
Returns
Divide(Rational, Rational)
Rational Divide(Rational dividend, Rational divisor)
Parameters
dividend
Rational
divisor
Rational
Returns
Remainder(Rational, Rational)
Rational Remainder(Rational dividend, Rational divisor)
Parameters
dividend
Rational
divisor
Rational
Returns
DivRem(Rational, Rational, out Rational)
Rational DivRem(Rational dividend, Rational divisor, out Rational remainder)
Parameters
dividend
Rational
divisor
Rational
remainder
out Rational
Returns
Pow(Rational, BigInteger)
Rational Pow(Rational baseValue, BigInteger exponent)
Parameters
baseValue
Rational
exponent
BigInteger
Returns
LeastCommonDenominator(Rational, Rational)
BigInteger LeastCommonDenominator(Rational x, Rational y)
Parameters
x
Rational
y
Rational
Returns
GreatestCommonDivisor(Rational, Rational)
Rational GreatestCommonDivisor(Rational a, Rational b)
Parameters
a
Rational
b
Rational
Returns
LeastCommonMultiple(Rational, Rational)
Rational LeastCommonMultiple(Rational a, Rational b)
Parameters
a
Rational
b
Rational
Returns
Compare(Rational, Rational)
int Compare(Rational r1, Rational r2)
Parameters
r1
Rational
r2
Rational
Returns
Max(Rational, Rational)
Rational Max(Rational a, Rational b)
Parameters
a
Rational
b
Rational
Returns
Max(Rational, Rational, Rational)
Rational Max(Rational a, Rational b, Rational c)
Parameters
a
Rational
b
Rational
c
Rational
Returns
Min(Rational, Rational)
Rational Min(Rational a, Rational b)
Parameters
a
Rational
b
Rational
Returns
Min(Rational, Rational, Rational)
Rational Min(Rational a, Rational b, Rational c)
Parameters
a
Rational
b
Rational
c
Rational