|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.github.kiprobinson.bigfraction.util.FloatUtil
public final class FloatUtil
Additional utilities for working with floay values. Useful to prevent hard-coding IEEE 754 constants in code.
Consider this a complement to the methods provided in Float.
| Field Summary | |
|---|---|
static int |
MAX_EXPONENT
The largest permitted exponent value, when using an exponent with offset. |
static int |
MAX_EXPONENT_BITS
The largest permitted exponent value, when using raw exponent bits. |
static int |
MAX_MANTISSA
The largest permitted mantissa value. |
static int |
MIN_EXPONENT
The smallest permitted exponent value, when using an exponent with offset. |
| Method Summary | |
|---|---|
static int[] |
getAllParts(float f)
Returns an array containing the parts of the float. |
static int[] |
getAllParts(float f,
boolean exponentAsBits)
Returns an array containing the parts of the float. |
static int |
getExponent(float f)
Returns the exponent, after adding the exponent offset to the exponent bits. |
static int |
getExponentBits(float f)
Returns the raw exponent bits, without adjusting for the offset. |
static float |
getFloat(int sign,
int exponent,
int mantissa)
Creates a new float primitive using the provided component bits. |
static float |
getFloat(int sign,
int exponent,
int mantissa,
boolean exponentAsBits)
Creates a new float primitive using the provided component bits. |
static int |
getMantissa(float f)
Returns the mantissa bits (bits 51-0). |
static int |
getSign(float f)
Returns the sign bit (bit 63). |
static boolean |
isFinite(float f)
Returns true if f is finite--not infinite and not NaN. |
static boolean |
isSubnormal(float f)
Returns whether or not this float is a subnormal value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MAX_MANTISSA
public static final int MAX_EXPONENT_BITS
public static final int MIN_EXPONENT
public static final int MAX_EXPONENT
| Method Detail |
|---|
public static boolean isFinite(float f)
f - a float value
public static int getSign(float f)
f - a float value
public static int getExponent(float f)
getExponent(0.5) == -1 because 1.0 == 1.0 * 2^-1getExponent(1.0) == 0 because 1.0 == 1.0 * 2^0getExponent(2.0) == 1 because 2.0 == 1.0 * 2^1
f - any float value
public static int getExponentBits(float f)
getExponentBits(0.5) == 0x3fegetExponentBits(1.0) == 0x3ffgetExponentBits(2.0) == 0x400
f - a float value
public static int getMantissa(float f)
f - a float value
public static boolean isSubnormal(float f)
f - a float value
public static int[] getAllParts(float f)
f - a float value
public static int[] getAllParts(float f,
boolean exponentAsBits)
f - a float valueexponentAsBits - whether to return exponent as raw bits rather than adjusted value
public static float getFloat(int sign,
int exponent,
int mantissa)
sign - sign bitexponent - adjusted exponentmantissa - mantissa bits
IllegalArgumentException - if any of the parts contain invalid bits.
public static float getFloat(int sign,
int exponent,
int mantissa,
boolean exponentAsBits)
sign - sign bitexponent - exponent (either raw bits or adjusted value)mantissa - mantissa bitsexponentAsBits - If true, assumes that exponent parameter represents the actual exponent bits. If false,
IEEE exponent offset value will be added to the offset to get the bits.
IllegalArgumentException - if any of the parts contain invalid bits.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||