java.lang.Object
java.lang.Number
at.syntaxerror.ieee754.Floating<T>
- All Implemented Interfaces:
Serializable
,Comparable<T>
- Author:
- Thomas Kasper
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFloating
(int signum, FloatingType type) Creates a new special floating-point number.Floating
(int signum, BigDecimal value) Creates a new floating-point number with the given signum and value. -
Method Summary
Modifier and TypeMethodDescriptionint
double
encode()
Encodes this number into its binary representationfloat
Returns theBigDecimal
stored.abstract FloatingCodec
<T> getCodec()
Returns thecodec
used for this floating-point numberint
Returns the signum, which is either-1
(negative),0
(zero), or1
(positive)int
intValue()
boolean
isFinite()
Checks whether this number isfinite
boolean
Checks whether this number isInfinity
boolean
isNaN()
boolean
Checks whether this number is negativeboolean
Checks whether this number is-Infinity
boolean
Checks whether this number is-0
boolean
Checks whether this number is positiveboolean
Checks whether this number is+Infinity
boolean
Checks whether this number is+0
.boolean
Checks whether this number isqNaN
boolean
Checks whether this number issNaN
boolean
isZero()
Checks whether this number is0
long
toString()
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
-
Floating
Creates a new floating-point number with the given signum and value.If the value exceeds the
maximum value
, the value becomesInfinity
with 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
-
Floating
Creates a new special floating-point number.- Parameters:
signum
- the signum (either-1
or1
)type
- the special type (must not beFloatingType.FINITE
)
-
-
Method Details
-
getBigDecimal
Returns theBigDecimal
stored. 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
signum
value0
also 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:
floatValue
in classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValue
in classNumber
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T extends Floating<T>>
-
toString
-
getCodec
Returns thecodec
used for this floating-point number- Returns:
- the codec
-