isLegalValue method
Check if the mantissa and exponent stored are compatible.
Implementation
bool isLegalValue() {
if (explicitJBit) {
final e = exponent.toInt();
final m = mantissa.toInt();
// For a subnormal/zero exponent (e == 0), the explicit j-bit (the
// mantissa's MSB) must be 0. For a normal exponent (e > 0), the
// explicit j-bit must be 1: this is the entire purpose of storing the
// j-bit explicitly, so any other bit pattern is not a legal encoding.
final normMantissa = 1 << (mantissa.width - 1);
return ((e == 0) && (m < normMantissa)) ||
((e > 0) && (m >= normMantissa));
}
return true;
}