Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.lang
Class Float

    java.lang.Object
      java.lang.Float

    public final class Float

extends Object

Minimal Float implementation that supports floatToIntBits and intBitsToFloat

Author:
  Lawrie Griffiths

Method Summary
`static int` | `floatToIntBits(float value)` Returns the bit represention of a single-float value.
`static float` | `intBitsToFloat(int value)` Returns the single-float corresponding to a given bit represention.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait`

Method Detail

### floatToIntBits

    public static int floatToIntBits(float value)

  Returns the bit represention of a single-float value. The result is a representation of the floating-point argument according to the IEEE 754 floating-point "single precision" bit layout.
  - Bit 31 (the bit that is selected by the mask `0x80000000`) represents the sign of the floating-point number.
  - Bits 30-23 (the bits that are selected by the mask `0x7f800000`) represent the exponent.
  - Bits 22-0 (the bits that are selected by the mask `0x007fffff`) represent the significand (sometimes called the mantissa) of the floating-point number.
  - If the argument is positive infinity, the result is `0x7f800000`.
  - If the argument is negative infinity, the result is `0xff800000`.

    If the argument is NaN, the result is the integer representing the actual NaN value. The lejos implementation behaves like floatToRawIntBits and does not collapse NaN values.

  In all cases, the result is an integer that, when given to the `intBitsToFloat(int)` method, will produce a floating-point value equal to the argument to `floatToRawIntBits`.

  Parameters:
    `value` - a floating-point number.
  Returns:
    the bits that represent the floating-point number.

### intBitsToFloat

    public static float intBitsToFloat(int value)

  Returns the single-float corresponding to a given bit represention. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "single precision" bit layout.

  If the argument is `0x7f800000`, the result is positive infinity.

  If the argument is `0xff800000`, the result is negative infinity.

  If the argument is any value in the range `0x7f800001` through `0x7fffffff` or in the range `0xff800001` through `0xffffffff`, the result is NaN. All IEEE 754 NaN values of type `float` are, in effect, lumped together by the Java programming language into a single `float` value called NaN. Distinct values of NaN are only accessible by use of the `Float.floatToRawIntBits` method.

  In all other cases, let s, e, and m be three values that can be computed from the argument:

  >      int s = ((bits >> 31) == 0) ? 1 : -1;
  >      int e = ((bits >> 23) & 0xff);
  >      int m = (e == 0) ?
  >                      (bits & 0x7fffff) << 1 :
  >                      (bits & 0x7fffff) | 0x800000;

  Then the floating-point result equals the value of the mathematical expression s·m·2e-150.

  Parameters:
    `value` - an integer.
  Returns:
    the single-format floating-point value with the same bit pattern.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD