PeterO.Numbers.ERational

## PeterO.Numbers.ERational

public sealed class ERational :
    System.IComparable,
    System.IEquatable

Represents an arbitrary-precision rational number. This class can’t be inherited. (The “E” stands for “extended”, meaning that instances of this class can be values other than numbers proper, such as infinity and not-a-number.) In this class, a rational number consists of a numerator and denominator, each an arbitrary-precision integer (EInteger), and this class does not automatically convert rational numbers to lowest terms. Thread safety: Instances of this class are immutable, so they are inherently safe for use by multiple threads. Multiple instances of this object with the same properties are interchangeable, so they should not be compared using the “==” operator (which might only check if each side of the operator is the same instance).

Member Summary

### ERational Constructor

public ERational(
    PeterO.Numbers.EInteger numerator,
    PeterO.Numbers.EInteger denominator);

Deprecated. Use the Create method instead.

Initializes a new instance of the PeterO.Numbers.ERational class.

Parameters:

Exceptions:

### NaN

public static readonly PeterO.Numbers.ERational NaN;

A not-a-number value.

### NegativeInfinity

public static readonly PeterO.Numbers.ERational NegativeInfinity;

Negative infinity, less than any other number.

### NegativeZero

public static readonly PeterO.Numbers.ERational NegativeZero;

A rational number for negative zero.

### One

public static readonly PeterO.Numbers.ERational One;

The rational number one.

### PositiveInfinity

public static readonly PeterO.Numbers.ERational PositiveInfinity;

Positive infinity, greater than any other number.

### SignalingNaN

public static readonly PeterO.Numbers.ERational SignalingNaN;

A signaling not-a-number value.

### Ten

public static readonly PeterO.Numbers.ERational Ten;

The rational number ten.

### Zero

public static readonly PeterO.Numbers.ERational Zero;

A rational number for zero.

### Denominator

public PeterO.Numbers.EInteger Denominator { get; }

Gets this object’s denominator.

Returns:

This object’s denominator.

### IsFinite

public bool IsFinite { get; }

Gets a value indicating whether this object is finite (not infinity or NaN).

Returns:

true if this object is finite (not infinity or NaN); otherwise, false .

### IsNegative

public bool IsNegative { get; }

Gets a value indicating whether this object’s value is negative (including negative zero).

Returns:

true if this object’s value is negative (including negative zero); otherwise, false . true if this object’s value is negative; otherwise, false .

### IsZero

public bool IsZero { get; }

Gets a value indicating whether this object’s value equals 0.

Returns:

true if this object’s value equals 0; otherwise, false . true if this object’s value equals 0; otherwise, false .

### Numerator

public PeterO.Numbers.EInteger Numerator { get; }

Gets this object’s numerator.

Returns:

This object’s numerator. If this object is a not-a-number value, returns the diagnostic information (which will be negative if this object is negative).

### Sign

public int Sign { get; }

Gets the sign of this rational number.

Returns:

The sign of this rational number.

### UnsignedNumerator

public PeterO.Numbers.EInteger UnsignedNumerator { get; }

Gets this object’s numerator with the sign removed.

Returns:

This object’s numerator. If this object is a not-a-number value, returns the diagnostic information.

### Abs

public PeterO.Numbers.ERational Abs();

Returns the absolute value of this rational number, that is, a number with the same value as this one but as a nonnegative number.

Return Value:

An arbitrary-precision rational number.

### Add

public PeterO.Numbers.ERational Add(
    int v);

Adds this arbitrary-precision rational number and a 32-bit signed integer and returns the result.

Parameters:

Return Value:

The sum of the two numbers, that is, this arbitrary-precision rational number plus a 32-bit signed integer.

### Add

public PeterO.Numbers.ERational Add(
    long v);

Adds this arbitrary-precision rational number and a 64-bit signed integer and returns the result.

Parameters:

Return Value:

The sum of the two numbers, that is, this arbitrary-precision rational number plus a 64-bit signed integer.

### Add

public PeterO.Numbers.ERational Add(
    PeterO.Numbers.ERational otherValue);

Adds this arbitrary-precision rational number and another arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The sum of the two numbers, that is, this arbitrary-precision rational number plus another arbitrary-precision rational number.

Exceptions:

### CompareTo

public int CompareTo(
    int intOther);

Compares the mathematical value of an arbitrary-precision rational number with that of this instance. This method currently uses the rules given in the CompareToValue method, so that it it is not consistent with the Equals method, but it may change in a future version to use the rules for the CompareToTotal method instead.

Parameters:

Return Value:

Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.

### CompareTo

public int CompareTo(
    long intOther);

Compares the mathematical values of this object and another object, accepting NaN values. This method currently uses the rules given in the CompareToValue method, so that it it is not consistent with the Equals method, but it may change in a future version to use the rules for the CompareToTotal method instead.

Parameters:

Return Value:

Less than 0 if this object’s value is less than the other value, or greater than 0 if this object’s value is greater than the other value, or 0 if both values are equal.

### CompareTo

public sealed int CompareTo(
    PeterO.Numbers.ERational other);

Compares the mathematical value of an arbitrary-precision rational number with that of this instance. This method currently uses the rules given in the CompareToValue method, so that it it is not consistent with the Equals method, but it may change in a future version to use the rules for the CompareToTotal method instead.

Parameters:

Return Value:

Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### CompareToBinary

public int CompareToBinary(
    PeterO.Numbers.EFloat other);

Compares an arbitrary-precision binary floating-point number with this instance. In this method, NaN values are greater than any other ERational or EFloat value, and two NaN values (even if their payloads differ) are treated as equal by this method.

Parameters:

Return Value:

Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### CompareToDecimal

public int CompareToDecimal(
    PeterO.Numbers.EDecimal other);

Compares an arbitrary-precision decimal number with this instance.

Parameters:

Return Value:

Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### CompareToTotal

public int CompareToTotal(
    PeterO.Numbers.ERational other);

