org.apache.lucene.util

## Class SmallFloat

- java.lang.Object
- - org.apache.lucene.util.SmallFloat

-     public class SmallFloat
      extends Object

  Floating point numbers smaller than 32 bits.
  NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static float` | `byte315ToFloat(byte b)` byteToFloat(b, mantissaBits=3, zeroExponent=15)
    `static int` | `byte4ToInt(byte b)` Decode values that have been encoded with `intToByte4(int)`.
    `static float` | `byteToFloat(byte b, int numMantissaBits, int zeroExp)` Converts an 8 bit float to a 32 bit float.
    `static byte` | `floatToByte(float f, int numMantissaBits, int zeroExp)` Converts a 32 bit float to an 8 bit float.
    `static byte` | `floatToByte315(float f)` floatToByte(b, mantissaBits=3, zeroExponent=15) smallest non-zero value = 5.820766E-10 largest value = 7.5161928E9 epsilon = 0.125
    `static long` | `int4ToLong(int i)` Decode values encoded with `longToInt4(long)`.
    `static byte` | `intToByte4(int i)` Encode an integer to a byte.
    `static int` | `longToInt4(long i)` Float-like encoding for positive longs that preserves ordering and 4 significant bits.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### floatToByte

          public static byte floatToByte(float f,
                                         int numMantissaBits,
                                         int zeroExp)

      Converts a 32 bit float to an 8 bit float.
      Values less than zero are all mapped to zero.
      Values are truncated (rounded down) to the nearest 8 bit value.
      Values between zero and the smallest representable value are rounded up.
      Parameters:
        `f` - the 32 bit float to be converted to an 8 bit float (byte)
        `numMantissaBits` - the number of mantissa bits to use in the byte, with the remainder to be used in the exponent
        `zeroExp` - the zero-point in the range of exponent values
      Returns:
        the 8 bit float representation

    - #### byteToFloat

          public static float byteToFloat(byte b,
                                          int numMantissaBits,
                                          int zeroExp)

      Converts an 8 bit float to a 32 bit float.

    - #### floatToByte315

          public static byte floatToByte315(float f)

      floatToByte(b, mantissaBits=3, zeroExponent=15)
      smallest non-zero value = 5.820766E-10
      largest value = 7.5161928E9
      epsilon = 0.125

    - #### byte315ToFloat

          public static float byte315ToFloat(byte b)

      byteToFloat(b, mantissaBits=3, zeroExponent=15)

    - #### longToInt4

          public static int longToInt4(long i)

      Float-like encoding for positive longs that preserves ordering and 4 significant bits.

    - #### int4ToLong

          public static final long int4ToLong(int i)

      Decode values encoded with `longToInt4(long)`.

    - #### intToByte4

          public static byte intToByte4(int i)

      Encode an integer to a byte. It is built upon `longToInt4(long)` and leverages the fact that `longToInt4(Integer.MAX_VALUE)` is less than 255 to encode low values more accurately.

    - #### byte4ToInt

          public static int byte4ToInt(byte b)

      Decode values that have been encoded with `intToByte4(int)`.

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.