Class Quadruple
- All Implemented Interfaces:
Serializable
,Comparable<Quadruple>
2.271e-646456993
to 1.761e+646456993
with precision not worse than 1,469368e-39
(2^-129
, half the less significant bit).
Like standard double
, it can store and process subnormal values,
with lower precision. The subnormal values range from 6.673e-646457032
to 2.271e-646456993
, they use less than 129 bits of the mantissa and their
precision depends on the number of used bits, the less the value the worse the precision.
Implements conversions from/to other numeric types, conversions from/to strings, formatting, arithmetic operations and square root.
Instances are mutable, a.add(2)
changes the value of a
so that it becomes
a + 2
, and a number of assign()
methods with different types of arguments
replace the old value with the new one, converted from the argument value.
For arithmetic operations, there provided both instance methods that modify the value of the instance, and static methods that return new instances with resulting values without changing the operands. A value of any numeric type may be used as an argument (the second one for static methods) in arithmetic operations. All the methods implementing arithmetic operations and assignments allow for chaining, so that one can write
a = a.add(2).multiply(5).divide(3);
to compute
a = (a + 2) * 5 / 3
.
The class is not thread safe. Different threads should not simultaneously perform operations even with different instances of the class.
An instance internally contains boolean flag for the value's sign,
32-bit (an int
) of binary exponent, and 128 bits (2 longs
) of fractional part of the mantissa.
Like with usual floating-point formats (e.g. standard Java double
), the most significant
bit of the mantissa is not stored explicitly and the exponent is biased.
The biased exponent values stored in the exponent
field are as following:
biased value | const name | means | unbiased exponent (power of 2) |
---|---|---|---|
0x0000_0000 |
EXPONENT_OF_SUBNORMAL |
subnormal values | 0x8000_0001 = -2147483647 = Integer.MIN_VALUE + 1 |
0x0000_0001 |
EXPONENT_OF_MIN_NORMAL |
MIN_NORMAL |
0x8000_0002 = -2147483646 = Integer.MIN_VALUE + 2 |
0x7FFF_FFFE |
-1 |
0xFFFF_FFFF |
|
0x7FFF_FFFF |
EXPONENT_OF_ONE |
0 |
0x0000_0000 |
0x8000_0000 |
1 |
0x0000_0001 |
|
0xFFFF_FFFE |
EXPONENT_OF_MAX_VALUE |
MAX_VALUE |
0x7fff_ffff = 2147483647 = Integer.MAX_VALUE |
0xFFFF_FFFF |
EXPONENT_OF_INFINITY |
Infinity |
0x8000_0000 = 2147483648 = Integer.MIN_VALUE |
The boundaries of the range are:
MAX_VALUE: 2^2147483647 * (2 - 2^-128) =
= 1.76161305168396335320749314979184028566452310e+646456993
MIN_NORMAL: 2^-2147483646 =
= 2.27064621040149253752656726517958758124747730e-646456993
MIN_VALUE: 2^-2147483774 =
= 6.67282948260747430814835377499134611597699952e-646457032
- Author:
- M.Vokhmentsev
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Deprecated.static final long
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
The value of the exponent (biased) corresponding to1.0 == 2^0
; equals to 2_147_483_647 (0x7FFF_FFFF
) The same asEXPONENT_OF_ONE
static final int
The value of the exponent (biased), corresponding toInfinity
,_Infinty
, andNaN
; equals to -1 (0xFFFF_FFFF
)static final long
The value of the exponent (biased), corresponding toMAX_VALUE
; equals to 4_294_967_294L (0xFFFF_FFFEL
)static final int
The value of the exponent (biased) corresponding toMIN_NORMAL
; equals to 1static final int
The value of the exponent (biased) corresponding to1.0 == 2^0
; equals to 2_147_483_647 (0x7FFF_FFFF
).static final int
The value of the exponent (biased) corresponding to subnormal values; equals to 0 -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofQuadruple
with value 0.0Quadruple
(boolean negative, int exponent, long mantHi, long mantLo) Creates a newQuadruple
built from the given parts.Quadruple
(double dValue) Creates a newQuadruple
instance with the givendouble
value.
First creates an empty (zero) instance, then assigns the given value to the new instance, usingassign(double)
.Quadruple
(int exponent, long mantHi, long mantLo) Creates a newQuadruple
with a positive value built from the given parts.Quadruple
(long lValue) Creates a newQuadruple
with the givenlong
value.
First creates an empty (zero) instance, then assigns the given value to the new instance, usingassign(long)
.Creates a newQuadruple
instance with the value of the givenQuadruple
instance.
First creates an empty (zero) instance, then copies the fields of the parameter.Creates a newQuadruple
with the value represented by the givenString
.
First creates an empty (zero) instance, then assigns the given value to the new instance, converting the string to the corresponding floating-point value.Quadruple
(BigDecimal bdValue) Creates a newQuadruple
with the value of the givenBigDecimal
instance.
First creates an empty (zero) instance, then assigns the given value to the new instance, converting the BigDecimal to respective floating-point value -
Method Summary
Modifier and TypeMethodDescriptionabs()
Returns a new instance ofQuadruple
with the value of the absolute value of this instanceadd
(double summand) Adds the value of the givendouble
summand to the value of this Quadruple.add
(long summand) Adds the value of the givenlong
summand to the value of this Quadruple.Adds the value of the givenQuadruple
summand to the value of this Quadruple.static Quadruple
Adds the value of the givendouble op2
to the value ofQuadruple op1
and creates a new instance of Quadruple containing the sum.static Quadruple
Adds the value of the givenlong op2
to the value ofQuadruple op1
and creates a new instance of Quadruple containing the sum.static Quadruple
Adds the value of the givenQuadruple op2
to the value ofQuadruple op1
and creates a new instance of Quadruple containing the sum.assign
(boolean negative, int exponent, long mantHi, long mantLo) Builds a Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the biased exponent value, so that its value equal toEXPONENT_OF_ONE
(0xFFFF_FFFEL
) corresponds to theQuadruple
value of 1.0.assign
(double value) Converts the given value to quadruple and assigns it to the instance.
Expands exponent to 32 bits preserving its value, and expands mantissa to 128 bits, filling with zeroes the least significant 76 bits that absent in the double value.assign
(int exponent, long mantHi, long mantLo) Builds a non-negative Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the biased exponent value, so that its value equal toEXPONENT_OF_ONE
(0xFFFF_FFFEL
) corresponds to theQuadruple
value of 1.0.assign
(long value) Converts the given value to quadruple and assigns it to the instance.
To find the mantissa, shifts the bits of the absolute value of the parameter left, so that its most significant non-zero bit (that stands for the 'implicit unity' of the floating point formats) gets shifted out, then corrects the exponent depending on the shift distance and sets the sign in accordance with the initial sign of the parameter.assign
(long[] value) Builds a Quadruple from the low-level parts given as an array oflong
.
The elements of the array are expected to contain the following values:Assigns the given value to the instance (copies the values of the private fields of the parameter to the respective fields of this instance).Parses the given String that is expected to contain floating-point value in any conventional string form or a string designation of one of special values, and assigns the corresponding value to the instance.
Parsing is case-insensitive.
The admittable string designations for special values are the following: "Quadruple.MIN_VALUE", "MIN_VALUE", "Quadruple.MAX_VALUE", "MAX_VALUE", "Quadruple.MIN_NORMAL", "MIN_NORMAL", "Quadruple.NaN", "NaN", "Quadruple.NEGATIVE_INFINITY", "NEGATIVE_INFINITY", "-INFINITY", "Quadruple.POSITIVE_INFINITy", "POSITIVE_INFINITY", "INFINITY", "+INFINITY".
If the exact value of the number represented by the input string is greater than the nearest exactQuadruple
value by less than0.5 - 1e-17
of the least significant bit of the mantissa of the latter, it gets rounded down to the aforementionedQuadruple
value.
If it is greater by 0.5 LSB or more, it gets rounded up to the greater adjacent Quadruple value.
In cases when difference between the input value and the nearestQuadruple
value is between(0.5 - 1e-17) * LSB
and0.5 * LSB
, the direction of the rounding is unpredictable.assign
(BigDecimal value) Converts the given value toQuadruple
, and assigns it to the instance.
If the source value can't be represented asQuadruple
exactly, it gets rounded to a 129-bit value (implicit unity + 128 bits of the fractional part of the mantissa) according to the 'half-up' rule.assignIeee754
(byte[] value) Assigns the value of a IEEE-754 quadruple value passed in as an array of 16byte
s containing the 128 bits of the IEEE-754 quadruple to the given instance.
The passed in array of longs is expected to be big-endian, in other words thevalue[0]
should contain the sign bit, and the high-order 7 bits of the IEEE-754 quadruple's exponent, and thevalue[15]
is expected to contain the least significant 8 bits of the significand.
The argument remains unchanged.assignIeee754
(long[] value) Assigns the value of a IEEE-754 quadruple value passed in as an array of twolong
s containing the 128 bits of the IEEE-754 quadruple to the given instance.
The passed in array of longs is expected to be big-endian, in other words thevalue[0]
should contain the sign bit, the exponent, and the most significant 48 bits of the significand.
The argument remains unchanged.Assigns to this instance the maximum of the values ofthis
instance and the operand.Assigns to this instance the minimum of the values ofthis
instance and the operand.Assigns the value of "Not a Number" (NaN
) to this instance.Assigns the value of-Infinity
to this instance.Assigns the value of+Infinity
to this instance.assignWithUnbiasedExponent
(boolean negative, int exponent, long mantHi, long mantLo) Builds a Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the unbiased exponent value, whose0
value corresponds to theQuadruple
value of 1.0.assignWithUnbiasedExponent
(int exponent, long mantHi, long mantLo) Builds a non-negative Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the unbiased exponent value, whose0
value corresponds to theQuadruple
value of 1.0.Builds and returns aBigDecimal
instance holding the same value as the given Quadruple (rounded to 100 significant decimal digits).static int
Compares the values of two instances.static int
compareMagnitudes
(Quadruple q1, Quadruple q2) Compares the magnitudes (absolute values) of the two Quadruples.int
compareMagnitudeTo
(Quadruple other) Compares the magnitude (absolute value) of this instance with the magnitude of the other instance.int
compareTo
(double other) Compares the value of this instance with the specifieddouble
value.int
compareTo
(long other) Compares the value of this instance with the specifiedlong
value.int
Compares the value of this instance with the value of the specified instance.divide
(double divisor) Divides the value of this Quadruple by the value of the givendouble
divisor.divide
(long divisor) Divides the value of this Quadruple by the value of the givenlong
divisor.Divides the value of this Quadruple by the value of the givenQuadruple
divisor.static Quadruple
Divides the value of the given dividend by the value of the givendouble
divisor, creates and returns a new instance of Quadruple containing the quotient.static Quadruple
Divides the value of the given dividend by the value of the givenlong
divisor, creates and returns a new instance of Quadruple containing the quotient.static Quadruple
Divides the value of the given dividend by the value of the givenQuadruple
divisor, creates and returns a new instance of Quadruple containing the quotient.double
Converts the value of thisQuadruple
to adouble
value in a way similar to standard narrowing conversions (e.g., fromdouble
tofloat
).boolean
Indicates whether the otherQuadruple
is equal to this one.int
exponent()
Returns the raw (biased) value of the binary exponent of the value i. e. 0x7FFF_FFFF for values falling within the interval of[1.0 .. 2.0)
, 0x8000_0000 for[2.0 .. 4.0)
etc.float
Converts the value of thisQuadruple
to afloat
value in a way similar to standard narrowing conversions (e.g., fromdouble
tofloat
).Returns aString
representing the value of this instance in a form defined by theformat
parameter.int
hashCode()
Computes a hashcode for thisQuadruple
, based on the values of its fields.int
intValue()
Converts the value of thisQuadruple
to anint
value in a way similar to standard narrowing conversions (e.g., fromdouble
toint
).boolean
Checks if the value is infinite (i.eNEGATIVE_INFINITY
orPOSITIVE_INFINITY
).boolean
isNaN()
Checks if the value is not a number (i.e. has the value ofNaN
).boolean
Checks if the value is negative.boolean
isZero()
Checks if the value is zero, either positive or negative.long
Converts the value of thisQuadruple
to along
value in a way similar to standard narrowing conversions (e.g., fromdouble
tolong
).long
mantHi()
Returns the most significant 64 bits of the fractional part of the mantissa.long
mantLo()
Returns the least significant 64 bits of the fractional part of the mantissastatic Quadruple
Returns a new instance ofQuadruple
with the value of the maximum of the values of the operands.static Quadruple
maxValue()
Returns a newQuadruple
instance with the value ofMAX_VALUE
(2^2147483647 * (2 - 2^-128)
= 1.76161305168396335320749314979184028566452310e+646456993)static Quadruple
Returns a new instance ofQuadruple
with the value of the minimum of the values of the operands.static Quadruple
Returns a newQuadruple
instance with the value ofMIN_NORMAL
(2^-2147483646
= 2.27064621040149253752656726517958758124747730e-646456993)static Quadruple
minValue()
Returns a newQuadruple
instance with the value ofMIN_VALUE
(2^-2147483774
= 6.67282948260747430814835377499134611597699952e-646457032)multiply
(double factor) Multiplies the value of this Quadruple by the value of the givendouble
factor.multiply
(long factor) Multiplies the value of this Quadruple by the value of the givenlong
factor.Multiplies the value of this Quadruple by the value of the givenQuadruple
factor.static Quadruple
Multiplies the value of the givenQuadruple factor1
by thedouble factor2
, creates and returns a new instance of Quadruple containing the product.static Quadruple
Multiplies the value of the givenQuadruple factor1
by thelong factor2
, creates and returns a new instance of Quadruple containing the product.static Quadruple
Multiplies the value of the givenQuadruple factor1
by theQuadruple factor2
, creates and returns a new instance of Quadruple containing the product.static Quadruple
nan()
Returns a newQuadruple
instance with the value ofNaN
.negate()
Changes the sign of this Quadruple.static Quadruple
Returns a newQuadruple
instance with the value of-Infinity
.static Quadruple
Creates a new Quadruple instance with a pseudo-random value using a static randomly initializedjava.util.Random
instance.static Quadruple
nextRandom
(Random rand) Creates a new Quadruple instance with a pseudo-random value using the givenjava.util.Random
instance.static Quadruple
one()
Returns a newQuadruple
instance with the value of 1.0.static Quadruple
pi()
Returns a newQuadruple
instance with the value of the numberπ
(pi) (3.141592653589793238462643383279502884195)static Quadruple
Returns a newQuadruple
instance with the value of+Infinity
.int
signum()
Returns 1 for positive values, -1 for negative values (including -0), and 0 for the positive zero valuesqrt()
Computes a square root of the value of thisQuadruple
and replaces the old value of this instance with the newly-computed value.static Quadruple
Computes a square root of the value of the givenQuadruple
, creates and returns a new instance of Quadruple containing the value of the square root.subtract
(double subtrahend) Subtracts the value of the givendouble
subtrahend from the value of this Quadruple.subtract
(long subtrahend) Subtracts the value of the givenlong
subtrahend from the value of this Quadruple.Subtracts the value of the givenQuadruple
subtrahend from the value of this Quadruple.static Quadruple
Subtracts the value of thedouble
subtrahend
from the value of theminuend
, creates and returns a new instance of Quadruple that contains the difference.static Quadruple
Subtracts the value of thelong
subtrahend
from the value of theminuend
, creates and returns a new instance of Quadruple that contains the difference.static Quadruple
Subtracts the value of theQuadruple
subtrahend
from the value of theminuend
, creates and returns a new instance of Quadruple that contains the difference.static Quadruple
ten()
Returns a newQuadruple
instance with the value of 10.0.Returns aString
containing a hexadecimal representation of the instance's value, consisting of sign, two 64-bit words of mantissa, and exponent preceded by letter 'e', with '_' separating the tetrads of hexadecimal digits.byte[]
Returns the 128 bits of an IEEE-754 quadruple precision number nearest to the value ofthis
instance as an array of 16byte
s, containing a physical representation of the standard IEEE-754 quadruple-precision floating-point number.
The order of bytes is big-endian, so that the sign bit and the most significant bits of the exponent is returned in result[0], and the least significant bits of the mantissa in result[15].long[]
Returns the 128 bits of an IEEE-754 quadruple precision number nearest to the value ofthis
instance as an array of twolong
s, containing a physical representation of the standard IEEE-754 quadruple-precision floating-point number.
The order of words is big-endian, so that the sign bit, exponent and 48 most significant bits of the mantissa are returned in result[0], and 64 least significant bits of the mantissa in result[1].long[]
Returns the fields of the instance that make up it's value as an array oflong
s.
The elements of the array contain the following values:toString()
Returns a decimal string representation of the value of thisQuadruple
in a scientific (exponential) notation, rounded to 43 digits after point.
For other String representations, seeformat(String)
static Quadruple
two()
Returns a newQuadruple
instance with the value of 2.0.int
Returns the unbiased value of binary exponent, i. e. 0 for values falling within the interval of[1.0 .. 2.0)
, 1 for[2.0 .. 4.0)
etc.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
EXP_SUB
Deprecated.The value of the exponent (biased) corresponding to subnormal values; equals to 0 Deprecated, will be removed in release version. UseEXPONENT_OF_SUBNORMAL
instead- See Also:
-
EXPONENT_OF_SUBNORMAL
public static final int EXPONENT_OF_SUBNORMALThe value of the exponent (biased) corresponding to subnormal values; equals to 0- See Also:
-
EXP_MIN
Deprecated.The value of the exponent (biased) corresponding toMIN_NORMAL
; equals to 1 Deprecated, will be removed in release version. UseEXPONENT_OF_MIN_NORMAL
instead- See Also:
-
EXPONENT_OF_MIN_NORMAL
public static final int EXPONENT_OF_MIN_NORMALThe value of the exponent (biased) corresponding toMIN_NORMAL
; equals to 1- See Also:
-
EXP_OF_ONE
Deprecated.The value of the exponent (biased) corresponding to1.0 == 2^0
; equals to 2_147_483_647 (0x7FFF_FFFF
) Deprecated, will be removed in release version. UseEXPONENT_OF_ONE
instead- See Also:
-
EXPONENT_OF_ONE
public static final int EXPONENT_OF_ONEThe value of the exponent (biased) corresponding to1.0 == 2^0
; equals to 2_147_483_647 (0x7FFF_FFFF
). The same asEXPONENT_BIAS
- See Also:
-
EXPONENT_BIAS
public static final int EXPONENT_BIASThe value of the exponent (biased) corresponding to1.0 == 2^0
; equals to 2_147_483_647 (0x7FFF_FFFF
) The same asEXPONENT_OF_ONE
- See Also:
-
EXP_MAX
Deprecated.The value of the exponent (biased), corresponding toMAX_VALUE
; equals to 4_294_967_294L (0xFFFF_FFFEL
) Deprecated, will be removed in release version. UseEXPONENT_OF_MAX_VALUE
instead- See Also:
-
EXPONENT_OF_MAX_VALUE
public static final long EXPONENT_OF_MAX_VALUEThe value of the exponent (biased), corresponding toMAX_VALUE
; equals to 4_294_967_294L (0xFFFF_FFFEL
)- See Also:
-
EXP_INF
Deprecated.The value of the exponent (biased), corresponding toInfinity
,_Infinty
, andNaN
; equals to -1 (0xFFFF_FFFF
) Deprecated, will be removed in release version. UseEXPONENT_OF_INFINITY
instead- See Also:
-
EXPONENT_OF_INFINITY
public static final int EXPONENT_OF_INFINITYThe value of the exponent (biased), corresponding toInfinity
,_Infinty
, andNaN
; equals to -1 (0xFFFF_FFFF
)- See Also:
-
-
Constructor Details
-
Quadruple
public Quadruple()Creates a new instance ofQuadruple
with value 0.0 -
Quadruple
Creates a newQuadruple
instance with the value of the givenQuadruple
instance.
First creates an empty (zero) instance, then copies the fields of the parameter. to the fields of the new instance- Parameters:
qValue
- theQuadruple
value to be assigned to the new instance.
-
Quadruple
public Quadruple(double dValue) Creates a newQuadruple
instance with the givendouble
value.
First creates an empty (zero) instance, then assigns the given value to the new instance, usingassign(double)
.- Parameters:
dValue
- thedouble
value to be assigned
-
Quadruple
public Quadruple(long lValue) Creates a newQuadruple
with the givenlong
value.
First creates an empty (zero) instance, then assigns the given value to the new instance, usingassign(long)
.- Parameters:
lValue
- thelong
value to be assigned
-
Quadruple
Creates a newQuadruple
with the value represented by the givenString
.
First creates an empty (zero) instance, then assigns the given value to the new instance, converting the string to the corresponding floating-point value. Some non-standard string designations for special values are admissible, seeassign(String)
- Parameters:
strValue
- theString
value to be assigned- See Also:
-
Quadruple
Creates a newQuadruple
with the value of the givenBigDecimal
instance.
First creates an empty (zero) instance, then assigns the given value to the new instance, converting the BigDecimal to respective floating-point value- Parameters:
bdValue
- theBigDecimal
value to be assigned
-
Quadruple
public Quadruple(boolean negative, int exponent, long mantHi, long mantLo) Creates a newQuadruple
built from the given parts.- Parameters:
negative
- the sign of the value (true
signifies negative values)exponent
- the binary exponent (unbiased)mantHi
- the most significant 64 bits of fractional part of the mantissamantLo
- the least significant 64 bits of fractional part of the mantissa
-
Quadruple
public Quadruple(int exponent, long mantHi, long mantLo) Creates a newQuadruple
with a positive value built from the given parts.- Parameters:
exponent
- the binary exponent (unbiased)mantHi
- the most significant 64 bits of fractional part of the mantissamantLo
- the least significant 64 bits of fractional part of the mantissa
-
-
Method Details
-
negativeInfinity
Returns a newQuadruple
instance with the value of-Infinity
.- Returns:
- a new
Quadruple
instance with the value of NEGATIVE_INFINITY
-
positiveInfinity
Returns a newQuadruple
instance with the value of+Infinity
.- Returns:
- a new
Quadruple
instance with the value of POSITIVE_INFINITY
-
nan
Returns a newQuadruple
instance with the value ofNaN
.- Returns:
- a new
Quadruple
instance with the value of NAN
-
one
Returns a newQuadruple
instance with the value of 1.0.- Returns:
- a new
Quadruple
instance with the value of 1.0
-
two
Returns a newQuadruple
instance with the value of 2.0.- Returns:
- a new
Quadruple
instance with the value of 2.0
-
ten
Returns a newQuadruple
instance with the value of 10.0.- Returns:
- a new
Quadruple
instance with the value of 10.0
-
minValue
Returns a newQuadruple
instance with the value ofMIN_VALUE
(2^-2147483774
= 6.67282948260747430814835377499134611597699952e-646457032)- Returns:
- a new
Quadruple
instance with the value of MIN_VALUE
-
maxValue
Returns a newQuadruple
instance with the value ofMAX_VALUE
(2^2147483647 * (2 - 2^-128)
= 1.76161305168396335320749314979184028566452310e+646456993)- Returns:
- a new
Quadruple
instance with the value ofMAX_VALUE
-
minNormal
Returns a newQuadruple
instance with the value ofMIN_NORMAL
(2^-2147483646
= 2.27064621040149253752656726517958758124747730e-646456993)- Returns:
- a new
Quadruple
instance with the value ofMIN_NORMAL
-
pi
Returns a newQuadruple
instance with the value of the numberπ
(pi) (3.141592653589793238462643383279502884195)- Returns:
- a new
Quadruple
instance with the value of the numberπ
(pi)
-
exponent
public int exponent()Returns the raw (biased) value of the binary exponent of the value i. e. 0x7FFF_FFFF for values falling within the interval of[1.0 .. 2.0)
, 0x8000_0000 for[2.0 .. 4.0)
etc.- Returns:
- the raw (biased) value of the binary exponent of the value
-
unbiasedExponent
public int unbiasedExponent()Returns the unbiased value of binary exponent, i. e. 0 for values falling within the interval of[1.0 .. 2.0)
, 1 for[2.0 .. 4.0)
etc.- Returns:
- the unbiased value of binary exponent
-
mantHi
public long mantHi()Returns the most significant 64 bits of the fractional part of the mantissa.- Returns:
- the most significant 64 bits of the fractional part of the mantissa
-
mantLo
public long mantLo()Returns the least significant 64 bits of the fractional part of the mantissa- Returns:
- the least significant 64 bits of the fractional part of the mantissa
-
isNegative
public boolean isNegative()Checks if the value is negative.- Returns:
true
, if the value is negative,false
otherwise
-
isInfinite
public boolean isInfinite()Checks if the value is infinite (i.eNEGATIVE_INFINITY
orPOSITIVE_INFINITY
).- Returns:
true
, if the value is infinity (either positive or negative),false
otherwise
-
isNaN
public boolean isNaN()Checks if the value is not a number (i.e. has the value ofNaN
).- Returns:
true
, if the value is not a number (NaN),false
otherwise
-
isZero
public boolean isZero()Checks if the value is zero, either positive or negative.- Returns:
true
, if the value is 0 or -0, otherwise returns
-
assign
Assigns the given value to the instance (copies the values of the private fields of the parameter to the respective fields of this instance).- Parameters:
qValue
- aQuadruple
instance whose value is to assign- Returns:
- this instance with the newly assigned value
-
assign
Converts the given value to quadruple and assigns it to the instance.
Expands exponent to 32 bits preserving its value, and expands mantissa to 128 bits, filling with zeroes the least significant 76 bits that absent in the double value. Subnormal double values(Double.MIN_NORMAL < v <= Double.MIN_VALUE)
are converted to normal quadruple values, by shifting them leftwards and correcting the exponent accordingly.- Parameters:
value
- thedouble
value to be assigned.- Returns:
- this instance with the newly assigned value
-
assign
Converts the given value to quadruple and assigns it to the instance.
To find the mantissa, shifts the bits of the absolute value of the parameter left, so that its most significant non-zero bit (that stands for the 'implicit unity' of the floating point formats) gets shifted out, then corrects the exponent depending on the shift distance and sets the sign in accordance with the initial sign of the parameter.- Parameters:
value
- thelong
value to be assigned- Returns:
- this instance with the newly assigned value
-
assign
Parses the given String that is expected to contain floating-point value in any conventional string form or a string designation of one of special values, and assigns the corresponding value to the instance.
Parsing is case-insensitive.
The admittable string designations for special values are the following:- "Quadruple.MIN_VALUE",
- "MIN_VALUE",
- "Quadruple.MAX_VALUE",
- "MAX_VALUE",
- "Quadruple.MIN_NORMAL",
- "MIN_NORMAL",
- "Quadruple.NaN",
- "NaN",
- "Quadruple.NEGATIVE_INFINITY",
- "NEGATIVE_INFINITY",
- "-INFINITY",
- "Quadruple.POSITIVE_INFINITy",
- "POSITIVE_INFINITY",
- "INFINITY",
- "+INFINITY".
If the exact value of the number represented by the input string is greater than the nearest exactQuadruple
value by less than0.5 - 1e-17
of the least significant bit of the mantissa of the latter, it gets rounded down to the aforementionedQuadruple
value.
If it is greater by 0.5 LSB or more, it gets rounded up to the greater adjacent Quadruple value.
In cases when difference between the input value and the nearestQuadruple
value is between(0.5 - 1e-17) * LSB
and0.5 * LSB
, the direction of the rounding is unpredictable. Expressing it via formulas,(1 + (n + d) * 2^-128) * 2^e ==> (1 + n * 2^-128) * 2^e, if d <= 0.5 - 1e-17; (1 + (n + d) * 2^-128) * 2^e ==> (1 + (n + 1) * 2^-128) * 2^e, if d => 0.5.
where n is an integer less than2^128
, e is the exponent of theQuadruple
.
For example,1.5 + 0.5 * 2^-128
, that equals
1.500000000000000000000000000000000000001469367938527859384960921...
gets rounded up to
1.5000000000000000000000000000000000000029387
, whose mantissa is0x8000_..._0001
,
while1.5 + (0.5 - 1e-17) * 2^-128
, that equals to
1.500000000000000000000000000000000000001469367938527859355573561...
gets rounded down to 1.5, whose mantissa is0x8000_..._0000
.
The values between the two may get rounded either up or down.- Parameters:
source
- the String to be parsed- Returns:
- this instance with the newly assigned value
- Throws:
NullPointerException
- if the input string isnull
NumberFormatException
- if the input string does not contain valid value
-
assign
Converts the given value toQuadruple
, and assigns it to the instance.
If the source value can't be represented asQuadruple
exactly, it gets rounded to a 129-bit value (implicit unity + 128 bits of the fractional part of the mantissa) according to the 'half-up' rule. Due to limited precision of computing of great powers of two, the input values that differ from exact values of correspondingQuadruples
by a value that lies between(0.5 - 1e-40) * LSB
and0.5 * LSB
may get rounded either up or down.- Parameters:
value
- the value to be assigned.- Returns:
- this instance with the newly assigned value
- Throws:
NullPointerException
- if the parameter isnull
-
assign
Builds a Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the biased exponent value, so that its value equal toEXPONENT_OF_ONE
(0xFFFF_FFFEL
) corresponds to theQuadruple
value of 1.0.- Parameters:
negative
- the sign of the value (true
for negative)exponent
- Binary exponent (biased, so that 0x7FFF_FFFF corresponds to 2^0)mantHi
- The most significant 64 bits of the fractional part of the mantissamantLo
- The least significant 64 bits of the fractional part of the mantissa- Returns:
- A
Quadruple
containing the value built of the given parts
-
assignWithUnbiasedExponent
public Quadruple assignWithUnbiasedExponent(boolean negative, int exponent, long mantHi, long mantLo) Builds a Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the unbiased exponent value, whose0
value corresponds to theQuadruple
value of 1.0.- Parameters:
negative
- the sign of the value (true
for negative)exponent
- Binary exponent (unbiased, 0 means 2^0)mantHi
- The higher 64 bits of the fractional part of the mantissamantLo
- The lower 64 bits of the fractional part of the mantissa- Returns:
- A Quadruple containing the value built of the given parts
-
assign
Builds a non-negative Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the biased exponent value, so that its value equal toEXPONENT_OF_ONE
(0xFFFF_FFFEL
) corresponds to theQuadruple
value of 1.0.- Parameters:
exponent
- Binary exponent (biased, 0x7FFF_FFFF means 2^0)mantHi
- The most significant 64 bits of the fractional part of the mantissamantLo
- The least significant 64 bits of the fractional part of the mantissa- Returns:
- A Quadruple containing the value built of the given parts
-
assignWithUnbiasedExponent
Builds a non-negative Quadruple value from the given low-level parts and assigns it to the instance.
Treats theexponent
parameter as the unbiased exponent value, whose0
value corresponds to theQuadruple
value of 1.0.- Parameters:
exponent
- Binary exponent (unbiased, 0 means 2^0)mantHi
- The most significant 64 bits of the fractional part of the mantissamantLo
- The least significant 64 bits of the fractional part of the mantissa- Returns:
- A Quadruple containing the value built of the given parts
-
assign
Builds a Quadruple from the low-level parts given as an array oflong
.
The elements of the array are expected to contain the following values:value[0] -- sign flag in bit 63 (1 means negative), biased exponent in bits 31 .. 0 value[1] -- The most significant 64 bits of the fractional part of the mantissa value[2] -- The most significant 64 bits of the fractional part of the mantissa
- Parameters:
value
- array oflong
containing the low-level parts of the Quadruple value- Returns:
- the instance after assigning it the required value
- See Also:
-
assignIeee754
Assigns the value of a IEEE-754 quadruple value passed in as an array of twolong
s containing the 128 bits of the IEEE-754 quadruple to the given instance.
The passed in array of longs is expected to be big-endian, in other words thevalue[0]
should contain the sign bit, the exponent, and the most significant 48 bits of the significand.
The argument remains unchanged.- Parameters:
value
- an array of two longs, containing the 128 bits of the IEEE-754 quadruple value to be assigned- Returns:
- this instance with the newly assigned value
- Throws:
IllegalArgumentException
- if the length of the input array is not 2
-
assignIeee754
Assigns the value of a IEEE-754 quadruple value passed in as an array of 16byte
s containing the 128 bits of the IEEE-754 quadruple to the given instance.
The passed in array of longs is expected to be big-endian, in other words thevalue[0]
should contain the sign bit, and the high-order 7 bits of the IEEE-754 quadruple's exponent, and thevalue[15]
is expected to contain the least significant 8 bits of the significand.
The argument remains unchanged.- Parameters:
value
- an array of 16 bytes, containing the 128 bits of the IEEE-754 quadruple value to be assigned- Returns:
- this instance with the newly assigned value
- Throws:
IllegalArgumentException
- if the length of the input array is not 16
-
assignPositiveInfinity
Assigns the value of+Infinity
to this instance.- Returns:
- this instance with the value of
POSITIVE_INFINITY
-
assignNegativeInfinity
Assigns the value of-Infinity
to this instance.- Returns:
- this instance with the value of
NEGATIVE_INFINITY
-
assignNaN
Assigns the value of "Not a Number" (NaN
) to this instance.- Returns:
- this instance with the value of
NaN
-
intValue
public int intValue()Converts the value of thisQuadruple
to anint
value in a way similar to standard narrowing conversions (e.g., fromdouble
toint
). -
longValue
public long longValue()Converts the value of thisQuadruple
to along
value in a way similar to standard narrowing conversions (e.g., fromdouble
tolong
). -
floatValue
public float floatValue()Converts the value of thisQuadruple
to afloat
value in a way similar to standard narrowing conversions (e.g., fromdouble
tofloat
).- Specified by:
floatValue
in classNumber
- Returns:
- the value of this
Quadruple
instance converted to afloat
.
-
doubleValue
public double doubleValue()Converts the value of thisQuadruple
to adouble
value in a way similar to standard narrowing conversions (e.g., fromdouble
tofloat
). Uses 'half-even' approach to the rounding, likeBigDecimal.doubleValue()
- Specified by:
doubleValue
in classNumber
- Returns:
- the value of this
Quadruple
instance converted to adouble
.
-
bigDecimalValue
Builds and returns aBigDecimal
instance holding the same value as the given Quadruple (rounded to 100 significant decimal digits).- Returns:
- a
BigDecimal
holding the same value as the givenQuadruple
- Throws:
NumberFormatException
- if the value of the instance is not convertible toBigDecimal
(i.e. it isInfinity
,-Infinity
, orNaN
)
-
toString
Returns a decimal string representation of the value of thisQuadruple
in a scientific (exponential) notation, rounded to 43 digits after point.
For other String representations, seeformat(String)
-
format
Returns aString
representing the value of this instance in a form defined by theformat
parameter. If the value is NaN or +/-Infinity, returns respectively "NaN", "Infinity", or "-Infinity", otherwise formats the value in accordance with the rules used for formattingBigDecimal
values, like in String.format("%9.3f", value).- Parameters:
format
- A pattern to format the value- Returns:
- a
String
representation of this value, formatted in accordance with theformat
parameter
-
toHexString
Returns aString
containing a hexadecimal representation of the instance's value, consisting of sign, two 64-bit words of mantissa, and exponent preceded by letter 'e', with '_' separating the tetrads of hexadecimal digits. This way, the value -1.5 is represented by the string-8000_0000_0000_0000 0000_0000_0000_0000 e7fff_ffff
- Returns:
- a string containing a hexadecimal representation
-
toLongWords
public long[] toLongWords()Returns the fields of the instance that make up it's value as an array oflong
s.
The elements of the array contain the following values:value[0] -- sign flag in bit 63 (1 means negative), biased exponent in bits 31 -- 0 value[1] -- The higher 64 bits of the fractional part of the mantissa value[2] -- The lower 64 bits of the fractional part of the mantissa
- Returns:
- an array of 3
long
s containing the contents of the instance's fields, as described above - See Also:
-
toIeee754Longs
public long[] toIeee754Longs()Returns the 128 bits of an IEEE-754 quadruple precision number nearest to the value ofthis
instance as an array of twolong
s, containing a physical representation of the standard IEEE-754 quadruple-precision floating-point number.
The order of words is big-endian, so that the sign bit, exponent and 48 most significant bits of the mantissa are returned in result[0], and 64 least significant bits of the mantissa in result[1]. The 128-bit significand of this instance is rounded to fit to the 112 bits of the IEEE-754 quadruple. The rounding mode is half-up, i.e. if the exact value of the instance differs from the nearest IEEE-754 quadruple value by 1/2 of LSB of the IEEE-754 quadruple's significand, it gets rounded up. The values whose magnitude exceed the maximum possible value of IEEE-754 Quadruple (namely, 1.18973149535723176508575932662800702 * 10^4932) plus half of its mantissa'a LSB are converted toInfinity
or-Infinity
, depending on the sign, the values with magnitudes less than minimum normal IEEE-754 quadruple value (3.36210314311209350626267781732175260 * 10^-4932
) but greater or equal to6.4751751194380251109244389582276466 * 10^-4966
are converted to subnormal IEEE-754 values, and the values whose magnitude is less than6.4751751194380251109244389582276466 * 10^-4966
(minimum positive value of of IEEE-754 Quadruple) are converted to 0 or -0, depending on the sign ofthis
instance.- Returns:
- an array of two longs containing the 128 bits of the IEEE-745 Quadruple value nearest to the value of this instance.
-
toIeee754Bytes
public byte[] toIeee754Bytes()Returns the 128 bits of an IEEE-754 quadruple precision number nearest to the value ofthis
instance as an array of 16byte
s, containing a physical representation of the standard IEEE-754 quadruple-precision floating-point number.
The order of bytes is big-endian, so that the sign bit and the most significant bits of the exponent is returned in result[0], and the least significant bits of the mantissa in result[15]. The 128-bit significand of this instance is rounded to fit to the 112 bits of the IEEE-754 quadruple. The rounding mode is half-up, i.e. if the exact value of the instance differs from the nearest IEEE-754 quadruple value by 1/2 of LSB of the IEEE-754 quadruple's significand, it gets rounded up. The values whose magnitude exceed the maximum possible value of IEEE-754 Quadruple (namely, 1.18973149535723176508575932662800702 * 10^4932) plus half of its mantissa'a LSB are converted toInfinity
or-Infinity
, depending on the sign, the values with magnitudes less than3.36210314311209350626267781732175260 * 10^-4932
but greater or equal to6.4751751194380251109244389582276466 * 10^-4966
are converted to subnormal IEEE-754 values, and the values whose magnitude is less than6.4751751194380251109244389582276466 * 10^-4966
(minimum positive value of of IEEE-754 Quadruple) are converted to 0 or -0, depending on the sign ofthis
instance.- Returns:
- an array of bytes containing the value of
this
instance as a physical representation of the nearest IEEE-745 Quadruple value, in the big-endian order.
-
compareTo
Compares the value of this instance with the value of the specified instance.- Specified by:
compareTo
in interfaceComparable<Quadruple>
- Parameters:
other
- theQuadruple
to compare with- Returns:
- a negative integer, zero, or a positive integer as the value of this instance is less than, equal to, or greater than the value of the specified instance.
-
compareTo
public int compareTo(long other) Compares the value of this instance with the specifiedlong
value. The value of the argument is converted to Quadruple, and then two Quadruple values are compared bycompareTo(Quadruple)
- Parameters:
other
- thelong
value to compare with- Returns:
- a negative integer, zero, or a positive integer as the value of this instance is less than,
equal to, or greater than the specified
long
value.
-
compareTo
public int compareTo(double other) Compares the value of this instance with the specifieddouble
value. The value of the argument is converted to Quadruple, and then two Quadruple values are compared bycompareTo(Quadruple)
- Parameters:
other
- thedouble
value to compare with- Returns:
- a negative integer, zero, or a positive integer as the value of this instance is less than,
equal to, or greater than the specified
double
value.
-
equals
Indicates whether the otherQuadruple
is equal to this one. -
hashCode
public int hashCode()Computes a hashcode for thisQuadruple
, based on the values of its fields. -
compare
Compares the values of two instances.- Parameters:
q1
- the instance to compare with the other oneq2
- the instance to compare with- Returns:
- a negative integer, zero, or a positive integer as the value of the first instance is less than, equal to, or greater than the value of the second instance.
-
compareMagnitudeTo
Compares the magnitude (absolute value) of this instance with the magnitude of the other instance.- Parameters:
other
- the Quadruple to compare with- Returns:
- 1 if this instance is greater in magnitude than the
other
instance, 0 if the argument is equal in magnitude to this instance, -1 if this instance is less in magnitude, than the argument
-
compareMagnitudes
Compares the magnitudes (absolute values) of the two Quadruples.- Parameters:
q1
- the instance to compare with the other oneq2
- the instance to compare with- Returns:
- a negative integer, zero, or a positive integer as the magnitude of the first instance is less than, equal to, or greater than the magnitude of the second instance.
-
max
Returns a new instance ofQuadruple
with the value of the maximum of the values of the operands.- Parameters:
q1
- first operand to compareq2
- first operand to compare- Returns:
- a new instance of
Quadruple
whose value is equal to the value of the greater of the operands.
-
min
Returns a new instance ofQuadruple
with the value of the minimum of the values of the operands.- Parameters:
q1
- first operand to compareq2
- first operand to compare- Returns:
- a new instance of
Quadruple
whose value is equal to the value of the lesser of the operands.
-
assignMax
Assigns to this instance the maximum of the values ofthis
instance and the operand.- Parameters:
other
- the operand to compare with- Returns:
this
instance, after setting its value to the value of the greater ofthis
and the operand.
-
assignMin
Assigns to this instance the minimum of the values ofthis
instance and the operand.- Parameters:
other
- the operand to compare with- Returns:
this
instance, after setting its value to the value of the lesser ofthis
and the operand.
-
add
Adds the value of the givenQuadruple
summand to the value of this Quadruple. The instance acquires a new value that equals the sum of the previous value and the value of the summand.- Parameters:
summand
- the value to add- Returns:
- the reference to this object, which holds a new value that equals the sum of its previous value and the value of the summand
-
add
Adds the value of the givenlong
summand to the value of this Quadruple. The value of thelong
operand is preliminarily converted to aQuadruple
value. The instance acquires the new value that equals the sum of the previous value and the value of the summand.- Parameters:
summand
- the value to add- Returns:
- the reference to this object, which holds a new value that equals the sum of its previous value and the value of the summand
-
add
Adds the value of the givendouble
summand to the value of this Quadruple. The value of thedouble
operand is preliminarily converted to aQuadruple
value. The instance acquires the new value that equals the sum of the previous value and the value of the summand.- Parameters:
summand
- the value to add- Returns:
- the reference to this object, which holds a new value that equals the sum of its previous value and the value of the summand
-
add
Adds the value of the givenQuadruple op2
to the value ofQuadruple op1
and creates a new instance of Quadruple containing the sum. The operands remain unchanged.- Parameters:
op1
- the first operand to addop2
- the second operand to add- Returns:
- a new instance of Quadruple containing the sum of the operands
-
add
Adds the value of the givenlong op2
to the value ofQuadruple op1
and creates a new instance of Quadruple containing the sum. The value of thelong
operand is preliminarily converted to aQuadruple
value. The Quadruple operand remains unchanged.- Parameters:
op1
- the first operand to addop2
- the second operand to add- Returns:
- a new instance of Quadruple containing the sum of the operands
-
add
Adds the value of the givendouble op2
to the value ofQuadruple op1
and creates a new instance of Quadruple containing the sum. The value of thedouble
operand is preliminarily converted to aQuadruple
value. The Quadruple operand remains unchanged.- Parameters:
op1
- the first operand to addop2
- the second operand to add- Returns:
- a new instance of Quadruple containing the sum of the operands
-
subtract
Subtracts the value of the givenQuadruple
subtrahend from the value of this Quadruple. The instance acquires a new value that equals the difference between the previous value and the value of the subtrahend.- Parameters:
subtrahend
- the value to be subtracted from the current value of this Quadruple- Returns:
- the reference to this object, which holds a new value that equals the difference between its previous value and the value of the subtrahend
-
subtract
Subtracts the value of the givenlong
subtrahend from the value of this Quadruple. The value of thelong
subtrahend is preliminarily converted to aQuadruple
value. The instance acquires a new value that equals the difference between the previous value and the value of the subtrahend.- Parameters:
subtrahend
- the value to be subtracted from the current value of this Quadruple- Returns:
- the reference to this object, which holds a new value that equals the difference between its previous value and the value of the subtrahend
-
subtract
Subtracts the value of the givendouble
subtrahend from the value of this Quadruple. The value of thedouble
subtrahend is preliminarily converted to aQuadruple
value. The instance acquires a new value that equals the difference between the previous value and the value of the subtrahend.- Parameters:
subtrahend
- the value to be subtracted from the current value of this Quadruple- Returns:
- the reference to this object, which holds a new value that equals the difference between its previous value and the value of the subtrahend
-
subtract
Subtracts the value of theQuadruple
subtrahend
from the value of theminuend
, creates and returns a new instance of Quadruple that contains the difference. The operands remain unchanged.- Parameters:
minuend
- the value from which the subtrahend is to be subtractedsubtrahend
- the value to be subtracted from the minuend- Returns:
- a new instance of Quadruple containing the difference
-
subtract
Subtracts the value of thelong
subtrahend
from the value of theminuend
, creates and returns a new instance of Quadruple that contains the difference. The value of thelong
subtrahend is preliminarily converted to aQuadruple
value. The Quadruple minuend remains unchanged.- Parameters:
minuend
- the value from which the subtrahend is to be subtractedsubtrahend
- the value to be subtracted from the minuend- Returns:
- a new instance of Quadruple containing the difference
-
subtract
Subtracts the value of thedouble
subtrahend
from the value of theminuend
, creates and returns a new instance of Quadruple that contains the difference. The value of thedouble
subtrahend is preliminarily converted to aQuadruple
value. The Quadruple minuend remains unchanged.- Parameters:
minuend
- the value from which the subtrahend is to be subtractedsubtrahend
- the value to be subtracted from the minuend- Returns:
- a new instance of Quadruple containing the difference
-
multiply
Multiplies the value of this Quadruple by the value of the givenQuadruple
factor. The instance acquires a new value that equals the product of the previous value and the value of the factor.- Parameters:
factor
- the value to multiply the current value of this Quadruple by.- Returns:
- the reference to this object, which holds a new value that equals the product of its previous value and the value of the factor
-
multiply
Multiplies the value of this Quadruple by the value of the givenlong
factor. The value of thelong
factor is preliminarily converted to aQuadruple
value. The instance acquires a new value that equals the product of the previous value and the value of the factor.- Parameters:
factor
- the value to multiply the current value of this Quadruple by.- Returns:
- the reference to this object, which holds a new value that equals the product of its previous value and the value of the factor
-
multiply
Multiplies the value of this Quadruple by the value of the givendouble
factor. The value of thedouble
factor is preliminarily converted to aQuadruple
value. The instance acquires a new value that equals the product of the previous value and the value of the factor.- Parameters:
factor
- the value to multiply the current value of this Quadruple by.- Returns:
- the reference to this object, which holds a new value that equals the product of its previous value and the value of the factor
-
multiply
Multiplies the value of the givenQuadruple factor1
by theQuadruple factor2
, creates and returns a new instance of Quadruple containing the product. The operands remain unchanged.- Parameters:
factor1
- the 1st factor to be multiplied by the second onefactor2
- the 2nd factor to be multiplied by the first one- Returns:
- a new instance of Quadruple containing the value of the product
-
multiply
Multiplies the value of the givenQuadruple factor1
by thelong factor2
, creates and returns a new instance of Quadruple containing the product. The value of thelong
factor is preliminarily converted to aQuadruple
value. The operands remain unchanged.- Parameters:
factor1
- the 1st factor to be multiplied by the second onefactor2
- the 2nd factor to be multiplied by the first one- Returns:
- a new instance of Quadruple containing the value of the product
-
multiply
Multiplies the value of the givenQuadruple factor1
by thedouble factor2
, creates and returns a new instance of Quadruple containing the product. The value of thedouble
factor is preliminarily converted to aQuadruple
value. The operands remain unchanged.- Parameters:
factor1
- the 1st factor to be multiplied by the second onefactor2
- the 2nd factor to be multiplied by the first one- Returns:
- a new instance of Quadruple containing the value of the product
-
divide
Divides the value of this Quadruple by the value of the givenQuadruple
divisor. The instance acquires a new value that equals the quotient.- Parameters:
divisor
- the divisor to divide the current value of this Quadruple by- Returns:
- the reference to this object, which holds a new value that equals the quotient of the previous value of this Quadruple divided by the given divisor
-
divide
Divides the value of this Quadruple by the value of the givenlong
divisor. The instance acquires a new value that equals the quotient. The value of thelong
divisor is preliminarily converted to aQuadruple
value.- Parameters:
divisor
- the divisor to divide the current value of this Quadruple by- Returns:
- the reference to this object, which holds a new value that equals the quotient of the previous value of this Quadruple divided by the given divisor
-
divide
Divides the value of this Quadruple by the value of the givendouble
divisor. The instance acquires a new value that equals the quotient. The value of thedouble
divisor is preliminarily converted to aQuadruple
value.- Parameters:
divisor
- the divisor to divide the current value of this Quadruple by- Returns:
- the reference to this object, which holds a new value that equals the quotient of the previous value of this Quadruple divided by the given divisor
-
divide
Divides the value of the given dividend by the value of the givenQuadruple
divisor, creates and returns a new instance of Quadruple containing the quotient. The operands remain unchanged.- Parameters:
dividend
- the value to be divided by the divisordivisor
- the divisor to divide the dividend by- Returns:
- a new instance of Quadruple, which holds the value of the quotient
-
divide
Divides the value of the given dividend by the value of the givenlong
divisor, creates and returns a new instance of Quadruple containing the quotient. The value of thelong
divisor is preliminarily converted to aQuadruple
value. The operands remain unchanged.- Parameters:
dividend
- the value to be divided by the divisordivisor
- the divisor to divide the dividend by- Returns:
- a new instance of Quadruple, which holds the value of the quotient
-
divide
Divides the value of the given dividend by the value of the givendouble
divisor, creates and returns a new instance of Quadruple containing the quotient. The value of thedouble
divisor is preliminarily converted to aQuadruple
value. The operands remain unchanged.- Parameters:
dividend
- the value to be divided by the divisordivisor
- the divisor to divide the dividend by- Returns:
- a new instance of Quadruple, which holds the value of the quotient
-
sqrt
Computes a square root of the value of thisQuadruple
and replaces the old value of this instance with the newly-computed value.- Returns:
- the reference to this instance, which holds a new value that equals to the square root of its previous value
-
sqrt
Computes a square root of the value of the givenQuadruple
, creates and returns a new instance of Quadruple containing the value of the square root. The parameter remains unchanged.- Parameters:
square
- the value to find the square root of- Returns:
- a new instance of Quadruple containing the value of the square root of the given argument
-
negate
Changes the sign of this Quadruple.- Returns:
- the reference to this object, which holds a new value that equals the previous value in magnitude, but with opposite sign
-
abs
Returns a new instance ofQuadruple
with the value of the absolute value of this instance- Returns:
- a new instance of
Quadruple
with the value of the absolute value of this instance
-
signum
public int signum()Returns 1 for positive values, -1 for negative values (including -0), and 0 for the positive zero value- Returns:
- 1 for positive values, -1 for negative values (including -0), and 0 for the positive zero value
-
nextRandom
Creates a new Quadruple instance with a pseudo-random value using a static randomly initializedjava.util.Random
instance. The generated value falls within the range 0.0 (inclusive) to 1.0 (exclusive).- Returns:
- a new instance containing a next random value
-
nextRandom
Creates a new Quadruple instance with a pseudo-random value using the givenjava.util.Random
instance. The generated value falls within the range 0.0 (inclusive) to 1.0 (exclusive). Can be used to repeatedly generate the same pseudo-random sequence.- Parameters:
rand
- an instance ofjava.util.Random
to be used for generating the random value- Returns:
- a new instance containing the next random value
-