Compares the values of this object and another object, imposing a total ordering on all possible values. In this method:

Parameters:

Return Value:

The number 0 if both objects have the same value, or -1 if this object is less than the other value, or 1 if this object is greater. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### CompareToTotalMagnitude

public int CompareToTotalMagnitude(
    PeterO.Numbers.ERational other);

Compares the absolute values of this object and another object, imposing a total ordering on all possible values (ignoring their signs). In this method:

Parameters:

Return Value:

The number 0 if both objects have the same value, or -1 if this object is less than the other value, or 1 if this object is greater. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### CompareToValue

public int CompareToValue(
    int intOther);

Compares the mathematical value of an arbitrary-precision rational number with that of this instance. In this method, NaN values are greater than any other ERational value, and two NaN values (even if their payloads differ) are treated as equal by this method. This method is not consistent with the Equals method.

Parameters:

Return Value:

Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.

### CompareToValue

public int CompareToValue(
    long intOther);

Compares the mathematical values of this object and another object, accepting NaN values. This method is not consistent with the Equals method because two different numbers with the same mathematical value, but different exponents, will compare as equal.

In this method, negative zero and positive zero are considered equal.

If this object is a quiet NaN or signaling NaN, this method will not trigger an error. Instead, NaN will compare greater than any other number, including infinity.

Parameters:

Return Value:

Less than 0 if this object’s value is less than the other value, or greater than 0 if this object’s value is greater than the other value, or 0 if both values are equal.

### CompareToValue

public int CompareToValue(
    PeterO.Numbers.ERational other);

Compares the mathematical value of an arbitrary-precision rational number with that of this instance. In this method, NaN values are greater than any other ERational value, and two NaN values (even if their payloads differ) are treated as equal by this method. This method is not consistent with the Equals method.

Parameters:

Return Value:

Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### Copy

public PeterO.Numbers.ERational Copy();

Creates a copy of this arbitrary-precision rational number.

Return Value:

An arbitrary-precision rational number.

### CopySign

public PeterO.Numbers.ERational CopySign(
    PeterO.Numbers.ERational other);

Returns a number with the same value as this one, but copying the sign (positive or negative) of another number.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### Create

public static PeterO.Numbers.ERational Create(
    int numeratorSmall,
    int denominatorSmall);

Creates a rational number with the given numerator and denominator.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### Create

public static PeterO.Numbers.ERational Create(
    long numeratorLong,
    long denominatorLong);

Creates a rational number with the given numerator and denominator.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### Create

public static PeterO.Numbers.ERational Create(
    PeterO.Numbers.EInteger numerator,
    PeterO.Numbers.EInteger denominator);

Creates a rational number with the given numerator and denominator.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### CreateNaN

public static PeterO.Numbers.ERational CreateNaN(
    PeterO.Numbers.EInteger diag);

Creates a not-a-number arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### CreateNaN

public static PeterO.Numbers.ERational CreateNaN(
    PeterO.Numbers.EInteger diag,
    bool signaling,
    bool negative);

Creates a not-a-number arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### Decrement

public PeterO.Numbers.ERational Decrement();

Subtracts one from an arbitrary-precision rational number.

Return Value:

The given arbitrary-precision rational number minus one.

### Divide

public PeterO.Numbers.ERational Divide(
    int v);

Divides this arbitrary-precision rational number by a 32-bit signed integer and returns the result.

Parameters:

Return Value:

The result of dividing this arbitrary-precision rational number by a 32-bit signed integer.

Exceptions:

### Divide

public PeterO.Numbers.ERational Divide(
    long v);

Divides this arbitrary-precision rational number by a 64-bit signed integer and returns the result.

Parameters:

Return Value:

The result of dividing this arbitrary-precision rational number by a 64-bit signed integer.

Exceptions:

### Divide

public PeterO.Numbers.ERational Divide(
    PeterO.Numbers.ERational otherValue);

Divides this arbitrary-precision rational number by another arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The result of dividing this arbitrary-precision rational number by another arbitrary-precision rational number.

Exceptions:

### Equals

public override bool Equals(
    object obj);

Determines whether this object’s numerator, denominator, and properties are equal to those of another object and that other object is an arbitrary-precision rational number. Not-a-number values are considered equal if the rest of their properties are equal. This is not the same as value equality. Notably, two ERationals with the same value, but of which one is in lowest terms and the other is not, are compared as unequal by this method (example: 1/2 vs. 5/10).

Parameters:

Return Value:

true if the objects are equal; otherwise, false . In this method, two objects are not equal if they don’t have the same type or if one is null and the other isn’t.

### Equals

public sealed bool Equals(
    PeterO.Numbers.ERational other);

Determines whether this object’s numerator, denominator, and properties are equal to those of another object. Not-a-number values are considered equal if the rest of their properties are equal.

Parameters:

Return Value:

Either true or false .

### FromBoolean

public static PeterO.Numbers.ERational FromBoolean(
    bool boolValue);

Converts a boolean value (true or false) to an arbitrary-precision rational number.

Parameters:

Return Value:

The number 1 if boolValue is true; otherwise, 0.

### FromByte

public static PeterO.Numbers.ERational FromByte(
    byte inputByte);

Converts a byte (from 0 to 255) to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### FromDecimal

public static PeterO.Numbers.ERational FromDecimal(
    decimal eint);

Converts a decimal under the Common Language Infrastructure (usually a.NET Framework decimal) to a rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### FromDouble

public static PeterO.Numbers.ERational FromDouble(
    double flt);

Converts a 64-bit floating-point number to a rational number. This method computes the exact value of the floating point number, not an approximation, as is often the case by converting the number to a string. The input value can be a not-a-number (NaN) value (such as Double.NaN ); however, NaN values have multiple forms that are equivalent for many applications’ purposes, and Double.NaN is only one of these equivalent forms. In fact, ERational.FromDouble(Double.NaN) could produce an object that is represented differently between DotNet and Java, because Double.NaN may have a different form in DotNet and Java (for example, the NaN value’s sign may be negative in DotNet, but positive in Java). Use IsNaN() to determine whether an object from this class stores a NaN value of any form.

