Beispiel #1
0
  /**
   * Converts the floating point value to its exponent-mantissa representation. The mantissa
   * occupies the 11 least significant bits (bits 10-0), and the exponent the previous 5 bits (bits
   * 15-11).
   *
   * @param step The quantization step, normalized to a dynamic range of 1.
   * @return The exponent mantissa representation of the step.
   */
  public static int convertToExpMantissa(float step) {
    int exp;

    exp = (int) Math.ceil(-Math.log(step) / log2);
    if (exp > QSTEP_MAX_EXPONENT) {
      // If step size is too small for exponent representation, use the
      // minimum, which is exponent QSTEP_MAX_EXPONENT and mantissa 0.
      return (QSTEP_MAX_EXPONENT << QSTEP_MANTISSA_BITS);
    }
    // NOTE: this formula does not support more than 5 bits for the
    // exponent, otherwise (-1<<exp) might overflow (the - is used to be
    // able to represent 2**31)
    return (exp << QSTEP_MANTISSA_BITS)
        | ((int) ((-step * (-1 << exp) - 1f) * (1 << QSTEP_MANTISSA_BITS) + 0.5f));
  }