LongRational
Represents a rational number with finite precision, using Int64 for both numerator and denominator.
Adapted from BigRational with the aim of reducing perfomance impact from the use of BigInteger.
public struct LongRational
Inheritance Object → ValueType → LongRational
Implements IComparable, IComparable<LongRational>, IEquatable<LongRational>, IToCodeString, IStableHashCode
Properties
Zero
A value representing the number 0.
public static LongRational Zero { get; }
Property Value
One
A value representing the number 1.
public static LongRational One { get; }
Property Value
MinusOne
A value representing the number -1.
public static LongRational MinusOne { get; }
Property Value
PlusInfinity
A value representing the number .
public static LongRational PlusInfinity { get; }
Property Value
MinusInfinity
A value representing the number .
public static LongRational MinusInfinity { get; }
Property Value
Sign
Returns an integer that indicates the sign of the rational
public int Sign { get; }
Property Value
Numerator
The numerator of the rational.
public long Numerator { get; private set; }
Property Value
Denominator
The denominator of the rational.
public long Denominator { get; private set; }
Property Value
IsFinite
True if the number is finite.
public bool IsFinite { get; }
Property Value
IsInfinite
True if the number is infinite.
public bool IsInfinite { get; }
Property Value
IsPlusInfinite
True if the number is .
public bool IsPlusInfinite { get; }
Property Value
IsMinusInfinite
True if the number is .
public bool IsMinusInfinite { get; }
Property Value
IsZero
True if the number is 0.
public bool IsZero { get; }
Property Value
IsPositive
True if the number is .
public bool IsPositive { get; }
Property Value
IsNegative
True if the number is .
public bool IsNegative { get; }
Property Value
IsInteger
True if the number is an integer.
public bool IsInteger { get; }
Property Value
Constructors
LongRational(Int32, Int32)
Constructor.
LongRational(int numerator, int denominator)
Parameters
numerator Int32
denominator Int32
Exceptions
LongRational(Int64, Int64)
Constructor.
LongRational(long numerator, long denominator)
Parameters
numerator Int64
denominator Int64
Exceptions
LongRational(Int64)
Constructor.
LongRational(long numerator)
Parameters
numerator Int64
LongRational(Decimal)
Constructor.
The Decimal type represents floating point numbers exactly, with no rounding error.
Values such as 0.1 in Decimal are actually representable, and convert cleanly to BigRational as 1/10.
LongRational(decimal value)
Parameters
value Decimal
Methods
GetWholePart()
long GetWholePart()
Returns
GetFractionPart()
LongRational GetFractionPart()
Returns
Floor()
long Floor()
Returns
Ceil()
long Ceil()
Returns
Equals(Object)
bool Equals(object obj)
Parameters
obj Object
Returns
GetHashCode()
int GetHashCode()
Returns
GetStableHashCode()
A stable hashcode.
int GetStableHashCode()
Returns
CompareTo(LongRational)
int CompareTo(LongRational other)
Parameters
other LongRational
Returns
ToString()
string ToString()
Returns
ToCodeString(Boolean, Int32)
Returns a string containing C# code to create this LongRational. 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(LongRational)
bool Equals(LongRational other)
Parameters
other LongRational
Returns
Abs(LongRational)
The absolute value of the number.
LongRational Abs(LongRational r)
Parameters
Returns
Negate(LongRational)
The opposite of the number.
LongRational Negate(LongRational r)
Parameters
Returns
Invert(LongRational)
The inverse of the number.
LongRational Invert(LongRational r)
Parameters
Returns
Add(LongRational, LongRational)
The sum of the two numbers.
LongRational Add(LongRational x, LongRational y)
Parameters
Returns
Subtract(LongRational, LongRational)
The difference of the two numbers.
LongRational Subtract(LongRational x, LongRational y)
Parameters
Returns
Multiply(LongRational, LongRational)
The product of the two numbers.
LongRational Multiply(LongRational x, LongRational y)
Parameters
Returns
Divide(LongRational, LongRational)
The division of the two numbers.
LongRational Divide(LongRational dividend, LongRational divisor)
Parameters
dividend LongRational
divisor LongRational
Returns
Remainder(LongRational, LongRational)
The remainder of the two numbers.
LongRational Remainder(LongRational dividend, LongRational divisor)
Parameters
dividend LongRational
divisor LongRational