Parameters:

Return Value:

A rational number with the same value as flt .

### FromDoubleBits

public static PeterO.Numbers.ERational FromDoubleBits(
    long value);

Creates a binary rational number from a 64-bit floating-point number encoded in the IEEE 754 binary64 format. This method computes the exact value of the floating point number, not an approximation, as is often the case by converting the number to a string.

Parameters:

Return Value:

A rational number with the same floating-point value as value .

### FromEDecimal

public static PeterO.Numbers.ERational FromEDecimal(
    PeterO.Numbers.EDecimal ef);

Converts an arbitrary-precision decimal number to a rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### FromEFloat

public static PeterO.Numbers.ERational FromEFloat(
    PeterO.Numbers.EFloat ef);

Converts an arbitrary-precision binary floating-point number to a rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### FromEInteger

public static PeterO.Numbers.ERational FromEInteger(
    PeterO.Numbers.EInteger bigint);

Converts an arbitrary-precision integer to a rational number.

Parameters:

Return Value:

The exact value of the integer as a rational number.

### FromExtendedDecimal

public static PeterO.Numbers.ERational FromExtendedDecimal(
    PeterO.Numbers.EDecimal ef);

Deprecated. Renamed to FromEDecimal.

Converts an arbitrary-precision decimal number to a rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### FromExtendedFloat

public static PeterO.Numbers.ERational FromExtendedFloat(
    PeterO.Numbers.EFloat ef);

Deprecated. Renamed to FromEFloat.

Converts an arbitrary-precision binary floating-point number to a rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### FromHalfBits

public static PeterO.Numbers.ERational FromHalfBits(
    short value);

Creates a binary rational number from a binary floating-point number encoded in the IEEE 754 binary16 format (also known as a “half-precision” floating-point number). This method computes the exact value of the floating point number, not an approximation, as is often the case by converting the number to a string.

Parameters:

Return Value:

A rational number with the same floating-point value as value .

### FromInt16

public static PeterO.Numbers.ERational FromInt16(
    short inputInt16);

Converts a 16-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### FromInt32

public static PeterO.Numbers.ERational FromInt32(
    int inputInt32);

Converts a 32-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### FromInt64

public static PeterO.Numbers.ERational FromInt64(
    long inputInt64);

Converts a 64-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### FromInt64AsUnsigned

public static PeterO.Numbers.ERational FromInt64AsUnsigned(
    long longerValue);

Converts an unsigned integer expressed as a 64-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number. If longerValue is 0 or greater, the return value will represent it. If longerValue is less than 0, the return value will store 2^64 plus this value instead.

### FromSByte

public static PeterO.Numbers.ERational FromSByte(
    sbyte inputSByte);

This API is not CLS-compliant.

Converts an 8-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### FromSingle

public static PeterO.Numbers.ERational FromSingle(
    float flt);

Converts a 32-bit binary floating-point number to a rational number. This method computes the exact value of the floating point number, not an approximation, as is often the case by converting the number to a string. The input value can be a not-a-number (NaN) value (such as Single.NaN in DotNet or Float.NaN in Java); however, NaN values have multiple forms that are equivalent for many applications’ purposes, and Single.NaN / Float.NaN is only one of these equivalent forms. In fact, ERational.FromSingle(Single.NaN) or ERational.FromSingle(Float.NaN) could produce an object that is represented differently between DotNet and Java, because Single.NaN / Float.NaN may have a different form in DotNet and Java (for example, the NaN value’s sign may be negative in DotNet, but positive in Java). Use IsNaN() to determine whether an object from this class stores a NaN value of any form.

Parameters:

Return Value:

A rational number with the same value as flt .

### FromSingleBits

public static PeterO.Numbers.ERational FromSingleBits(
    int value);

Creates a binary rational number from a 32-bit floating-point number encoded in the IEEE 754 binary32 format. This method computes the exact value of the floating point number, not an approximation, as is often the case by converting the number to a string.

Parameters:

Return Value:

A rational number with the same floating-point value as value .

### FromString

public static PeterO.Numbers.ERational FromString(
    byte[] bytes);

Creates a rational number from a sequence of bytes that represents a number. See FromString(String, int, int) for more information.

Parameters:

Return Value:

An arbitrary-precision rational number with the same value as the given sequence of bytes.

Exceptions:

### FromString

public static PeterO.Numbers.ERational FromString(
    byte[] bytes,
    int offset,
    int length);

Creates a rational number from a sequence of bytes that represents a number.

The format of the sequence of bytes generally consists of:

The sequence of bytes can also be “-INF”, “-Infinity”, “Infinity”, “INF”, quiet NaN (“NaN” /”-NaN”) followed by any number of digits, or signaling NaN (“sNaN” /”-sNaN”) followed by any number of digits, all in any combination of upper and lower case.

All characters mentioned above are the corresponding characters in the Basic Latin range. In particular, the digits must be the basic digits 0 to 9 (U+0030 to U+0039). The sequence of bytes is not allowed to contain white space characters, including spaces.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### FromString

public static PeterO.Numbers.ERational FromString(
    char[] chars);

Creates a rational number from a sequence of char s that represents a number. See FromString(String, int, int) for more information.

Parameters:

Return Value:

An arbitrary-precision rational number with the same value as the given sequence of char s.

Exceptions:

### FromString

public static PeterO.Numbers.ERational FromString(
    char[] chars,
    int offset,
    int length);

Creates a rational number from a sequence of char s that represents a number.

The format of the sequence of char s generally consists of:

The sequence of char s can also be “-INF”, “-Infinity”, “Infinity”, “INF”, quiet NaN (“NaN” /”-NaN”) followed by any number of digits, or signaling NaN (“sNaN” /”-sNaN”) followed by any number of digits, all in any combination of upper and lower case.

