# 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

## 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 $+\infty$.

`public static LongRational PlusInfinity { get; }`

#### Property Value

**MinusInfinity**

A value representing the number $-\infty$.

`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 of the number is finite.

`public bool IsFinite { get; }`

#### Property Value

**IsInfinite**

True of the number is infinite.

`public bool IsInfinite { get; }`

#### Property Value

**IsPlusInfinite**

True of the number is $+\infty$.

`public bool IsPlusInfinite { get; }`

#### Property Value

**IsMinusInfinite**

True of the number is $-\infty$.

`public bool IsMinusInfinite { get; }`

#### Property Value

**IsZero**

True of the number is 0.

`public bool IsZero { get; }`

#### Property Value

**IsPositive**

True of the number is $> 0$.

`public bool IsPositive { get; }`

#### Property Value

**IsNegative**

True of the number is $< 0$.

`public bool IsNegative { get; }`

#### Property Value

## Constructors

**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

**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

#### Returns

**DivRem(LongRational, LongRational, out LongRational)**

Performs a division with reminder.

`LongRational DivRem(LongRational dividend, LongRational divisor, out LongRational remainder)`

#### Parameters

`dividend`

LongRational

`divisor`

LongRational

`remainder`

out LongRational

The reminder resulting from the division.

#### Returns

LongRational

The integer result of the division.

**Pow(LongRational, Int64)**

Computes the power `baseValue`

^`exponent`

`LongRational Pow(LongRational baseValue, long exponent)`

#### Parameters

`baseValue`

LongRational

`exponent`

Int64

#### Returns

#### Exceptions

**LeastCommonDenominator(LongRational, LongRational)**

The LCD is the least common multiple of the two denominators. For instance, the LCD of $\frac{1}{2}, \frac{1}{4}$ is 4 because the least common multiple of 2 and 4 is 4. Likewise, the LCD of $\frac{1}{2}, \frac{1}{3}$ is 6.

To find the LCD: Find the Greatest Common Divisor (GCD) of the denominators Multiply the denominators together Divide the product of the denominators by the GCD

`long LeastCommonDenominator(LongRational x, LongRational y)`

#### Parameters

#### Returns

**GreatestCommonDivisor(LongRational, LongRational)**

Greatest Common Divisor of the two numbers.

`LongRational GreatestCommonDivisor(LongRational a, LongRational b)`

#### Parameters

#### Returns

**GreatestCommonDivisor(Int64, Int64)**

Greatest Common Divisor of the two numbers.

`long GreatestCommonDivisor(long a, long b)`

#### Parameters

`a`

Int64

`b`

Int64

#### Returns

**LeastCommonMultiple(LongRational, LongRational)**

Least Common Multiple of the two numbers.

`LongRational LeastCommonMultiple(LongRational a, LongRational b)`

#### Parameters

#### Returns

**Compare(LongRational, LongRational)**

Compares two values and returns an integer that indicates whether the first value is less than, equal to, or greater than the second value.

`int Compare(LongRational r1, LongRational r2)`

#### Parameters

`r1`

LongRational

The first value to compare.

`r2`

LongRational

The second value to compare.

#### Returns

Int32

A signed integer that indicates the relative values of and , as shown in the following table. ValueConditionLess than zero is less than .Zero equals .Greater than zero is greater than .

**Max(LongRational, LongRational)**

Max of the two numbers.

`LongRational Max(LongRational a, LongRational b)`

#### Parameters

#### Returns

**Max(LongRational, LongRational, LongRational)**

Max of the three numbers.

`LongRational Max(LongRational a, LongRational b, LongRational c)`

#### Parameters

#### Returns

**Min(LongRational, LongRational)**

Min of the two numbers.

`LongRational Min(LongRational a, LongRational b)`

#### Parameters

#### Returns

**Min(LongRational, LongRational, LongRational)**

Min of the three numbers.

`LongRational Min(LongRational a, LongRational b, LongRational c)`