java.lang.Object
java.lang.Number
at.syntaxerror.ieee754.binary.Binary<T>
- All Implemented Interfaces:
Serializable,Comparable<T>
- Direct Known Subclasses:
Binary1024,Binary128,Binary16,Binary2048,Binary256,Binary32,Binary512,Binary64,Binary80
This class is the base class for implementing IEEE 754 floating point specifications
- Author:
- Thomas Kasper
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBinary(int signum, BinaryType type) Creates a new special binary floating-point number.Binary(int signum, BigDecimal value) Creates a new binary floating-point number with the given signum and value.Binary(int signum, BigDecimal value, boolean unchecked) Deprecated.internal use only -
Method Summary
Modifier and TypeMethodDescriptionintdoubleencode()Encodes this number into its binary representationfloatReturns theBigDecimalstored.abstract BinaryCodec<T>getCodec()Returns thecodecused for this binary floating-point numberintReturns the signum, which is either-1(negative),0(zero), or1(positive)intintValue()booleanisFinite()Checks whether this number isfinitebooleanChecks whether this number isInfinitybooleanisNaN()booleanChecks whether this number is negativebooleanChecks whether this number is-InfinitybooleanChecks whether this number is-0booleanChecks whether this number is positivebooleanChecks whether this number is+InfinitybooleanChecks whether this number is+0.booleanChecks whether this number isqNaNbooleanChecks whether this number issNaNbooleanisZero()Checks whether this number is0longtoString()Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
POSITIVE
public static final int POSITIVE- See Also:
-
NEGATIVE
public static final int NEGATIVE- See Also:
-
-
Constructor Details
-
Binary
Deprecated.internal use only- Parameters:
signum-value-unchecked-
-
Binary
Creates a new binary floating-point number with the given signum and value.If the value exceeds the
maximum value, the value becomesInfinitywith the respective sign.If the value is less than the
minimum value, the values becomes0.- Parameters:
signum- the signum (either-1,0, or1; must be the same asthe value's signum)value- the value
-
Binary
Creates a new special binary floating-point number.- Parameters:
signum- the signum (either-1or1)type- the special type (must not beBinaryType.FINITE)
-
-
Method Details
-
getBigDecimal
Returns theBigDecimalstored. Fails if the number is notfinite.- Returns:
- the stored
BigDecimal
-
getSignum
public int getSignum()Returns the signum, which is either-1(negative),0(zero), or1(positive)- Returns:
- the signum
-
isPositive
public boolean isPositive()Checks whether this number is positive- Returns:
- whether this number is positive
-
isNegative
public boolean isNegative()Checks whether this number is negative- Returns:
- whether this number is negative
-
isFinite
public boolean isFinite()Checks whether this number isfinite- Returns:
- whether this number is finite
-
isNaN
public boolean isNaN()- Returns:
- whether this number is
NaN
-
isSignalingNaN
public boolean isSignalingNaN()Checks whether this number issNaN- Returns:
- whether this number is
sNaN
-
isQuietNaN
public boolean isQuietNaN()Checks whether this number isqNaN- Returns:
- whether this number is
qNaN
-
isInfinity
public boolean isInfinity()Checks whether this number isInfinity- Returns:
- whether this number is
Infinity
-
isPositiveInfinity
public boolean isPositiveInfinity()Checks whether this number is+Infinity- Returns:
- whether this number is
+Infinity
-
isNegativeInfinity
public boolean isNegativeInfinity()Checks whether this number is-Infinity- Returns:
- whether this number is
-Infinity
-
isZero
public boolean isZero()Checks whether this number is0- Returns:
- whether this number is
0
-
isPositiveZero
public boolean isPositiveZero()Checks whether this number is+0.Note: The
signumvalue0also classifies as positive in this case- Returns:
- whether this number is
+0
-
isNegativeZero
public boolean isNegativeZero()Checks whether this number is-0- Returns:
- whether this number is
-0
-
encode
Encodes this number into its binary representation- Returns:
- the binary representation
-
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classNumber
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends Binary<T>>
-
toString
-
getCodec
Returns thecodecused for this binary floating-point number- Returns:
- the codec
-