All characters mentioned above are the corresponding characters in the Basic Latin range. In particular, the digits must be the basic digits 0 to 9 (U+0030 to U+0039). The sequence of char s is not allowed to contain white space characters, including spaces.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### FromString

public static PeterO.Numbers.ERational FromString(
    string str);

Creates a rational number from a text string that represents a number. See FromString(String, int, int) for more information.

Parameters:

Return Value:

An arbitrary-precision rational number with the same value as the given string.

Exceptions:

### FromString

public static PeterO.Numbers.ERational FromString(
    string str,
    int offset,
    int length);

Creates a rational number from a text string that represents a number.

The format of the string generally consists of:

The string can also be “-INF”, “-Infinity”, “Infinity”, “INF”, quiet NaN (“NaN” /”-NaN”) followed by any number of digits, or signaling NaN (“sNaN” /”-sNaN”) followed by any number of digits, all in any combination of upper and lower case.

All characters mentioned above are the corresponding characters in the Basic Latin range. In particular, the digits must be the basic digits 0 to 9 (U+0030 to U+0039). The string is not allowed to contain white space characters, including spaces.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### FromUInt16

public static PeterO.Numbers.ERational FromUInt16(
    ushort inputUInt16);

This API is not CLS-compliant.

Converts a 16-bit unsigned integer to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### FromUInt32

public static PeterO.Numbers.ERational FromUInt32(
    uint inputUInt32);

This API is not CLS-compliant.

Converts a 32-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### FromUInt64

public static PeterO.Numbers.ERational FromUInt64(
    ulong inputUInt64);

This API is not CLS-compliant.

Converts a 64-bit unsigned integer to an arbitrary-precision rational number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision rational number.

### GetHashCode

public override int GetHashCode();

Returns the hash code for this instance. No application or process IDs are used in the hash code calculation.

Return Value:

A 32-bit signed integer.

### Increment

public PeterO.Numbers.ERational Increment();

Adds one to an arbitrary-precision rational number.

Return Value:

The given arbitrary-precision rational number plus one.

### IsInfinity

public bool IsInfinity();

Gets a value indicating whether this object’s value is infinity.

Return Value:

true if this object’s value is infinity; otherwise, false .

### IsInteger

public bool IsInteger();

Returns whether this object’s value is an integer.

Return Value:

true if this object’s value is an integer; otherwise, false .

### IsNaN

public bool IsNaN();

Returns whether this object is a not-a-number value.

Return Value:

true if this object is a not-a-number value; otherwise, false .

### IsNegativeInfinity

public bool IsNegativeInfinity();

Returns whether this object is negative infinity.

Return Value:

true if this object is negative infinity; otherwise, false .

### IsPositiveInfinity

public bool IsPositiveInfinity();

Returns whether this object is positive infinity.

Return Value:

true if this object is positive infinity; otherwise, false .

### IsQuietNaN

public bool IsQuietNaN();

Returns whether this object is a quiet not-a-number value.

Return Value:

true if this object is a quiet not-a-number value; otherwise, false .

### IsSignalingNaN

public bool IsSignalingNaN();

Returns whether this object is a signaling not-a-number value (which causes an error if the value is passed to any arithmetic operation in this class).

Return Value:

true if this object is a signaling not-a-number value (which causes an error if the value is passed to any arithmetic operation in this class); otherwise, false .

### Max

public static PeterO.Numbers.ERational Max(
    PeterO.Numbers.ERational first,
    PeterO.Numbers.ERational second);

Gets the greater value between two rational numbers.

Parameters:

Return Value:

The larger value of the two numbers. If one is positive zero and the other is negative zero, returns the positive zero. If the two numbers are positive and have the same value, returns the one with the larger denominator. If the two numbers are negative and have the same value, returns the one with the smaller denominator.

Exceptions:

### MaxMagnitude

public static PeterO.Numbers.ERational MaxMagnitude(
    PeterO.Numbers.ERational first,
    PeterO.Numbers.ERational second);

Gets the greater value between two values, ignoring their signs. If the absolute values are equal, has the same effect as Max.

Parameters:

Return Value:

The larger value of the two numbers, ignoring their signs.

Exceptions:

### Min

public static PeterO.Numbers.ERational Min(
    PeterO.Numbers.ERational first,
    PeterO.Numbers.ERational second);

Gets the lesser value between two rational numbers.

Parameters:

Return Value:

The smaller value of the two numbers. If one is positive zero and the other is negative zero, returns the negative zero. If the two numbers are positive and have the same value, returns the one with the smaller denominator. If the two numbers are negative and have the same value, returns the one with the larger denominator.

Exceptions:

### MinMagnitude

public static PeterO.Numbers.ERational MinMagnitude(
    PeterO.Numbers.ERational first,
    PeterO.Numbers.ERational second);

Gets the lesser value between two values, ignoring their signs. If the absolute values are equal, has the same effect as Min.

Parameters:

Return Value:

The smaller value of the two numbers, ignoring their signs.

Exceptions:

### Multiply

public PeterO.Numbers.ERational Multiply(
    int v);

Multiplies this arbitrary-precision rational number by a 32-bit signed integer and returns the result.

Parameters:

Return Value:

The product of the two numbers, that is, this arbitrary-precision rational number times a 32-bit signed integer.

### Multiply

public PeterO.Numbers.ERational Multiply(
    long v);

Multiplies this arbitrary-precision rational number by a 64-bit signed integer and returns the result.

Parameters:

Return Value:

The product of the two numbers, that is, this arbitrary-precision rational number times a 64-bit signed integer.

### Multiply

public PeterO.Numbers.ERational Multiply(
    PeterO.Numbers.ERational otherValue);

Multiplies this arbitrary-precision rational number by another arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The product of the two numbers, that is, this arbitrary-precision rational number times another arbitrary-precision rational number.

Exceptions:

### Negate

public PeterO.Numbers.ERational Negate();

