public final class ERational extends Object implements Comparable<ERational>
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).
| Modifier and Type | Field and Description |
|---|---|
static ERational |
NaN
A not-a-number value.
|
static ERational |
NegativeInfinity
Negative infinity, less than any other number.
|
static ERational |
NegativeZero
A rational number for negative zero.
|
static ERational |
One
The rational number one.
|
static ERational |
PositiveInfinity
Positive infinity, greater than any other number.
|
static ERational |
SignalingNaN
A signaling not-a-number value.
|
static ERational |
Ten
The rational number ten.
|
static ERational |
Zero
A rational number for zero.
|
| Constructor and Description |
|---|
ERational(EInteger numerator,
EInteger denominator)
Deprecated.
Use the ERational.Create method instead. This constructor will be private or
unavailable in version 1.0.
|
| Modifier and Type | Method and Description |
|---|---|
ERational |
Abs()
Not documented yet.
|
ERational |
Add(ERational otherValue)
Adds two rational numbers.
|
int |
compareTo(ERational other)
Compares an arbitrary-precision rational number with this instance.
|
int |
CompareToBinary(EFloat other)
Compares an arbitrary-precision binary float with this instance.
|
int |
CompareToDecimal(EDecimal other)
Compares an arbitrary-precision decimal number with this instance.
|
int |
CompareToTotal(ERational other)
Compares the values of this object and another object, imposing a total
ordering on all possible values.
|
int |
CompareToTotalMagnitude(ERational other)
Compares the absolute values of this object and another object, imposing a
total ordering on all possible values (ignoring their signs).
|
ERational |
CopySign(ERational other)
Returns a number with the same value as this one, but copying the sign
(positive or negative) of another number.
|
static ERational |
Create(EInteger numerator,
EInteger denominator)
Creates a rational number with the given numerator and denominator.
|
static ERational |
Create(int numeratorSmall,
int denominatorSmall)
Creates a rational number with the given numerator and denominator.
|
static ERational |
CreateNaN(EInteger diag)
Creates a not-a-number arbitrary-precision rational number.
|
static ERational |
CreateNaN(EInteger diag,
boolean signaling,
boolean negative)
Creates a not-a-number arbitrary-precision rational number.
|
ERational |
Divide(ERational otherValue)
Divides this instance by the value of an arbitrary-precision rational number
object.
|
boolean |
equals(ERational other)
Determines whether this object's numerator, denominator, and properties
are equal to those of another object.
|
boolean |
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.
|
static ERational |
FromByte(byte inputByte)
Converts a byte (from 0 to 255) to an arbitrary-precision rational number.
|
static ERational |
FromDouble(double flt)
Converts a 64-bit floating-point number to a rational number.
|
static ERational |
FromEDecimal(EDecimal ef)
Converts an arbitrary-precision decimal number to a rational number.
|
static ERational |
FromEFloat(EFloat ef)
Not documented yet.
|
static ERational |
FromEInteger(EInteger bigint)
Converts an arbitrary-precision integer to a rational number.
|
static ERational |
FromExtendedDecimal(EDecimal ef)
Deprecated.
Renamed to FromEDecimal.
|
static ERational |
FromExtendedFloat(EFloat ef)
Deprecated.
Renamed to FromEFloat.
|
static ERational |
FromInt16(short inputInt16)
Converts a 16-bit signed integer to an arbitrary-precision rational number.
|
static ERational |
FromInt32(int inputInt32)
Converts a 32-bit signed integer to an arbitrary-precision rational number.
|
static ERational |
FromInt64(long inputInt64)
Converts a 64-bit signed integer to an arbitrary-precision rational number.
|
static ERational |
FromSingle(float flt)
Converts a 32-bit floating-point number to a rational number.
|
static ERational |
FromString(String str)
Creates a rational number from a text string that represents a number.
|
static ERational |
FromString(String str,
int offset,
int length)
Creates a rational number from a text string that represents a
number.
|
EInteger |
getDenominator()
Gets this object's denominator.
|
EInteger |
getNumerator()
Gets this object's numerator.
|
EInteger |
getUnsignedNumerator()
Gets this object's numerator with the sign removed.
|
int |
hashCode()
Returns the hash code for this instance.
|
boolean |
isFinite()
Gets a value indicating whether this object is finite (not infinity or NaN).
|
boolean |
IsInfinity()
Gets a value indicating whether this object's value is infinity.
|
boolean |
IsNaN()
Returns whether this object is a not-a-number value.
|
boolean |
isNegative()
Gets a value indicating whether this object's value is negative (including
negative zero).
|
boolean |
IsNegativeInfinity()
Returns whether this object is negative infinity.
|
boolean |
IsPositiveInfinity()
Returns whether this object is positive infinity.
|
boolean |
IsQuietNaN()
Returns whether this object is a quiet not-a-number value.
|
boolean |
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).
|
boolean |
isZero()
Gets a value indicating whether this object's value equals 0.
|
ERational |
Multiply(ERational otherValue)
Multiplies this instance by the value of an arbitrary-precision rational
number.
|
ERational |
Negate()
Returns a rational number with the sign reversed.
|
ERational |
Remainder(ERational otherValue)
Finds the remainder that results when this instance is divided by the value
of an arbitrary-precision rational number.
|
int |
signum()
Gets the sign of this rational number.
|
ERational |
Subtract(ERational otherValue)
Subtracts an arbitrary-precision rational number from this instance.
|
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 truncating to an integer.
|
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.
|
byte |
ToByteUnchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a byte (from 0
to 255).
|
double |
ToDouble()
Converts this value to a 64-bit floating-point number.
|
EDecimal |
ToEDecimal()
Converts this rational number to a decimal number.
|
EDecimal |
ToEDecimal(EContext ctx)
Converts this rational number to a decimal number and rounds the result to
the given precision.
|
EDecimal |
ToEDecimalExactIfPossible(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
given precision.
|
EFloat |
ToEFloat()
Converts this rational number to a binary float.
|
EFloat |
ToEFloat(EContext ctx)
Converts this rational number to a binary float and rounds that result to
the given precision.
|
EFloat |
ToEFloatExactIfPossible(EContext ctx)
Converts this rational number to a binary float, but if the result would
have a nonterminating binary expansion, rounds that result to the
given precision.
|
EInteger |
ToEInteger()
Converts this value to an arbitrary-precision integer.
|
EInteger |
ToEIntegerExact()
Deprecated.
Renamed to ToEIntegerIfExact.
|
EInteger |
ToEIntegerIfExact()
Converts this value to an arbitrary-precision integer, checking whether the
value is an exact integer.
|
EDecimal |
ToExtendedDecimal()
Deprecated.
Renamed to ToEDecimal.
|
EDecimal |
ToExtendedDecimal(EContext ctx)
Deprecated.
Renamed to ToEDecimal.
|
EDecimal |
ToExtendedDecimalExactIfPossible(EContext ctx)
Deprecated.
Renamed to ToEDecimalExactIfPossible.
|
EFloat |
ToExtendedFloat()
Deprecated.
Renamed to ToEFloat.
|
EFloat |
ToExtendedFloat(EContext ctx)
Deprecated.
Renamed to ToEFloat.
|
EFloat |
ToExtendedFloatExactIfPossible(EContext ctx)
Deprecated.
Renamed to ToEFloatExactIfPossible.
|
short |
ToInt16Checked()
Converts this number's value to a 16-bit signed integer if it can fit in a
16-bit signed integer after truncating to an integer.
|
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.
|
short |
ToInt16Unchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a 16-bit
signed integer.
|
int |
ToInt32Checked()
Converts this number's value to a 32-bit signed integer if it can fit in a
32-bit signed integer after truncating to an integer.
|
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.
|
int |
ToInt32Unchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a 32-bit
signed integer.
|
long |
ToInt64Checked()
Converts this number's value to a 64-bit signed integer if it can fit in a
64-bit signed integer after truncating to an integer.
|
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.
|
long |
ToInt64Unchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a 64-bit
signed integer.
|
float |
ToSingle()
Converts this value to a 32-bit floating-point number.
|
String |
toString()
Converts this object to a text string.
|
public static final ERational NaN
public static final ERational NegativeInfinity
public static final ERational NegativeZero
public static final ERational One
public static final ERational PositiveInfinity
public static final ERational SignalingNaN
public static final ERational Ten
public static final ERational Zero
@Deprecated public ERational(EInteger numerator, EInteger denominator)
ERational
class.numerator - An arbitrary-precision integer.denominator - Another arbitrary-precision integer.NullPointerException - The parameter numerator or
denominator is null.public final EInteger getDenominator()
public final boolean isFinite()
true if this object is finite (not infinity or not-a-number
(NaN)); otherwise, false.public final boolean isNegative()
true if this object's value is negative; otherwise, false.public final boolean isZero()
true if this object's value equals 0; otherwise, . false.public final EInteger getNumerator()
public final int signum()
public final EInteger getUnsignedNumerator()
public static ERational Create(int numeratorSmall, int denominatorSmall)
numeratorSmall - The numerator.denominatorSmall - The denominator.IllegalArgumentException - The denominator is zero.public static ERational Create(EInteger numerator, EInteger denominator)
numerator - The numerator.denominator - The denominator.IllegalArgumentException - The denominator is zero.public static ERational CreateNaN(EInteger diag)
diag - A number to use as diagnostic information associated with this
object. If none is needed, should be zero.NullPointerException - The parameter diag is null.IllegalArgumentException - The parameter diag is less than 0.public static ERational CreateNaN(EInteger diag, boolean signaling, boolean negative)
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.NullPointerException - The parameter diag is null.IllegalArgumentException - The parameter diag is less than 0.public static ERational FromDouble(double flt)
flt - A 64-bit floating-point number.flt.@Deprecated public static ERational FromExtendedDecimal(EDecimal ef)
ef - An arbitrary-precision decimal number.NullPointerException - The parameter ef is null.@Deprecated public static ERational FromExtendedFloat(EFloat ef)
ef - An arbitrary-precision binary float.NullPointerException - The parameter ef is null.public static ERational FromEDecimal(EDecimal ef)
ef - An arbitrary-precision decimal number.NullPointerException - The parameter ef is null.public static ERational FromEFloat(EFloat ef)
ef - An arbitrary-precision binary float.NullPointerException - The parameter ef is null.public static ERational FromEInteger(EInteger bigint)
bigint - An arbitrary-precision integer.public static ERational FromSingle(float flt)
flt - A 32-bit floating-point number.flt.public static ERational FromString(String str)
FromString(String, int, int) for more information.str - A string that represents a number.NullPointerException - The parameter str is null.NumberFormatException - The parameter str is not a correctly
formatted number string.public static 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.
str - A text string, a portion of which represents a number.offset - A zero-based index that identifies the start of the number.length - The length of the number within the string.NullPointerException - The parameter str is null.NumberFormatException - The parameter str is not a correctly
formatted number string.public int CompareToTotalMagnitude(ERational other)
other - An arbitrary-precision rational number to compare with this
one.public int CompareToTotal(ERational other)
other - An arbitrary-precision rational number to compare with this
one.public ERational Abs()
public ERational Add(ERational otherValue)
otherValue - Another arbitrary-precision rational number.NullPointerException - The parameter otherValue is
null.public int compareTo(ERational other)
compareTo in interface Comparable<ERational>other - An arbitrary-precision rational number.public int CompareToBinary(EFloat other)
other - An arbitrary-precision binary float.public int CompareToDecimal(EDecimal other)
other - An arbitrary-precision decimal number.public ERational CopySign(ERational other)
other - A number whose sign will be copied.NullPointerException - The parameter other is null.public ERational Divide(ERational otherValue)
otherValue - An arbitrary-precision rational number.NullPointerException - The parameter otherValue is
null.public boolean equals(Object obj)
public boolean equals(ERational other)
other - The parameter other is not documented yet.public int hashCode()
public boolean IsInfinity()
true if this object's value is infinity; otherwise, false.public boolean IsNaN()
true if this object is a not-a-number value; otherwise,
false.public boolean IsNegativeInfinity()
true if this object is negative infinity; otherwise, false.public boolean IsPositiveInfinity()
true if this object is positive infinity; otherwise, false.public boolean IsQuietNaN()
true if this object is a quiet not-a-number value;
otherwise, false.public boolean IsSignalingNaN()
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.public ERational Multiply(ERational otherValue)
otherValue - An arbitrary-precision rational number.NullPointerException - The parameter otherValue is
null.public ERational Negate()
public ERational Remainder(ERational otherValue)
otherValue - An arbitrary-precision rational number.NullPointerException - The parameter otherValue is
null.public ERational Subtract(ERational otherValue)
otherValue - An arbitrary-precision rational number.NullPointerException - The parameter otherValue is
null.public double ToDouble()
public EInteger ToEInteger()
ArithmeticException - This object's value is infinity or
not-a-number (NaN).@Deprecated public EInteger ToEIntegerExact()
ArithmeticException - This object's value is infinity or
not-a-number (NaN).ArithmeticException - This object's value is not an exact integer.public EInteger ToEIntegerIfExact()
ArithmeticException - This object's value is infinity or
not-a-number (NaN).ArithmeticException - This object's value is not an exact integer.public EDecimal ToEDecimal()
public EDecimal ToEDecimal(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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
the precision is unlimited and no rounding is needed.public EDecimal ToEDecimalExactIfPossible(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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 the precision is unlimited and no
rounding is needed.@Deprecated public EDecimal ToExtendedDecimal()
@Deprecated public EDecimal ToExtendedDecimal(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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
the precision is unlimited and no rounding is needed.@Deprecated public EDecimal ToExtendedDecimalExactIfPossible(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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 the precision is unlimited and no
rounding is needed.public EFloat ToEFloat()
public EFloat ToEFloat(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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
the precision is unlimited and no rounding is needed.public EFloat ToEFloatExactIfPossible(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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 the precision is unlimited and no
rounding is needed.@Deprecated public EFloat ToExtendedFloat()
@Deprecated public EFloat ToExtendedFloat(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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
the precision is unlimited and no rounding is needed.@Deprecated public EFloat ToExtendedFloatExactIfPossible(EContext ctx)
ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. 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 the precision is unlimited and no
rounding is needed.public float ToSingle()
public String toString()
public byte ToByteChecked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than 0 or greater than 255.public byte ToByteUnchecked()
public byte ToByteIfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than 0 or greater than 255.public static ERational FromByte(byte inputByte)
inputByte - The number to convert as a byte (from 0 to 255).public short ToInt16Checked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than -32768 or greater than 32767.public short ToInt16Unchecked()
public short ToInt16IfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than -32768 or greater than 32767.public static ERational FromInt16(short inputInt16)
inputInt16 - The number to convert as a 16-bit signed integer.public int ToInt32Checked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than -2147483648 or greater than
2147483647.public int ToInt32Unchecked()
public int ToInt32IfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than -2147483648 or greater than
2147483647.public static ERational FromInt32(int inputInt32)
inputInt32 - The number to convert as a 32-bit signed integer.public long ToInt64Checked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than -9223372036854775808 or greater
than 9223372036854775807.public long ToInt64Unchecked()
public long ToInt64IfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than -9223372036854775808 or greater
than 9223372036854775807.public static ERational FromInt64(long inputInt64)
inputInt64 - The number to convert as a 64-bit signed integer.CBOR for Java documentation, generated in 2016.