Skip to main content

Rational

Represents a rational number with infinite precision, using BigInteger for both numerator and denominator.

note

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 ObjectValueTypeRational
Implements IComparable, IComparable<Rational>, IEquatable<Rational>, IToCodeString, IStableHashCode

Properties

Zero

public static Rational Zero { get; }

Property Value

Rational

One

public static Rational One { get; }

Property Value

Rational

MinusOne

public static Rational MinusOne { get; }

Property Value

Rational

PlusInfinity

public static Rational PlusInfinity { get; }

Property Value

Rational

MinusInfinity

public static Rational MinusInfinity { get; }

Property Value

Rational

Sign

public int Sign { get; }

Property Value

Int32

Numerator

public BigInteger Numerator { get; private set; }

Property Value

BigInteger

Denominator

public BigInteger Denominator { get; private set; }

Property Value

BigInteger

IsFinite

public bool IsFinite { get; }

Property Value

Boolean

IsInfinite

public bool IsInfinite { get; }

Property Value

Boolean

IsPlusInfinite

public bool IsPlusInfinite { get; }

Property Value

Boolean

IsMinusInfinite

public bool IsMinusInfinite { get; }

Property Value

Boolean

IsZero

public bool IsZero { get; }

Property Value

Boolean

IsPositive

public bool IsPositive { get; }

Property Value

Boolean

IsNegative

public bool IsNegative { get; }

Property Value

Boolean

Constructors

Rational(Int32, Int32)

Rational(int numerator, int denominator)

Parameters

numerator Int32

denominator Int32

Rational(Int64, Int64)

Rational(long numerator, long denominator)

Parameters

numerator Int64

denominator Int64

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

BigInteger

GetFractionPart()

Rational GetFractionPart()

Returns

Rational

Floor()

BigInteger Floor()

Returns

BigInteger

Ceil()

BigInteger Ceil()

Returns

BigInteger

FastFloor()

int FastFloor()

Returns

Int32

FastCeil()

int FastCeil()

Returns

Int32

Equals(Object)

bool Equals(object obj)

Parameters

obj Object

Returns

Boolean

GetHashCode()

int GetHashCode()

Returns

Int32

GetStableHashCode()

A stable hashcode.

int GetStableHashCode()

Returns

Int32

CompareTo(Rational)

int CompareTo(Rational other)

Parameters

other Rational

Returns

Int32

ToString()

string ToString()

Returns

String

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

String

Equals(Rational)

bool Equals(Rational other)

Parameters

other Rational

Returns

Boolean

Abs(Rational)

Rational Abs(Rational r)

Parameters

r Rational

Returns

Rational

Negate(Rational)

Rational Negate(Rational r)

Parameters

r Rational

Returns

Rational

Invert(Rational)

Rational Invert(Rational r)

Parameters

r Rational

Returns

Rational

Add(Rational, Rational)

Rational Add(Rational x, Rational y)

Parameters

x Rational

y Rational

Returns

Rational

Subtract(Rational, Rational)

Rational Subtract(Rational x, Rational y)

Parameters

x Rational

y Rational

Returns

Rational

Multiply(Rational, Rational)

Rational Multiply(Rational x, Rational y)

Parameters

x Rational

y Rational

Returns

Rational

Divide(Rational, Rational)

Rational Divide(Rational dividend, Rational divisor)

Parameters

dividend Rational

divisor Rational

Returns

Rational

Remainder(Rational, Rational)

Rational Remainder(Rational dividend, Rational divisor)

Parameters

dividend Rational

divisor Rational

Returns

Rational

DivRem(Rational, Rational, out Rational)

Rational DivRem(Rational dividend, Rational divisor, out Rational remainder)

Parameters

dividend Rational

divisor Rational

remainder out Rational

Returns

Rational

Pow(Rational, BigInteger)

Rational Pow(Rational baseValue, BigInteger exponent)

Parameters

baseValue Rational

exponent BigInteger

Returns

Rational

LeastCommonDenominator(Rational, Rational)

BigInteger LeastCommonDenominator(Rational x, Rational y)

Parameters

x Rational

y Rational

Returns

BigInteger

GreatestCommonDivisor(Rational, Rational)

Rational GreatestCommonDivisor(Rational a, Rational b)

Parameters

a Rational

b Rational

Returns

Rational

LeastCommonMultiple(Rational, Rational)

Rational LeastCommonMultiple(Rational a, Rational b)

Parameters

a Rational

b Rational

Returns

Rational

Compare(Rational, Rational)

int Compare(Rational r1, Rational r2)

Parameters

r1 Rational

r2 Rational

Returns

Int32

Max(Rational, Rational)

Rational Max(Rational a, Rational b)

Parameters

a Rational

b Rational

Returns

Rational

Max(Rational, Rational, Rational)

Rational Max(Rational a, Rational b, Rational c)

Parameters

a Rational

b Rational

c Rational

Returns

Rational

Min(Rational, Rational)

Rational Min(Rational a, Rational b)

Parameters

a Rational

b Rational

Returns

Rational

Min(Rational, Rational, Rational)

Rational Min(Rational a, Rational b, Rational c)

Parameters

a Rational

b Rational

c Rational

Returns

Rational