Returns a rational number with the same value as this one but with the sign reversed.

Return Value:

An arbitrary-precision rational number.

### Operator +

public static PeterO.Numbers.ERational operator +(
    PeterO.Numbers.ERational bthis,
    PeterO.Numbers.ERational augend);

Adds an arbitrary-precision rational number and another arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The sum of the two numbers, that is, an arbitrary-precision rational number plus another arbitrary-precision rational number.

Exceptions:

### Operator --

public static PeterO.Numbers.ERational operator --(
    PeterO.Numbers.ERational bthis);

Subtracts one from an arbitrary-precision rational number.

Parameters:

Return Value:

The number given in bthis minus one.

Exceptions:

### Operator /

public static PeterO.Numbers.ERational operator /(
    PeterO.Numbers.ERational dividend,
    PeterO.Numbers.ERational divisor);

Divides an arbitrary-precision rational number by the value of another arbitrary-precision rational number object.

Parameters:

Return Value:

The quotient of the two objects.

Exceptions:

### Explicit Operator

public static explicit operator byte(
    PeterO.Numbers.ERational input);

Converts an arbitrary-precision rational number to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to a byte (from 0 to 255).

Exceptions:

### Explicit Operator

public static explicit operator decimal(
    PeterO.Numbers.ERational extendedNumber);

Converts an arbitrary-precision rational number to a decimal under the Common Language Infrastructure (see "Forms of numbers"“Forms of numbers” ).

Parameters:

Return Value:

A decimal under the Common Language Infrastructure (usually a.NET Framework decimal).

Exceptions:

### Explicit Operator

public static explicit operator double(
    PeterO.Numbers.ERational bigValue);

Converts an arbitrary-precision rational number to a 64-bit floating-point number. The half-even rounding mode is used.

Parameters:

Return Value:

The closest 64-bit floating-point number to this value. The return value can be positive infinity or negative infinity if this value exceeds the range of a 64-bit floating point number.

Exceptions:

### Explicit Operator

public static explicit operator float(
    PeterO.Numbers.ERational bigValue);

Converts an arbitrary-precision rational number to a 32-bit binary floating-point number. The half-even rounding mode is used.

Parameters:

Return Value:

The closest 32-bit binary floating-point number to this value. The return value can be positive infinity or negative infinity if this value exceeds the range of a 32-bit floating point number.

Exceptions:

### Explicit Operator

public static explicit operator int(
    PeterO.Numbers.ERational input);

Converts an arbitrary-precision rational number to a 32-bit signed integer if it can fit in a 32-bit signed integer after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to a 32-bit signed integer.

Exceptions:

### Explicit Operator

public static explicit operator long(
    PeterO.Numbers.ERational input);

Converts an arbitrary-precision rational number to a 64-bit signed integer if it can fit in a 64-bit signed integer after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to a 64-bit signed integer.

Exceptions:

### Explicit Operator

public static explicit operator PeterO.Numbers.EInteger(
    PeterO.Numbers.ERational bigValue);

Converts an arbitrary-precision rational number to an arbitrary-precision integer. Any fractional part in the value will be discarded when converting to an arbitrary-precision integer.

Parameters:

Return Value:

An arbitrary-precision integer.

Exceptions:

### Explicit Operator

public static explicit operator PeterO.Numbers.ERational(
    bool boolValue);

Converts a boolean value (true or false) to an arbitrary-precision rational number.

Parameters:

Return Value:

1 if boolValue is true; otherwise, 0.

### Explicit Operator

public static explicit operator sbyte(
    PeterO.Numbers.ERational input);

This API is not CLS-compliant.

Converts an arbitrary-precision rational number to an 8-bit signed integer if it can fit in an 8-bit signed integer after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to an 8-bit signed integer.

Exceptions:

### Explicit Operator

public static explicit operator short(
    PeterO.Numbers.ERational input);

Converts an arbitrary-precision rational number to a 16-bit signed integer if it can fit in a 16-bit signed integer after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to a 16-bit signed integer.

Exceptions:

### Explicit Operator

public static explicit operator uint(
    PeterO.Numbers.ERational input);

This API is not CLS-compliant.

Converts an arbitrary-precision rational number to a 32-bit signed integer if it can fit in a 32-bit signed integer after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to a 32-bit signed integer.

Exceptions:

### Explicit Operator

public static explicit operator ulong(
    PeterO.Numbers.ERational input);

This API is not CLS-compliant.

Converts an arbitrary-precision rational number to a 64-bit unsigned integer if it can fit in a 64-bit unsigned integer after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to a 64-bit unsigned integer.

Exceptions:

### Explicit Operator

public static explicit operator ushort(
    PeterO.Numbers.ERational input);

This API is not CLS-compliant.

Converts an arbitrary-precision rational number to a 16-bit unsigned integer if it can fit in a 16-bit unsigned integer after converting it to an integer by discarding its fractional part.

Parameters:

Return Value:

The value of input , truncated to a 16-bit unsigned integer.

Exceptions:

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    byte inputByte);

Converts a byte (from 0 to 255) to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputByte as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    decimal eint);

Converts a decimal under the Common Language Infrastructure (usually a.NET Framework decimal). to an arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    double eint);

Converts a 64-bit floating-point number to an arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    float eint);

Converts a 32-bit binary floating-point number to a rational number.

Parameters:

Return Value:

The value of eint as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    int inputInt32);

Converts a 32-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputInt32 as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    long inputInt64);

Converts a 64-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputInt64 as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    PeterO.Numbers.EDecimal eint);

Converts an arbitrary-precision decimal floating-point number to an arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    PeterO.Numbers.EFloat eint);

Converts an arbitrary-precision binary floating-point number to an arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    PeterO.Numbers.EInteger eint);

Converts an arbitrary-precision integer to an arbitrary-precision rational number.

Parameters:

Return Value:

An arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    sbyte inputSByte);

