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:
numerator: A BigInteger object.
denominator: Another BigInteger object.
Exceptions:
- System.ArgumentNullException: The parameter numerator or denominator is null.
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:
- otherValue: Another ExtendedRational object.
Returns:
The sum of the two numbers. Returns NaN if either operand is NaN.
Exceptions:
- System.ArgumentNullException: The parameter otherValue is null.
CompareTo
public sealed int CompareTo(
PeterO.Numbers.ERational other);
Compares an ExtendedRational object with this instance.
Parameters:
- other: An ExtendedRational object.
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:
- other: An ExtendedFloat object.
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:
- other: An ExtendedDecimal object.
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:
numeratorSmall: A 32-bit signed integer.
denominatorSmall: A 32-bit signed integer. (2).
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:
numerator: A BigInteger object.
denominator: Another BigInteger object.
Returns:
An ExtendedRational object.
CreateNaN
public static PeterO.Numbers.ERational CreateNaN(
PeterO.Numbers.EInteger diag);
Creates a not-a-number ExtendedRational object.
Parameters:
- diag: A number to use as diagnostic information associated with this object. If none is needed, should be zero.
Returns:
An ExtendedRational object.
Exceptions:
System.ArgumentNullException: The parameter diag is null.
System.ArgumentException: The parameter diag is less than 0.
CreateNaN
public static PeterO.Numbers.ERational CreateNaN(
PeterO.Numbers.EInteger diag,
bool signaling,
bool negative);
Creates a not-a-number ExtendedRational object.
Parameters:
diag: A number to use as diagnostic information associated with this object. If none is needed, should be zero.
signaling: Whether the return value will be signaling (true) or quiet (false).
negative: Whether the return value is negative.
Returns:
An ExtendedRational object.
Exceptions:
System.ArgumentNullException: The parameter diag is null.
System.ArgumentException: The parameter diag is less than 0.
Divide
public PeterO.Numbers.ERational Divide(
PeterO.Numbers.ERational otherValue);
Divides this instance by the value of an ExtendedRational object.
Parameters:
- otherValue: An ExtendedRational object.
Returns:
The quotient of the two objects.
Exceptions:
- System.ArgumentNullException: The parameter otherValue is null.
Equals
public override bool Equals(
object obj);
Determines whether this object and another object are equal.
Parameters:
- obj: An arbitrary object.
Returns:
True if the objects are equal; otherwise, false.
Equals
public sealed bool Equals(
PeterO.Numbers.ERational other);
Not documented yet.
Parameters:
- other: An ExtendedRational object.
Returns:
A Boolean object.
FromBigInteger
public static PeterO.Numbers.ERational FromBigInteger(
PeterO.Numbers.EInteger bigint);
Converts a big integer to a rational number.
Parameters:
- bigint: A BigInteger object.
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:
- flt: A 64-bit floating-point number.
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:
- ef: An ExtendedDecimal object.
Returns:
An ExtendedRational object.
Exceptions:
- System.ArgumentNullException: The parameter ef is null.
FromExtendedFloat
public static PeterO.Numbers.ERational FromExtendedFloat(
PeterO.Numbers.EFloat ef);
Not documented yet.
Parameters:
- ef: An ExtendedFloat object.
Returns:
An ExtendedRational object.
Exceptions:
- System.ArgumentNullException: The parameter ef is null.
FromInt32
public static PeterO.Numbers.ERational FromInt32(
int smallint);
Not documented yet.
Parameters:
- smallint: A 32-bit signed integer.
Returns:
An ExtendedRational object.
FromInt64
public static PeterO.Numbers.ERational FromInt64(
long longInt);
Not documented yet.
Parameters:
- longInt: A 64-bit signed integer.
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:
- flt: A 32-bit floating-point number.
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:
- otherValue: An ExtendedRational object.
Returns:
The product of the two objects.
Exceptions:
- System.ArgumentNullException: The parameter otherValue is null.
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:
- otherValue: An ExtendedRational object.
Returns:
The remainder of the two objects.
Exceptions:
- System.ArgumentNullException: The parameter otherValue is null.
Subtract
public PeterO.Numbers.ERational Subtract(
PeterO.Numbers.ERational otherValue);
Subtracts an ExtendedRational object from this instance.
Parameters:
- otherValue: An ExtendedRational object.
Returns:
The difference of the two objects.
Exceptions:
- System.ArgumentNullException: The parameter otherValue is null.
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:
- System.OverflowException: This object's value is infinity or NaN.
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:
System.OverflowException: This object's value is infinity or NaN.
System.ArithmeticException: This object's value is not an exact integer.
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:
- ctx: A PrecisionContext object.
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:
- ctx: A precision context object to control the precision. The rounding and exponent range settings of this context are ignored. This context will be used only if the exact result would have a nonterminating decimal expansion. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case this method is the same as ToExtendedDecimal.
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:
- ctx: A PrecisionContext object.
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:
- ctx: A precision context object to control the precision. The rounding and exponent range settings of this context are ignored. This context will be used only if the exact result would have a nonterminating binary expansion. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case this method is the same as ToExtendedFloat.
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.