isLegalValue method

bool isLegalValue()

Check if the mantissa and exponent stored are compatible.

Implementation

bool isLegalValue() {
  if (explicitJBit) {
    final e = exponent.toInt();
    final m = mantissa.toInt();
    // TODO(desmonddak): We need to check this with bit-pattern testing
    // of legal mantissas and that exponents are compatible with those.
    // Basically, if e > 0 then we expect a 1 somewhere.  If e == 0 then
    // we expect anything except a leading 1 in the mantissas.
    final normMantissa = 1 << (mantissa.width - 1);

    return ((e == 0) && (m < normMantissa)) || ((e > 0) && (m >= 1));
  }
  return true;
}