This API is not CLS-compliant.

Converts an 8-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputSByte as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    short inputInt16);

Converts a 16-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputInt16 as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    uint inputUInt32);

This API is not CLS-compliant.

Converts a 32-bit signed integer to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputUInt32 as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    ulong inputUInt64);

This API is not CLS-compliant.

Converts a 64-bit unsigned integer to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputUInt64 as an arbitrary-precision rational number.

### Implicit Operator

public static implicit operator PeterO.Numbers.ERational(
    ushort inputUInt16);

This API is not CLS-compliant.

Converts a 16-bit unsigned integer to an arbitrary-precision rational number.

Parameters:

Return Value:

The value of inputUInt16 as an arbitrary-precision rational number.

### Operator ++

public static PeterO.Numbers.ERational operator ++(
    PeterO.Numbers.ERational bthis);

Adds one to an arbitrary-precision rational number.

Parameters:

Return Value:

The number given in bthis plus one.

Exceptions:

### Operator %

public static PeterO.Numbers.ERational operator %(
    PeterO.Numbers.ERational dividend,
    PeterO.Numbers.ERational divisor);

Returns the remainder that would result when an arbitrary-precision rational number is divided by another arbitrary-precision rational number.

Parameters:

Return Value:

The remainder that would result when an arbitrary-precision rational number is divided by another arbitrary-precision rational number.

Exceptions:

### Operator *

public static PeterO.Numbers.ERational operator *(
    PeterO.Numbers.ERational operand1,
    PeterO.Numbers.ERational operand2);

Multiplies an arbitrary-precision rational number by another arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The product of the two numbers, that is, an arbitrary-precision rational number times another arbitrary-precision rational number.

Exceptions:

### Operator -

public static PeterO.Numbers.ERational operator -(
    PeterO.Numbers.ERational bthis,
    PeterO.Numbers.ERational subtrahend);

Subtracts an arbitrary-precision rational number from this instance.

Parameters:

Return Value:

The difference of the two objects.

Exceptions:

### Operator -

public static PeterO.Numbers.ERational operator -(
    PeterO.Numbers.ERational bigValue);

Returns an arbitrary-precision rational number with the same value as the given one but with its sign reversed.

Parameters:

Return Value:

An arbitrary-precision rational number.

Exceptions:

### Remainder

public PeterO.Numbers.ERational Remainder(
    int v);

Returns the remainder that would result when this arbitrary-precision rational number is divided by a 32-bit signed integer.

Parameters:

Return Value:

The remainder that would result when this arbitrary-precision rational number is divided by a 32-bit signed integer.

Exceptions:

### Remainder

public PeterO.Numbers.ERational Remainder(
    long v);

Returns the remainder that would result when this arbitrary-precision rational number is divided by a 64-bit signed integer.

Parameters:

Return Value:

The remainder that would result when this arbitrary-precision rational number is divided by a 64-bit signed integer.

Exceptions:

### Remainder

public PeterO.Numbers.ERational Remainder(
    PeterO.Numbers.ERational otherValue);

Returns the remainder that would result when this arbitrary-precision rational number is divided by another arbitrary-precision rational number.

Parameters:

Return Value:

The remainder that would result when this arbitrary-precision rational number is divided by another arbitrary-precision rational number.

Exceptions:

### Subtract

public PeterO.Numbers.ERational Subtract(
    int v);

Subtracts a 32-bit signed integer from this arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The difference between the two numbers, that is, this arbitrary-precision rational number minus a 32-bit signed integer.

### Subtract

public PeterO.Numbers.ERational Subtract(
    long v);

Subtracts a 64-bit signed integer from this arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The difference between the two numbers, that is, this arbitrary-precision rational number minus a 64-bit signed integer.

### Subtract

public PeterO.Numbers.ERational Subtract(
    PeterO.Numbers.ERational otherValue);

Subtracts an arbitrary-precision rational number from this arbitrary-precision rational number and returns the result.

Parameters:

Return Value:

The difference between the two numbers, that is, this arbitrary-precision rational number minus another arbitrary-precision rational number.

Exceptions:

### ToByteChecked

public byte ToByteChecked();

Converts this number’s value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a byte (from 0 to 255).

Exceptions:

### ToByteIfExact

public byte ToByteIfExact();

Converts this number’s value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) without rounding to a different numerical value.

Return Value:

This number’s value as a byte (from 0 to 255).

Exceptions:

### ToByteUnchecked

public byte ToByteUnchecked();

Converts this number’s value to an integer (using ToEInteger), and returns the least-significant bits of that integer’s two’s-complement form as a byte (from 0 to 255).

Return Value:

This number, converted to a byte (from 0 to 255). Returns 0 if this value is infinity or not-a-number.

### ToDecimal

public decimal ToDecimal();

Converts this value to a decimal under the Common Language Infrastructure (usually a.NET Framework decimal). Currently, converts this value to the precision and range of a.NET Framework decimal.

Return Value:

A decimal under the Common Language Infrastructure (usually a.NET Framework decimal).

### ToDouble

public double ToDouble();

Converts this value to a 64-bit floating-point number. The half-even rounding mode is used.

Return Value:

The closest 64-bit floating-point number to this value. The return value can be positive infinity or negative infinity if this value exceeds the range of a 64-bit floating point number.

### ToDoubleBits

public long ToDoubleBits();

Converts this value to its closest equivalent as a 64-bit floating-point number, expressed as an integer in the IEEE 754 binary64 format. The half-even rounding mode is used. If this value is a NaN, sets the high bit of the 64-bit floating point number’s significand area for a quiet NaN, and clears it for a signaling NaN. Then the other bits of the significand area are set to the lowest bits of this object’s unsigned significand, and the next-highest bit of the significand area is set if those bits are all zeros and this is a signaling NaN.

Return Value:

The closest 64-bit binary floating-point number to this value, expressed as an integer in the IEEE 754 binary64 format. The return value can be positive infinity or negative infinity if this value exceeds the range of a 64-bit floating point number.

