Class NFPUnsignedFloatLong

java.lang.Object
com.io7m.jnfp.core.NFPUnsignedFloatLong

public final class NFPUnsignedFloatLong extends Object

Conversion of unsigned normalized fixed-point values to and from floating point values.

The OpenGL 3.3 specification defines the conversion from floating point values x (implied to be in the range [0, 1]) to unsigned normalized fixed-point values f, with b bits of precision, as:

 f = x * (pow(2, b) - 1)
 

The specification defines the conversion from unsigned normalized fixed-point values f with b bits of precision to floating point values x as:

 x = f / (pow(2, b) - 1)
 
  • Method Details

    • fromUnsignedNormalized

      public static float fromUnsignedNormalized(long f, int b)
      Convert f to floating point format. f is assumed to be an unsigned fixed-point value with b bits of precision.
      Parameters:
      f - A value in the range [0, (2 ^ b) - 1]
      b - A value in the range [2, 32]
      Returns:
      A floating point value in the range [0, 1]
    • toUnsignedNormalized

      public static long toUnsignedNormalized(float x, int b)
      Convert x to fixed-point format.
      Parameters:
      x - A value in the range [0, 1]
      b - A value in the range [2, 32]
      Returns:
      An unsigned normalized fixed-point value with b bits of precision