Record Class QuadrupleImmutable
- Record Components:
negative- The sign of the value (truesignifies negative values).exponent- The binary exponent (unbiased).mantHi- The most significant 64 bits of fractional part of the mantissa.mantLo- The least significant 64 bits of fractional part of the mantissa.
- All Implemented Interfaces:
Comparable<QuadrupleImmutable>
Quadruple implemented as a Java record.
A floating-point number with a 128-bit fractional part of the mantissa and 32-bit
exponent. Normal values range from approximately 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 worst the precision.
Implements conversions from/to other numeric types, conversions from/to strings, formatting, arithmetic operations and square root.
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
Original code by M. Vokhmentsev, see this repository.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe value of the exponent (biased) corresponding to1.0 == 2^0; equals to 2_147_483_647 (0x7FFF_FFFF) The same asEXPONENT_OF_ONEstatic final intThe value of the exponent (biased), corresponding toInfinity,-Infinity, andNaN; equals to -1 (0xFFFF_FFFF)static final longThe value of the exponent (biased), corresponding toMAX_VALUE; equals to 4_294_967_294L (0xFFFF_FFFEL)static final intThe value of the exponent (biased) corresponding to1.0 == 2^0; equals to 2_147_483_647 (0x7FFF_FFFF).static final QuadrupleImmutableValue ofNaN.static final QuadrupleImmutableValue of-Infinity.static final QuadrupleImmutableValue of negative zero.static final QuadrupleImmutableValue of one.static final QuadrupleImmutableValue ofPI.static final QuadrupleImmutableValue of+Infinity.static final QuadrupleImmutableValue of zero. -
Constructor Summary
ConstructorsConstructorDescriptionQuadrupleImmutable(boolean negative, int exponent, long mantHi, long mantLo) Creates an instance of aQuadrupleImmutablerecord class.QuadrupleImmutable(int exponent, long mantHi, long mantLo) Creates a newQuadrupleImmutablewith a positive value built from the given parts.Creates a newQuadrupleImmutableinstance with the value of the givenQuadrupleImmutableinstance.
First creates an empty (zero) instance, then copies the fields of the parameter. -
Method Summary
Modifier and TypeMethodDescriptionabs()Returns a new instance ofQuadrupleImmutablewith the value of the absolute value of this instanceadd(double summand) Adds the value of the givendoublesummand to the value of this Float128.add(long summand) Adds the value of the givenlongsummand to the value of this Float128.add(QuadrupleImmutable summand) Adds the value of the givenQuadrupleImmutablesummand to the value of this Float128.intcompareTo(QuadrupleImmutable other) Compares the value of this instance with the value of the specified instance.cpy()Returns a copy of this Float128.divide(double divisor) Divides the value of this Float128 by the value of the givendoubledivisor.divide(long divisor) Divides the value of this Float128 by the value of the givenlongdivisor.divide(QuadrupleImmutable divisor) Divides the value of this Float128 by the value of the givenQuadrupleImmutabledivisor.doubleConverts the value of thisQuadrupleImmutableto adoublevalue in a way similar to standard narrowing conversions (e.g., fromdoubletofloat).final booleanIndicates whether some other object is "equal to" this one.intexponent()Returns the value of theexponentrecord component.floatConverts the value of thisQuadrupleImmutableto afloatvalue in a way similar to standard narrowing conversions (e.g., fromdoubletofloat).static QuadrupleImmutablefrom(double value) Creates a newQuadrupleImmutableinstance with the given double value.static QuadrupleImmutablefrom(long value) Creates a newQuadrupleImmutableinstance with the given long value.static QuadrupleImmutablefromUnbiasedExponent(boolean negative, int exponent, long mantHi, long mantLo) Builds a Float128 value from the given low-level parts.
Treats theexponentparameter as the unbiased exponent value, whose0value corresponds to theQuadrupleImmutablevalue of 1.0.inthashCode()Computes a hashcode for thisQuadrupleImmutable, based on the values of its fields.static QuadrupleImmutableinfinity(boolean negative) intintValue()Converts the value of thisQuadrupleImmutableto anintvalue in a way similar to standard narrowing conversions (e.g., fromdoubletoint).booleanChecks if the value is infinite (i.eNEGATIVE_INFINITYorPOSITIVE_INFINITY).booleanisNaN()Checks if the value is not a number (i.e.booleanChecks if the value is negative.booleanisZero()Checks if the value is zero, either positive or negative.longConverts the value of thisQuadrupleImmutableto alongvalue in a way similar to standard narrowing conversions (e.g., fromdoubletolong).longmantHi()Returns the value of themantHirecord component.longmantLo()Returns the value of themantLorecord component.multiply(double factor) Multiplies the value of this Float128 by the value of the givendoublefactor.multiply(long factor) Multiplies the value of this Float128 by the value of the givenlongfactor.multiply(QuadrupleImmutable factor) Multiplies the value of this Float128 by the value of the givenQuadrupleImmutablefactor.booleannegative()Returns the value of thenegativerecord component.intsignum()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 thisQuadrupleImmutableand replaces the old value of this instance with the newly-computed value.static QuadrupleImmutablesqrt(QuadrupleImmutable square) Computes a square root of the value of the givenQuadrupleImmutable, creates and returns a new instance of Float128 containing the value of the square root.subtract(double subtrahend) Subtracts the value of the givendoublesubtrahend from the value of this Float128.subtract(long subtrahend) Subtracts the value of the givenlongsubtrahend from the value of this Float128.subtract(QuadrupleImmutable subtrahend) Subtracts the value of the givenQuadrupleImmutablesubtrahend from the value of this Float128.toString()Returns a string representation of this record class.static QuadrupleImmutablezero(boolean negative)
-
Field Details
-
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:
-
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:
-
EXPONENT_OF_INFINITY
public static final int EXPONENT_OF_INFINITYThe value of the exponent (biased), corresponding toInfinity,-Infinity, andNaN; equals to -1 (0xFFFF_FFFF)- See Also:
-
ONE
Value of one. -
ZERO
Value of zero. -
NEGATIVE_ZERO
Value of negative zero. -
POSITIVE_INFINITY
Value of+Infinity. -
NEGATIVE_INFINITY
Value of-Infinity. -
NAN
Value ofNaN. -
PI
Value ofPI.
-
-
Constructor Details
-
QuadrupleImmutable
public QuadrupleImmutable(int exponent, long mantHi, long mantLo) Creates a newQuadrupleImmutablewith 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 mantissa.mantLo- The least significant 64 bits of fractional part of the mantissa.
-
QuadrupleImmutable
Creates a newQuadrupleImmutableinstance with the value of the givenQuadrupleImmutableinstance.
First creates an empty (zero) instance, then copies the fields of the parameter. to the fields of the new instance- Parameters:
value- theQuadrupleImmutablevalue to be assigned to the new instance.
-
QuadrupleImmutable
public QuadrupleImmutable(boolean negative, int exponent, long mantHi, long mantLo) Creates an instance of aQuadrupleImmutablerecord class.
-
-
Method Details
-
infinity
-
zero
-
from
Creates a newQuadrupleImmutableinstance with the given double value.- Parameters:
value- the double value to be assigned.
-
from
Creates a newQuadrupleImmutableinstance with the given long value.- Parameters:
value- the long value to be assigned.
-
fromUnbiasedExponent
public static QuadrupleImmutable fromUnbiasedExponent(boolean negative, int exponent, long mantHi, long mantLo) Builds a Float128 value from the given low-level parts.
Treats theexponentparameter as the unbiased exponent value, whose0value corresponds to theQuadrupleImmutablevalue of 1.0.- Parameters:
negative- the sign of the value (truefor 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 Float128 containing the value built of the given parts
-
intValue
public int intValue()Converts the value of thisQuadrupleImmutableto anintvalue in a way similar to standard narrowing conversions (e.g., fromdoubletoint).- Returns:
- the value of this
QuadrupleImmutableinstance converted to anint.
-
longValue
public long longValue()Converts the value of thisQuadrupleImmutableto alongvalue in a way similar to standard narrowing conversions (e.g., fromdoubletolong).- Returns:
- the value of this
QuadrupleImmutableinstance converted to along.
-
floatValue
public float floatValue()Converts the value of thisQuadrupleImmutableto afloatvalue in a way similar to standard narrowing conversions (e.g., fromdoubletofloat).- Returns:
- the value of this
QuadrupleImmutableinstance converted to afloat.
-
doubleValue
public double doubleValue()Converts the value of thisQuadrupleImmutableto adoublevalue in a way similar to standard narrowing conversions (e.g., fromdoubletofloat). Uses 'half-even' approach to the rounding, likeBigDecimal.doubleValue()- Returns:
- the value of this
QuadrupleImmutableinstance converted to adouble.
-
add
Adds the value of the givenQuadrupleImmutablesummand to the value of this Float128. 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 givenlongsummand to the value of this Float128. The value of thelongoperand is preliminarily converted to aQuadrupleImmutablevalue. 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 givendoublesummand to the value of this Float128. The value of thedoubleoperand is preliminarily converted to aQuadrupleImmutablevalue. 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
-
subtract
Subtracts the value of the givenQuadrupleImmutablesubtrahend from the value of this Float128. 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 Float128- 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 givenlongsubtrahend from the value of this Float128. The value of thelongsubtrahend is preliminarily converted to aQuadrupleImmutablevalue. 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 Float128- 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 givendoublesubtrahend from the value of this Float128. The value of thedoublesubtrahend is preliminarily converted to aQuadrupleImmutablevalue. 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 Float128- 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
-
multiply
Multiplies the value of this Float128 by the value of the givenQuadrupleImmutablefactor. 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 Float128 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 Float128 by the value of the givenlongfactor. The value of thelongfactor is preliminarily converted to aQuadrupleImmutablevalue. 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 Float128 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 Float128 by the value of the givendoublefactor. The value of thedoublefactor is preliminarily converted to aQuadrupleImmutablevalue. 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 Float128 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
-
divide
Divides the value of this Float128 by the value of the givenQuadrupleImmutabledivisor. The instance acquires a new value that equals the quotient.- Parameters:
divisor- the divisor to divide the current value of this Float128 by- Returns:
- the reference to this object, which holds a new value that equals the quotient of the previous value of this Float128 divided by the given divisor
-
divide
Divides the value of this Float128 by the value of the givenlongdivisor. The instance acquires a new value that equals the quotient. The value of thelongdivisor is preliminarily converted to aQuadrupleImmutablevalue.- Parameters:
divisor- the divisor to divide the current value of this Float128 by- Returns:
- the reference to this object, which holds a new value that equals the quotient of the previous value of this Float128 divided by the given divisor
-
divide
Divides the value of this Float128 by the value of the givendoubledivisor. The instance acquires a new value that equals the quotient. The value of thedoubledivisor is preliminarily converted to aQuadrupleImmutablevalue.- Parameters:
divisor- the divisor to divide the current value of this Float128 by- Returns:
- the reference to this object, which holds a new value that equals the quotient of the previous value of this Float128 divided by the given divisor
-
sqrt
Computes a square root of the value of thisQuadrupleImmutableand 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 givenQuadrupleImmutable, creates and returns a new instance of Float128 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 Float128 containing the value of the square root of the given argument
-
cpy
Returns a copy of this Float128.- Returns:
- A new instance of Float128 with the same value as this
-
abs
Returns a new instance ofQuadrupleImmutablewith the value of the absolute value of this instance- Returns:
- a new instance of
QuadrupleImmutablewith the value of the absolute value of this instance
-
isNegative
public boolean isNegative()Checks if the value is negative.- Returns:
true, if the value is negative,falseotherwise
-
isInfinite
public boolean isInfinite()Checks if the value is infinite (i.eNEGATIVE_INFINITYorPOSITIVE_INFINITY).- Returns:
true, if the value is infinity (either positive or negative),falseotherwise
-
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),falseotherwise
-
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
-
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
-
compareTo
Compares the value of this instance with the value of the specified instance.- Specified by:
compareToin interfaceComparable<QuadrupleImmutable>- Parameters:
other- theQuadrupleImmutableto 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.
-
hashCode
public int hashCode()Computes a hashcode for thisQuadrupleImmutable, based on the values of its fields. -
toString
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
negative
-
exponent
-
mantHi
-
mantLo
-