### ToEDecimal

public PeterO.Numbers.EDecimal ToEDecimal(
    PeterO.Numbers.EContext ctx);

Converts this rational number to an arbitrary-precision decimal number and rounds the result to the given precision.

Parameters:

Return Value:

The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating decimal expansion.

### ToEDecimal

public PeterO.Numbers.EDecimal ToEDecimal();

Converts this rational number to an arbitrary-precision decimal number.

Return Value:

The exact value of the rational number, or not-a-number (NaN) if the result can’t be exact because it has a nonterminating decimal expansion.

### ToEDecimalExactIfPossible

public PeterO.Numbers.EDecimal ToEDecimalExactIfPossible(
    PeterO.Numbers.EContext ctx);

Converts this rational number to an arbitrary-precision decimal number, but if the result would have a nonterminating decimal expansion, rounds that result to the given precision.

Parameters:

Return Value:

The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating decimal expansion.

### ToEFloat

public PeterO.Numbers.EFloat ToEFloat(
    PeterO.Numbers.EContext ctx);

Converts this rational number to a binary floating-point number and rounds that result to the given precision.

Parameters:

Return Value:

The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating binary expansion.

### ToEFloat

public PeterO.Numbers.EFloat ToEFloat();

Converts this rational number to a binary floating-point number.

Return Value:

The exact value of the rational number, or not-a-number (NaN) if the result can’t be exact because it has a nonterminating binary expansion.

### ToEFloatExactIfPossible

public PeterO.Numbers.EFloat ToEFloatExactIfPossible(
    PeterO.Numbers.EContext ctx);

Converts this rational number to a binary floating-point number, but if the result would have a nonterminating binary expansion, rounds that result to the given precision.

Parameters:

Return Value:

The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating binary expansion.

### ToEInteger

public PeterO.Numbers.EInteger ToEInteger();

Converts this value to an arbitrary-precision integer by dividing the numerator by the denominator and discarding the fractional part of the result.

Return Value:

An arbitrary-precision integer.

Exceptions:

### ToEIntegerExact

public PeterO.Numbers.EInteger ToEIntegerExact();

Deprecated. Renamed to ToEIntegerIfExact.

Converts this value to an arbitrary-precision integer, checking whether the value is an exact integer.

Return Value:

An arbitrary-precision integer.

Exceptions:

### ToEIntegerIfExact

public PeterO.Numbers.EInteger ToEIntegerIfExact();

Converts this value to an arbitrary-precision integer, checking whether the value is an exact integer.

Return Value:

An arbitrary-precision integer.

Exceptions:

### ToExtendedDecimal

public PeterO.Numbers.EDecimal ToExtendedDecimal(
    PeterO.Numbers.EContext ctx);

Deprecated. Renamed to ToEDecimal.

Converts this rational number to an arbitrary-precision decimal number and rounds the result to the given precision.

Parameters:

Return Value:

The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating decimal expansion.

### ToExtendedDecimal

public PeterO.Numbers.EDecimal ToExtendedDecimal();

Deprecated. Renamed to ToEDecimal.

Converts this rational number to an arbitrary-precision decimal number.

Return Value:

The exact value of the rational number, or not-a-number (NaN) if the result can’t be exact because it has a nonterminating decimal expansion.

### ToExtendedDecimalExactIfPossible

public PeterO.Numbers.EDecimal ToExtendedDecimalExactIfPossible(
    PeterO.Numbers.EContext ctx);

Deprecated. Renamed to ToEDecimalExactIfPossible.

Converts this rational number to an arbitrary-precision decimal number, but if the result would have a nonterminating decimal expansion, rounds that result to the given precision.

Parameters:

Return Value:

The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating decimal expansion.

### ToExtendedFloat

public PeterO.Numbers.EFloat ToExtendedFloat(
    PeterO.Numbers.EContext ctx);

Deprecated. Renamed to ToEFloat.

Converts this rational number to a binary floating-point number and rounds that result to the given precision.

Parameters:

Return Value:

The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating binary expansion.

### ToExtendedFloat

public PeterO.Numbers.EFloat ToExtendedFloat();

Deprecated. Renamed to ToEFloat.

Converts this rational number to a binary floating-point number.

Return Value:

The exact value of the rational number, or not-a-number (NaN) if the result can’t be exact because it has a nonterminating binary expansion.

### ToExtendedFloatExactIfPossible

public PeterO.Numbers.EFloat ToExtendedFloatExactIfPossible(
    PeterO.Numbers.EContext ctx);

Deprecated. Renamed to ToEFloatExactIfPossible.

Converts this rational number to a binary floating-point number, but if the result would have a nonterminating binary expansion, rounds that result to the given precision.

Parameters:

Return Value:

The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can’t be exact because it has a nonterminating binary expansion.

### ToHalfBits

public short ToHalfBits();

Converts this value to its closest equivalent as a binary floating-point number, expressed as an integer in the IEEE 754 binary16 format (also known as a “half-precision” floating-point number). The half-even rounding mode is used. If this value is a NaN, sets the high bit of the binary16 number’s significand area for a quiet NaN, and clears it for a signaling NaN. Then the other bits of the significand area are set to the lowest bits of this object’s unsigned significand, and the next-highest bit of the significand area is set if those bits are all zeros and this is a signaling NaN.

Return Value:

The closest binary floating-point number to this value, expressed as an integer in the IEEE 754 binary16 format. The return value can be positive infinity or negative infinity if this value exceeds the range of a floating-point number in the binary16 format.

### ToInt16Checked

public short ToInt16Checked();

Converts this number’s value to a 16-bit signed integer if it can fit in a 16-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 16-bit signed integer.

Exceptions:

### ToInt16IfExact

public short ToInt16IfExact();

Converts this number’s value to a 16-bit signed integer if it can fit in a 16-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 16-bit signed integer.

Exceptions:

