Menu - Top - Home - Donate to Me

PeterO.Numbers.ERational

PeterO.Numbers.ERational

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

Arbitrary-precision rational number. This class cannot be inherited; this is a change in version 2.0 from previous versions, where the class was inadvertently left inheritable.

ERational Constructor

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

Initializes a new instance of the ExtendedRational 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; 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.

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:

Zero if this value is zero or negative zero; -1 if this value is less than 0; and 1 if this value is greater than 0.

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();

Not documented yet.

Returns:

An ExtendedRational object.

Add

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

Adds two rational numbers.

Parameters:

Returns:

The sum of the two numbers. Returns NaN if either operand is NaN.

Exceptions:

CompareTo

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

Compares an ExtendedRational object with this instance.

Parameters:

Returns:

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

CompareToBinary

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

Compares an ExtendedFloat object with this instance.

Parameters:

Returns:

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

CompareToDecimal

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

Compares an ExtendedDecimal object with this instance.

Parameters:

Returns:

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

Create

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

Creates a number with the specified numerator and denominator.

Parameters:

Returns:

An ExtendedRational object.

Create

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

Creates a number with the specified numerator and denominator.

Parameters:

Returns:

An ExtendedRational object.

CreateNaN

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

Creates a not-a-number ExtendedRational object.

Parameters:

Returns:

An ExtendedRational object.

Exceptions:

CreateNaN

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

Creates a not-a-number ExtendedRational object.

Parameters:

Returns:

An ExtendedRational object.

Exceptions:

Divide

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

Divides this instance by the value of an ExtendedRational object.

Parameters:

Returns:

The quotient of the two objects.

Exceptions:

Equals

public override bool Equals(
    object obj);

Determines whether this object and another object are equal.

Parameters:

Returns:

True if the objects are equal; otherwise, false.

Equals

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

Not documented yet.

Parameters:

Returns:

A Boolean object.

FromBigInteger

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

Converts a big integer to a rational number.

Parameters:

Returns:

The exact value of the integer as a 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.

Parameters:

Returns:

A rational number with the same value as flt .

FromExtendedDecimal

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

Not documented yet.

Parameters:

Returns:

An ExtendedRational object.

Exceptions:

FromExtendedFloat

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

Not documented yet.

Parameters:

Returns:

An ExtendedRational object.

Exceptions:

FromInt32

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

Not documented yet.

Parameters:

Returns:

An ExtendedRational object.

FromInt64

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

Not documented yet.

Parameters:

Returns:

An ExtendedRational object.

FromSingle

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

Converts a 32-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.

Parameters:

Returns:

A rational number with the same value as flt .

GetHashCode

public override int GetHashCode();

Returns the hash code for this instance.

Returns:

A 32-bit hash code.

IsInfinity

public bool IsInfinity();

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

Returns:

True if this object's value is infinity; otherwise, false.

IsNaN

public bool IsNaN();

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

Returns:

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

IsNegativeInfinity

public bool IsNegativeInfinity();

Returns whether this object is negative infinity.

Returns:

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

IsPositiveInfinity

public bool IsPositiveInfinity();

Returns whether this object is positive infinity.

Returns:

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

IsQuietNaN

public bool IsQuietNaN();

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

Returns:

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).

Returns:

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.

Multiply

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

Multiplies this instance by the value of an ExtendedRational object.

Parameters:

Returns:

The product of the two objects.

Exceptions:

Negate

public PeterO.Numbers.ERational Negate();

Not documented yet.

Returns:

An ExtendedRational object.

Remainder

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

Finds the remainder that results when this instance is divided by the value of a ExtendedRational object.

Parameters:

Returns:

The remainder of the two objects.

Exceptions:

Subtract

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

Subtracts an ExtendedRational object from this instance.

Parameters:

Returns:

The difference of the two objects.

Exceptions:

ToBigInteger

public PeterO.Numbers.EInteger ToBigInteger();

Converts this value to an arbitrary-precision integer. Any fractional part in this value will be discarded when converting to a big integer.

Returns:

A BigInteger object.

Exceptions:

ToBigIntegerExact

public PeterO.Numbers.EInteger ToBigIntegerExact();

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

Returns:

A BigInteger object.

Exceptions:

ToDouble

public double ToDouble();

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

Returns:

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.

ToExtendedDecimal

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

Converts this rational number to a decimal number and rounds the result to the specified precision.

Parameters:

Returns:

An ExtendedDecimal object.

ToExtendedDecimal

public PeterO.Numbers.EDecimal ToExtendedDecimal();

Converts this rational number to a decimal number.

Returns:

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);

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

Parameters:

Returns:

An ExtendedDecimal object.

ToExtendedFloat

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

Converts this rational number to a binary number and rounds the result to the specified precision.

Parameters:

Returns:

An ExtendedFloat object.

ToExtendedFloat

public PeterO.Numbers.EFloat ToExtendedFloat();

Converts this rational number to a binary number.

Returns:

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);

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

Parameters:

Returns:

An ExtendedFloat object.

ToSingle

public float ToSingle();

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

Returns:

The closest 32-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 32-bit floating point number.

ToString

public override string ToString();

Converts this object to a text string.

Returns:

A string representation of this object. The result can be Infinity, NaN, or sNaN (with a minus sign before it for negative values), or a number of the following form: [-]numerator/denominator.

Back to CBOR start page.