public class Quadruple extends Number implements 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 |
MAX_VALUE: 2^2147483647 * (2 - 2^-128) =
= 1.76161305168396335320749314979184028566452310e+646456993
MIN_NORMAL: 2^-2147483646 =
= 2.27064621040149253752656726517958758124747730e-646456993
MIN_VALUE: 2^-2147483774 =
= 6.67282948260747430814835377499134611597699952e-646457032
Modifier and Type | Field and Description |
---|---|
static int |
EXP_INF
Deprecated.
|
static long |
EXP_MAX
Deprecated.
|
static int |
EXP_MIN
Deprecated.
|
static int |
EXP_OF_ONE
Deprecated.
|
static int |
EXP_SUB
Deprecated.
|
static int |
EXPONENT_BIAS
The value of the exponent (biased) corresponding to
1.0 == 2^0 ;
equals to 2_147_483_647 (0x7FFF_FFFF )
The same as EXPONENT_OF_ONE |
static int |
EXPONENT_OF_INFINITY
The value of the exponent (biased), corresponding to
Infinity ,
_Infinty , and NaN ;
equals to -1 (0xFFFF_FFFF ) |
static long |
EXPONENT_OF_MAX_VALUE
The value of the exponent (biased), corresponding to
MAX_VALUE ;
equals to 4_294_967_294L (0xFFFF_FFFEL ) |
static int |
EXPONENT_OF_MIN_NORMAL
The value of the exponent (biased) corresponding to
MIN_NORMAL ; equals to 1 |
static int |
EXPONENT_OF_ONE
The value of the exponent (biased) corresponding to
1.0 == 2^0 ;
equals to 2_147_483_647 (0x7FFF_FFFF ). |
static int |
EXPONENT_OF_SUBNORMAL
The value of the exponent (biased) corresponding to subnormal values; equals to 0
|
Constructor and Description |
---|
Quadruple()
Creates a new instance of
Quadruple with value 0.0 |
Quadruple(BigDecimal bdValue)
Creates a new
Quadruple with the value of the given BigDecimal instance. |
Quadruple(boolean negative,
int exponent,
long mantHi,
long mantLo)
Creates a new
Quadruple built from the given parts. |
Quadruple(double dValue)
Creates a new
Quadruple instance with the given double value. |
Quadruple(int exponent,
long mantHi,
long mantLo)
Creates a new
Quadruple with a positive value built from the given parts. |
Quadruple(long lValue)
Creates a new
Quadruple with the given long value. |
Quadruple(Quadruple qValue)
Creates a new
Quadruple instance with the value of the given Quadruple instance. |
Quadruple(String strValue)
Creates a new
Quadruple with the value represented by the given String . |
Modifier and Type | Method and Description |
---|---|
Quadruple |
abs()
Returns a new instance of
Quadruple with the value of the absolute value of this instance |
Quadruple |
add(double summand)
Adds the value of the given
double summand to the value of this Quadruple. |
Quadruple |
add(long summand)
Adds the value of the given
long summand to the value of this Quadruple. |
Quadruple |
add(Quadruple summand)
Adds the value of the given
Quadruple summand to the value of this Quadruple. |
static Quadruple |
add(Quadruple op1,
double op2)
Adds the value of the given
double op2 to the value of Quadruple op1
and creates a new instance of Quadruple containing the sum. |
static Quadruple |
add(Quadruple op1,
long op2)
Adds the value of the given
long op2 to the value of Quadruple op1
and creates a new instance of Quadruple containing the sum. |
static Quadruple |
add(Quadruple op1,
Quadruple op2)
Adds the value of the given
Quadruple op2 to the value of Quadruple op1
and creates a new instance of Quadruple containing the sum. |
Quadruple |
assign(BigDecimal value)
Converts the given value to
Quadruple , and assigns it to the instance. |
Quadruple |
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.
|
Quadruple |
assign(double value)
Converts the given value to quadruple and assigns it to the instance.
|
Quadruple |
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.
|
Quadruple |
assign(long value)
Converts the given value to quadruple and assigns it to the instance.
|
Quadruple |
assign(long[] value)
Builds a Quadruple from the low-level parts given as an array of
long . |
Quadruple |
assign(Quadruple qValue)
Assigns the given value to the instance (copies the values of the private fields of the parameter
to the respective fields of this instance).
|
Quadruple |
assign(String source)
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.
|
Quadruple |
assignIeee754(byte[] value)
Assigns the value of a IEEE-754 quadruple value passed in as an array
of 16
byte s containing the 128 bits of the IEEE-754 quadruple to the given instance. |
Quadruple |
assignIeee754(long[] value)
Assigns the value of a IEEE-754 quadruple value passed in as an array
of two
long s containing the 128 bits of the IEEE-754 quadruple to the given instance. |
Quadruple |
assignMax(Quadruple other)
Assigns to this instance the maximum of the
values of
this instance and the operand. |
Quadruple |
assignMin(Quadruple other)
Assigns to this instance the minimum of the
values of
this instance and the operand. |
Quadruple |
assignNaN()
Assigns the value of "Not a Number" (
NaN ) to this instance. |
Quadruple |
assignNegativeInfinity()
Assigns the value of
-Infinity to this instance. |
Quadruple |
assignPositiveInfinity()
Assigns the value of
+Infinity to this instance. |
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.
|
Quadruple |
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.
|
BigDecimal |
bigDecimalValue()
Builds and returns a
BigDecimal instance holding the same value as the given Quadruple
(rounded to 100 significant decimal digits). |
static int |
compare(Quadruple q1,
Quadruple q2)
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 specified
double value. |
int |
compareTo(long other)
Compares the value of this instance with the specified
long value. |
int |
compareTo(Quadruple other)
Compares the value of this instance with the value of the specified instance.
|
Quadruple |
divide(double divisor)
Divides the value of this Quadruple by the value of the given
double divisor. |
Quadruple |
divide(long divisor)
Divides the value of this Quadruple by the value of the given
long divisor. |
Quadruple |
divide(Quadruple divisor)
Divides the value of this Quadruple by the value of the given
Quadruple divisor. |
static Quadruple |
divide(Quadruple dividend,
double divisor)
Divides the value of the given dividend by the value of the given
double divisor,
creates and returns a new instance of Quadruple containing the quotient. |
static Quadruple |
divide(Quadruple dividend,
long divisor)
Divides the value of the given dividend by the value of the given
long divisor,
creates and returns a new instance of Quadruple containing the quotient. |
static Quadruple |
divide(Quadruple dividend,
Quadruple divisor)
Divides the value of the given dividend by the value of the given
Quadruple divisor,
creates and returns a new instance of Quadruple containing the quotient. |
double |
doubleValue()
Converts the value of this
Quadruple to a double value in a way
similar to standard narrowing conversions (e.g., from double to float ). |
boolean |
equals(Object obj)
Indicates whether the other
Quadruple 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 |
floatValue()
Converts the value of this
Quadruple to a float value in a way
similar to standard narrowing conversions (e.g., from double to float ). |
String |
format(String format)
Returns a
String representing the value
of this instance in a form defined by the format parameter. |
int |
hashCode()
Computes a hashcode for this
Quadruple ,
based on the values of its fields. |
int |
intValue()
Converts the value of this
Quadruple to an int value in a way
similar to standard narrowing conversions (e.g., from double to int ). |
boolean |
isInfinite()
Checks if the value is infinite (i.e
NEGATIVE_INFINITY or POSITIVE_INFINITY ). |
boolean |
isNaN()
Checks if the value is not a number (i.e. has the value of
NaN ). |
boolean |
isNegative()
Checks if the value is negative.
|
boolean |
isZero()
Checks if the value is zero, either positive or negative.
|
long |
longValue()
Converts the value of this
Quadruple to a long value in a way
similar to standard narrowing conversions (e.g., from double to long ). |
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 mantissa
|
static Quadruple |
max(Quadruple q1,
Quadruple q2)
Returns a new instance of
Quadruple with the value of the
maximum of the values of the operands. |
static Quadruple |
maxValue()
Returns a new
Quadruple instance with the value of MAX_VALUE ( 2^2147483647 * (2 - 2^-128) = 1.76161305168396335320749314979184028566452310e+646456993) |
static Quadruple |
min(Quadruple q1,
Quadruple q2)
Returns a new instance of
Quadruple with the value of the
minimum of the values of the operands. |
static Quadruple |
minNormal()
Returns a new
Quadruple instance with the value of MIN_NORMAL ( 2^-2147483646 = 2.27064621040149253752656726517958758124747730e-646456993) |
static Quadruple |
minValue()
Returns a new
Quadruple instance with the value of MIN_VALUE ( 2^-2147483774 = 6.67282948260747430814835377499134611597699952e-646457032) |
Quadruple |
multiply(double factor)
Multiplies the value of this Quadruple by the value of the given
double factor. |
Quadruple |
multiply(long factor)
Multiplies the value of this Quadruple by the value of the given
long factor. |
Quadruple |
multiply(Quadruple factor)
Multiplies the value of this Quadruple by the value of the given
Quadruple factor. |
static Quadruple |
multiply(Quadruple factor1,
double factor2)
Multiplies the value of the given
Quadruple factor1 by the double factor2 ,
creates and returns a new instance of Quadruple containing the product. |
static Quadruple |
multiply(Quadruple factor1,
long factor2)
Multiplies the value of the given
Quadruple factor1 by the long factor2 ,
creates and returns a new instance of Quadruple containing the product. |
static Quadruple |
multiply(Quadruple factor1,
Quadruple factor2)
Multiplies the value of the given
Quadruple factor1 by the Quadruple factor2 ,
creates and returns a new instance of Quadruple containing the product. |
static Quadruple |
nan()
Returns a new
Quadruple instance with the value of NaN . |
Quadruple |
negate()
Changes the sign of this Quadruple.
|
static Quadruple |
negativeInfinity()
Returns a new
Quadruple instance with the value of -Infinity . |
static Quadruple |
nextRandom()
Creates a new Quadruple instance with a pseudo-random value
using a static randomly initialized
java.util.Random instance. |
static Quadruple |
nextRandom(Random rand)
Creates a new Quadruple instance with a pseudo-random value
using the given
java.util.Random instance. |
static Quadruple |
one()
Returns a new
Quadruple instance with the value of 1.0. |
static Quadruple |
pi()
Returns a new
Quadruple instance with the value of the number π (pi)
(3.141592653589793238462643383279502884195) |
static Quadruple |
positiveInfinity()
Returns a new
Quadruple 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 value
|
Quadruple |
sqrt()
Computes a square root of the value of this
Quadruple
and replaces the old value of this instance with the newly-computed value. |
static Quadruple |
sqrt(Quadruple square)
Computes a square root of the value of the given
Quadruple ,
creates and returns a new instance of Quadruple containing the value of the square root. |
Quadruple |
subtract(double subtrahend)
Subtracts the value of the given
double subtrahend from the value of this Quadruple. |
Quadruple |
subtract(long subtrahend)
Subtracts the value of the given
long subtrahend from the value of this Quadruple. |
Quadruple |
subtract(Quadruple subtrahend)
Subtracts the value of the given
Quadruple subtrahend from the value of this Quadruple. |
static Quadruple |
subtract(Quadruple minuend,
double subtrahend)
Subtracts the value of the
double subtrahend from the value of the minuend ,
creates and returns a new instance of Quadruple that contains the difference. |
static Quadruple |
subtract(Quadruple minuend,
long subtrahend)
Subtracts the value of the
long subtrahend from the value of the minuend ,
creates and returns a new instance of Quadruple that contains the difference. |
static Quadruple |
subtract(Quadruple minuend,
Quadruple subtrahend)
Subtracts the value of the
Quadruple subtrahend from the value of the minuend ,
creates and returns a new instance of Quadruple that contains the difference. |
static Quadruple |
ten()
Returns a new
Quadruple instance with the value of 10.0. |
String |
toHexString()
Returns a
String 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[] |
toIeee754Bytes()
Returns the 128 bits of an IEEE-754 quadruple precision number nearest to the value
of
this instance as an array of 16 byte s, containing a physical representation
of the standard IEEE-754 quadruple-precision floating-point number. |
long[] |
toIeee754Longs()
Returns the 128 bits of an IEEE-754 quadruple precision number nearest to the value
of
this instance as an array of two long s, containing a physical representation
of the standard IEEE-754 quadruple-precision floating-point number. |
long[] |
toLongWords()
Returns the fields of the instance that make up it's value as
an array of
long s. |
String |
toString()
Returns a decimal string representation of the value of this
Quadruple
in a scientific (exponential) notation, rounded to 43 digits after point. |
static Quadruple |
two()
Returns a new
Quadruple instance with the value of 2.0. |
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. |
byteValue, shortValue
@Deprecated public static final int EXP_SUB
EXPONENT_OF_SUBNORMAL
insteadpublic static final int EXPONENT_OF_SUBNORMAL
@Deprecated public static final int EXP_MIN
MIN_NORMAL
; equals to 1
Deprecated, will be removed in release version. Use EXPONENT_OF_MIN_NORMAL
insteadpublic static final int EXPONENT_OF_MIN_NORMAL
MIN_NORMAL
; equals to 1@Deprecated public static final int EXP_OF_ONE
1.0 == 2^0
;
equals to 2_147_483_647 (0x7FFF_FFFF
)
Deprecated, will be removed in release version. Use EXPONENT_OF_ONE
insteadpublic static final int EXPONENT_OF_ONE
1.0 == 2^0
;
equals to 2_147_483_647 (0x7FFF_FFFF
).
The same as EXPONENT_BIAS
public static final int EXPONENT_BIAS
1.0 == 2^0
;
equals to 2_147_483_647 (0x7FFF_FFFF
)
The same as EXPONENT_OF_ONE
@Deprecated public static final long EXP_MAX
MAX_VALUE
;
equals to 4_294_967_294L (0xFFFF_FFFEL
)
Deprecated, will be removed in release version. Use EXPONENT_OF_MAX_VALUE
insteadpublic static final long EXPONENT_OF_MAX_VALUE
MAX_VALUE
;
equals to 4_294_967_294L (0xFFFF_FFFEL
)@Deprecated public static final int EXP_INF
Infinity
,
_Infinty
, and NaN
;
equals to -1 (0xFFFF_FFFF
)
Deprecated, will be removed in release version. Use EXPONENT_OF_INFINITY
insteadpublic static final int EXPONENT_OF_INFINITY
Infinity
,
_Infinty
, and NaN
;
equals to -1 (0xFFFF_FFFF
)public Quadruple()
Quadruple
with value 0.0public Quadruple(Quadruple qValue)
Quadruple
instance with the value of the given Quadruple
instance.qValue
- the Quadruple
value to be assigned to the new instance.public Quadruple(double dValue)
Quadruple
instance with the given double
value.assign(double)
.dValue
- the double
value to be assignedpublic Quadruple(long lValue)
Quadruple
with the given long
value.assign(long)
.lValue
- the long
value to be assignedpublic Quadruple(String strValue)
Quadruple
with the value represented by the given String
.assign(String)
strValue
- the String
value to be assignedassign(String)
public Quadruple(BigDecimal bdValue)
Quadruple
with the value of the given BigDecimal
instance.bdValue
- the BigDecimal
value to be assignedpublic Quadruple(boolean negative, int exponent, long mantHi, long mantLo)
Quadruple
built from the given parts.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 mantissapublic Quadruple(int exponent, long mantHi, long mantLo)
Quadruple
with a positive value built from the given parts.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 mantissapublic static Quadruple negativeInfinity()
Quadruple
instance with the value of -Infinity
.Quadruple
instance with the value of NEGATIVE_INFINITYpublic static Quadruple positiveInfinity()
Quadruple
instance with the value of +Infinity
.Quadruple
instance with the value of POSITIVE_INFINITYpublic static Quadruple nan()
Quadruple
instance with the value of NaN
.Quadruple
instance with the value of NANpublic static Quadruple one()
Quadruple
instance with the value of 1.0.Quadruple
instance with the value of 1.0public static Quadruple two()
Quadruple
instance with the value of 2.0.Quadruple
instance with the value of 2.0public static Quadruple ten()
Quadruple
instance with the value of 10.0.Quadruple
instance with the value of 10.0public static Quadruple minValue()
Quadruple
instance with the value of MIN_VALUE
2^-2147483774
= 6.67282948260747430814835377499134611597699952e-646457032)Quadruple
instance with the value of MIN_VALUEpublic static Quadruple maxValue()
Quadruple
instance with the value of MAX_VALUE
2^2147483647 * (2 - 2^-128)
= 1.76161305168396335320749314979184028566452310e+646456993)Quadruple
instance with the value of MAX_VALUE
public static Quadruple minNormal()
Quadruple
instance with the value of MIN_NORMAL
2^-2147483646
= 2.27064621040149253752656726517958758124747730e-646456993)Quadruple
instance with the value of MIN_NORMAL
public static Quadruple pi()
Quadruple
instance with the value of the number π
(pi)
(3.141592653589793238462643383279502884195)Quadruple
instance with the value of the number π
(pi)public int exponent()
[1.0 .. 2.0)
, 0x8000_0000 for [2.0 .. 4.0)
etc.public int unbiasedExponent()
[1.0 .. 2.0)
, 1 for [2.0 .. 4.0)
etc.public long mantHi()
public long mantLo()
public boolean isNegative()
true
, if the value is negative, false
otherwisepublic boolean isInfinite()
NEGATIVE_INFINITY
or POSITIVE_INFINITY
).true
, if the value is infinity (either positive or negative), false
otherwisepublic boolean isNaN()
NaN
).true
, if the value is not a number (NaN), false
otherwisepublic boolean isZero()
true
, if the value is 0 or -0, otherwise returnspublic Quadruple assign(Quadruple qValue)
qValue
- a Quadruple
instance whose value is to assignpublic Quadruple assign(double value)
(Double.MIN_NORMAL < v <= Double.MIN_VALUE)
are converted
to normal quadruple values, by shifting them leftwards and correcting the exponent accordingly.value
- the double
value to be assigned.public Quadruple assign(long value)
value
- the long
value to be assignedpublic Quadruple assign(String source) throws NullPointerException, NumberFormatException
Quadruple
value by less than
0.5 - 1e-17
of the least significant bit of the mantissa of the latter, it gets rounded
down to the aforementioned Quadruple
value.Quadruple
value is between
(0.5 - 1e-17) * LSB
and 0.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 than
2^128
, e
is the exponent of the Quadruple
.1.5 + 0.5 * 2^-128
, that equals1.500000000000000000000000000000000000001469367938527859384960921...
1.5000000000000000000000000000000000000029387
, whose mantissa is 0x8000_..._0001
,1.5 + (0.5 - 1e-17) * 2^-128
, that equals to1.500000000000000000000000000000000000001469367938527859355573561...
0x8000_..._0000
.source
- the String to be parsedNullPointerException
- if the input string is null
NumberFormatException
- if the input string does not contain valid valuepublic Quadruple assign(BigDecimal value)
Quadruple
, and assigns it to the instance.Quadruple
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 corresponding Quadruples
by a value that lies between
(0.5 - 1e-40) * LSB
and 0.5 * LSB
may get rounded either up or down.value
- the value to be assigned.NullPointerException
- if the parameter is null
public Quadruple assign(boolean negative, int exponent, long mantHi, long mantLo)
exponent
parameter as the biased exponent value,
so that its value equal to EXPONENT_OF_ONE
(0xFFFF_FFFEL
)
corresponds to the Quadruple
value of 1.0.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 mantissaQuadruple
containing the value built of the given partspublic Quadruple assignWithUnbiasedExponent(boolean negative, int exponent, long mantHi, long mantLo)
exponent
parameter as the unbiased exponent value,
whose 0
value corresponds to the Quadruple
value of 1.0.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 mantissapublic Quadruple assign(int exponent, long mantHi, long mantLo)
exponent
parameter as the biased exponent value,
so that its value equal to EXPONENT_OF_ONE
(0xFFFF_FFFEL
)
corresponds to the Quadruple
value of 1.0.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 mantissapublic Quadruple assignWithUnbiasedExponent(int exponent, long mantHi, long mantLo)
exponent
parameter as the unbiased exponent value,
whose 0
value corresponds to the Quadruple
value of 1.0.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 mantissapublic Quadruple assign(long[] value)
long
.
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
value
- array of long
containing the low-level parts of the Quadruple valuetoLongWords()
public Quadruple assignIeee754(long[] value) throws IllegalArgumentException
long
s containing the 128 bits of the IEEE-754 quadruple to the given instance.value[0]
should contain the sign bit, the exponent, and the most significant 48 bits of the significand.value
- an array of two longs, containing the 128 bits of the IEEE-754 quadruple value to be assignedIllegalArgumentException
- if the length of the input array is not 2public Quadruple assignIeee754(byte[] value)
byte
s containing the 128 bits of the IEEE-754 quadruple to the given instance.value[0]
should contain the sign bit, and the high-order 7 bits of the IEEE-754 quadruple's exponent,
and the value[15]
is expected to contain the least significant 8 bits of the significand.value
- an array of 16 bytes, containing the 128 bits of the IEEE-754 quadruple value to be assignedIllegalArgumentException
- if the length of the input array is not 16public Quadruple assignPositiveInfinity()
+Infinity
to this instance.POSITIVE_INFINITY
public Quadruple assignNegativeInfinity()
-Infinity
to this instance.NEGATIVE_INFINITY
public Quadruple assignNaN()
NaN
) to this instance.NaN
public int intValue()
Quadruple
to an int
value in a way
similar to standard narrowing conversions (e.g., from double
to int
).public long longValue()
Quadruple
to a long
value in a way
similar to standard narrowing conversions (e.g., from double
to long
).public float floatValue()
Quadruple
to a float
value in a way
similar to standard narrowing conversions (e.g., from double
to float
).floatValue
in class Number
Quadruple
instance converted to a float
.public double doubleValue()
Quadruple
to a double
value in a way
similar to standard narrowing conversions (e.g., from double
to float
).
Uses 'half-even' approach to the rounding, like BigDecimal.doubleValue()
doubleValue
in class Number
Quadruple
instance converted to a double
.public BigDecimal bigDecimalValue() throws NumberFormatException
BigDecimal
instance holding the same value as the given Quadruple
(rounded to 100 significant decimal digits).BigDecimal
holding the same value as the given Quadruple
NumberFormatException
- if the value of the instance is not convertible to BigDecimal
(i.e. it is Infinity
, -Infinity
, or NaN
)public String toString()
Quadruple
in a scientific (exponential) notation, rounded to 43 digits after point.format(String)
toString
in class Object
format(String)
,
Object.toString()
public String format(String format)
String
representing the value
of this instance in a form defined by the format
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 formatting BigDecimal
values, like in String.format("%9.3f", value).format
- A pattern to format the valueString
representation of this value, formatted in accordance with the
format
parameterpublic String toHexString()
String
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
public long[] toLongWords()
long
s.
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
long
s containing the contents of the
instance's fields, as described aboveassign(long[])
public long[] toIeee754Longs()
this
instance as an array of two long
s, containing a physical representation
of the standard IEEE-754 quadruple-precision floating-point number.Infinity
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 to 6.4751751194380251109244389582276466 * 10^-4966
are converted to subnormal IEEE-754 values, and the values whose magnitude is less
than 6.4751751194380251109244389582276466 * 10^-4966
(minimum positive value of of IEEE-754 Quadruple)
are converted to 0 or -0, depending on the sign of this
instance.public byte[] toIeee754Bytes()
this
instance as an array of 16 byte
s, containing a physical representation
of the standard IEEE-754 quadruple-precision floating-point number.Infinity
or -Infinity
, depending on the sign,
the values with magnitudes less than 3.36210314311209350626267781732175260 * 10^-4932
but greater or equal to 6.4751751194380251109244389582276466 * 10^-4966
are converted to subnormal IEEE-754 values,
and the values whose magnitude is less than 6.4751751194380251109244389582276466 * 10^-4966
(minimum positive value of of IEEE-754 Quadruple)
are converted to 0 or -0, depending on the sign of this
instance.this
instance
as a physical representation of the nearest IEEE-745 Quadruple value,
in the big-endian order.public int compareTo(Quadruple other)
compareTo
in interface Comparable<Quadruple>
other
- the Quadruple
to compare withpublic int compareTo(long other)
long
value.
The value of the argument is converted to Quadruple, and then two Quadruple values
are compared by compareTo(Quadruple)
other
- the long
value to compare withlong
value.public int compareTo(double other)
double
value.
The value of the argument is converted to Quadruple,
and then two Quadruple values are compared by compareTo(Quadruple)
other
- the double
value to compare withdouble
value.public boolean equals(Object obj)
Quadruple
is equal to this one.public int hashCode()
Quadruple
,
based on the values of its fields.hashCode
in class Object
Object.hashCode()
public static int compare(Quadruple q1, Quadruple q2)
q1
- the instance to compare with the other oneq2
- the instance to compare withpublic int compareMagnitudeTo(Quadruple other)
other
- the Quadruple to compare withother
instance,
0 if the argument is equal in magnitude to this instance, -1 if this instance is less in magnitude, than the argumentpublic static int compareMagnitudes(Quadruple q1, Quadruple q2)
q1
- the instance to compare with the other oneq2
- the instance to compare withpublic static Quadruple max(Quadruple q1, Quadruple q2)
Quadruple
with the value of the
maximum of the values of the operands.q1
- first operand to compareq2
- first operand to compareQuadruple
whose value is
equal to the value of the greater of the operands.public static Quadruple min(Quadruple q1, Quadruple q2)
Quadruple
with the value of the
minimum of the values of the operands.q1
- first operand to compareq2
- first operand to compareQuadruple
whose value is
equal to the value of the lesser of the operands.public Quadruple assignMax(Quadruple other)
this
instance and the operand.other
- the operand to compare withthis
instance, after setting its value
to the value of the greater of this
and the operand.public Quadruple assignMin(Quadruple other)
this
instance and the operand.other
- the operand to compare withthis
instance, after setting its value
to the value of the lesser of this
and the operand.public Quadruple add(Quadruple summand)
Quadruple
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.summand
- the value to addpublic Quadruple add(long summand)
long
summand to the value of this Quadruple.
The value of the long
operand is preliminarily converted to a Quadruple
value.
The instance acquires the new value that equals the sum of the previous value and the value of the summand.summand
- the value to addpublic Quadruple add(double summand)
double
summand to the value of this Quadruple.
The value of the double
operand is preliminarily converted to a Quadruple
value.
The instance acquires the new value that equals the sum of the previous value and the value of the summand.summand
- the value to addpublic static Quadruple add(Quadruple op1, Quadruple op2)
Quadruple op2
to the value of Quadruple op1
and creates a new instance of Quadruple containing the sum.
The operands remain unchanged.op1
- the first operand to addop2
- the second operand to addpublic static Quadruple add(Quadruple op1, long op2)
long op2
to the value of Quadruple op1
and creates a new instance of Quadruple containing the sum.
The value of the long
operand is preliminarily converted to a Quadruple
value.
The Quadruple operand remains unchanged.op1
- the first operand to addop2
- the second operand to addpublic static Quadruple add(Quadruple op1, double op2)
double op2
to the value of Quadruple op1
and creates a new instance of Quadruple containing the sum.
The value of the double
operand is preliminarily converted to a Quadruple
value.
The Quadruple operand remains unchanged.op1
- the first operand to addop2
- the second operand to addpublic Quadruple subtract(Quadruple subtrahend)
Quadruple
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.subtrahend
- the value to be subtracted from the current value of this Quadruplepublic Quadruple subtract(long subtrahend)
long
subtrahend from the value of this Quadruple.
The value of the long
subtrahend is preliminarily converted to a Quadruple
value.
The instance acquires a new value that equals the difference between the previous value and the value of the subtrahend.subtrahend
- the value to be subtracted from the current value of this Quadruplepublic Quadruple subtract(double subtrahend)
double
subtrahend from the value of this Quadruple.
The value of the double
subtrahend is preliminarily converted to a Quadruple
value.
The instance acquires a new value that equals the difference between the previous value and the value of the subtrahend.subtrahend
- the value to be subtracted from the current value of this Quadruplepublic static Quadruple subtract(Quadruple minuend, Quadruple subtrahend)
Quadruple
subtrahend
from the value of the minuend
,
creates and returns a new instance of Quadruple that contains the difference.
The operands remain unchanged.minuend
- the value from which the subtrahend is to be subtractedsubtrahend
- the value to be subtracted from the minuendpublic static Quadruple subtract(Quadruple minuend, long subtrahend)
long
subtrahend
from the value of the minuend
,
creates and returns a new instance of Quadruple that contains the difference.
The value of the long
subtrahend is preliminarily converted to a Quadruple
value.
The Quadruple minuend remains unchanged.minuend
- the value from which the subtrahend is to be subtractedsubtrahend
- the value to be subtracted from the minuendpublic static Quadruple subtract(Quadruple minuend, double subtrahend)
double
subtrahend
from the value of the minuend
,
creates and returns a new instance of Quadruple that contains the difference.
The value of the double
subtrahend is preliminarily converted to a Quadruple
value.
The Quadruple minuend remains unchanged.minuend
- the value from which the subtrahend is to be subtractedsubtrahend
- the value to be subtracted from the minuendpublic Quadruple multiply(Quadruple factor)
Quadruple
factor.
The instance acquires a new value that equals the product of the previous value and the value of the factor.factor
- the value to multiply the current value of this Quadruple by.public Quadruple multiply(long factor)
long
factor.
The value of the long
factor is preliminarily converted to a Quadruple
value.
The instance acquires a new value that equals the product of the previous value and the value of the factor.factor
- the value to multiply the current value of this Quadruple by.public Quadruple multiply(double factor)
double
factor.
The value of the double
factor is preliminarily converted to a Quadruple
value.
The instance acquires a new value that equals the product of the previous value and the value of the factor.factor
- the value to multiply the current value of this Quadruple by.public static Quadruple multiply(Quadruple factor1, Quadruple factor2)
Quadruple factor1
by the Quadruple factor2
,
creates and returns a new instance of Quadruple containing the product.
The operands remain unchanged.factor1
- the 1st factor to be multiplied by the second onefactor2
- the 2nd factor to be multiplied by the first onepublic static Quadruple multiply(Quadruple factor1, long factor2)
Quadruple factor1
by the long factor2
,
creates and returns a new instance of Quadruple containing the product.
The value of the long
factor is preliminarily converted to a Quadruple
value.
The operands remain unchanged.factor1
- the 1st factor to be multiplied by the second onefactor2
- the 2nd factor to be multiplied by the first onepublic static Quadruple multiply(Quadruple factor1, double factor2)
Quadruple factor1
by the double factor2
,
creates and returns a new instance of Quadruple containing the product.
The value of the double
factor is preliminarily converted to a Quadruple
value.
The operands remain unchanged.factor1
- the 1st factor to be multiplied by the second onefactor2
- the 2nd factor to be multiplied by the first onepublic Quadruple divide(Quadruple divisor)
Quadruple
divisor.
The instance acquires a new value that equals the quotient.divisor
- the divisor to divide the current value of this Quadruple bypublic Quadruple divide(long divisor)
long
divisor.
The instance acquires a new value that equals the quotient.
The value of the long
divisor is preliminarily converted to a Quadruple
value.divisor
- the divisor to divide the current value of this Quadruple bypublic Quadruple divide(double divisor)
double
divisor.
The instance acquires a new value that equals the quotient.
The value of the double
divisor is preliminarily converted to a Quadruple
value.divisor
- the divisor to divide the current value of this Quadruple bypublic static Quadruple divide(Quadruple dividend, Quadruple divisor)
Quadruple
divisor,
creates and returns a new instance of Quadruple containing the quotient.
The operands remain unchanged.dividend
- the value to be divided by the divisordivisor
- the divisor to divide the dividend bypublic static Quadruple divide(Quadruple dividend, long divisor)
long
divisor,
creates and returns a new instance of Quadruple containing the quotient.
The value of the long
divisor is preliminarily converted to a Quadruple
value.
The operands remain unchanged.dividend
- the value to be divided by the divisordivisor
- the divisor to divide the dividend bypublic static Quadruple divide(Quadruple dividend, double divisor)
double
divisor,
creates and returns a new instance of Quadruple containing the quotient.
The value of the double
divisor is preliminarily converted to a Quadruple
value.
The operands remain unchanged.dividend
- the value to be divided by the divisordivisor
- the divisor to divide the dividend bypublic Quadruple sqrt()
Quadruple
and replaces the old value of this instance with the newly-computed value.public static Quadruple sqrt(Quadruple square)
Quadruple
,
creates and returns a new instance of Quadruple containing the value of the square root.
The parameter remains unchanged.square
- the value to find the square root ofpublic Quadruple negate()
public Quadruple abs()
Quadruple
with the value of the absolute value of this instanceQuadruple
with the value of the absolute value of this instancepublic int signum()
public static Quadruple nextRandom()
java.util.Random
instance.
The generated value falls within the range 0.0 (inclusive) to 1.0 (exclusive).public static Quadruple nextRandom(Random rand)
java.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.rand
- an instance of java.util.Random
to be used for generating the random value