### ToInt16Unchecked

public short ToInt16Unchecked();

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 16-bit signed integer.

Return Value:

This number, converted to a 16-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToInt32Checked

public int ToInt32Checked();

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 32-bit signed integer.

Exceptions:

### ToInt32IfExact

public int ToInt32IfExact();

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 32-bit signed integer.

Exceptions:

### ToInt32Unchecked

public int ToInt32Unchecked();

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 32-bit signed integer.

Return Value:

This number, converted to a 32-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToInt64Checked

public long ToInt64Checked();

Converts this number’s value to a 64-bit signed integer if it can fit in a 64-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 64-bit signed integer.

Exceptions:

### ToInt64IfExact

public long ToInt64IfExact();

Converts this number’s value to a 64-bit signed integer if it can fit in a 64-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 64-bit signed integer.

Exceptions:

### ToInt64Unchecked

public long ToInt64Unchecked();

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 64-bit signed integer.

Return Value:

This number, converted to a 64-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToLowestTerms

public PeterO.Numbers.ERational ToLowestTerms();

Converts this value to its form in lowest terms. For example, (8/4) becomes (4/1).

Return Value:

An arbitrary-precision rational with the same value as this one but in lowest terms. Returns this object if it is infinity or NaN. Returns ERational.NegativeZero if this object is a negative zero. Returns ERational.Zero if this object is a positive zero.

Exceptions:

### ToSByteChecked

public sbyte ToSByteChecked();

This API is not CLS-compliant.

Converts this number’s value to an 8-bit signed integer if it can fit in an 8-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to an 8-bit signed integer.

Exceptions:

### ToSByteIfExact

public sbyte ToSByteIfExact();

This API is not CLS-compliant.

Converts this number’s value to an 8-bit signed integer if it can fit in an 8-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as an 8-bit signed integer.

Exceptions:

### ToSByteUnchecked

public sbyte ToSByteUnchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as an 8-bit signed integer.

Return Value:

This number, converted to an 8-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToSingle

public float ToSingle();

Converts this value to a 32-bit binary floating-point number. The half-even rounding mode is used.

Return Value:

The closest 32-bit binary floating-point number to this value. The return value can be positive infinity or negative infinity if this value exceeds the range of a 32-bit floating point number.

### ToSingleBits

public int ToSingleBits();

Converts this value to its closest equivalent as 32-bit floating-point number, expressed as an integer in the IEEE 754 binary32 format. The half-even rounding mode is used. If this value is a NaN, sets the high bit of the 32-bit floating point number’s significand area for a quiet NaN, and clears it for a signaling NaN. Then the other bits of the significand area are set to the lowest bits of this object’s unsigned significand, and the next-highest bit of the significand area is set if those bits are all zeros and this is a signaling NaN.

Return Value:

The closest 32-bit binary floating-point number to this value, expressed as an integer in the IEEE 754 binary32 format. The return value can be positive infinity or negative infinity if this value exceeds the range of a 32-bit floating point number.

### ToSizedEInteger

public PeterO.Numbers.EInteger ToSizedEInteger(
    int maxBitLength);

Converts this value to an arbitrary-precision integer by dividing the numerator by the denominator, discarding its fractional part, and checking whether the resulting integer overflows the given signed bit count.

Parameters:

Return Value:

An arbitrary-precision integer.

Exceptions:

### ToSizedEIntegerIfExact

public PeterO.Numbers.EInteger ToSizedEIntegerIfExact(
    int maxBitLength);

Converts this value to an arbitrary-precision integer, only if this number’s value is an exact integer and that integer does not overflow the given signed bit count.

Parameters:

Return Value:

An arbitrary-precision integer.

Exceptions:

### ToString

public override string ToString();

Converts this object to a text string.

Return Value:

A string representation of this object. If this object’s value is infinity or not-a-number, the result is the analogous return value of the EDecimal.ToString method. Otherwise, the return value has the following form: [-]numerator/denominator .

### ToUInt16Checked

public ushort ToUInt16Checked();

This API is not CLS-compliant.

Converts this number’s value to a 16-bit unsigned integer if it can fit in a 16-bit unsigned integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 16-bit unsigned integer.

Exceptions:

### ToUInt16IfExact

public ushort ToUInt16IfExact();

This API is not CLS-compliant.

Converts this number’s value to a 16-bit unsigned integer if it can fit in a 16-bit unsigned integer without rounding to a different numerical value.

Return Value:

This number’s value as a 16-bit unsigned integer.

Exceptions:

### ToUInt16Unchecked

public ushort ToUInt16Unchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 16-bit unsigned integer.

Return Value:

This number, converted to a 16-bit unsigned integer. Returns 0 if this value is infinity or not-a-number.

### ToUInt32Checked

public uint ToUInt32Checked();

This API is not CLS-compliant.

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 32-bit signed integer.

Exceptions:

### ToUInt32IfExact

public uint ToUInt32IfExact();

This API is not CLS-compliant.

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 32-bit signed integer.

Exceptions:

### ToUInt32Unchecked

public uint ToUInt32Unchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 32-bit signed integer.

Return Value:

This number, converted to a 32-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToUInt64Checked

public ulong ToUInt64Checked();

This API is not CLS-compliant.

Converts this number’s value to a 64-bit unsigned integer if it can fit in a 64-bit unsigned integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 64-bit unsigned integer.

Exceptions:

### ToUInt64IfExact

public ulong ToUInt64IfExact();

This API is not CLS-compliant.

Converts this number’s value to a 64-bit unsigned integer if it can fit in a 64-bit unsigned integer without rounding to a different numerical value.

Return Value:

This number’s value as a 64-bit unsigned integer.

Exceptions:

### ToUInt64Unchecked

public ulong ToUInt64Unchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 64-bit unsigned integer.

Return Value:

This number, converted to a 64-bit unsigned integer. Returns 0 if this value is infinity or not-a-number.

Back to Numbers start page.