getSpecialConstantComponents method
- FloatingPointConstants constantFloatingPoint
override
Returns a tuple of LogicValues for the sign, exponent, and
mantissa components of a special constant, or null
if the constant
does not have special components.This is useful for constants like NaN,
infinity, etc., in certain types of floating point representations.
Implementation
@override
@protected
({LogicValue sign, LogicValue exponent, LogicValue mantissa})?
getSpecialConstantComponents(
FloatingPointConstants constantFloatingPoint) {
final (
String signStr,
String exponentStr,
String mantissaStr
) stringComponents;
switch (constantFloatingPoint) {
/// Largest positive number, most positive exponent, full mantissa
case FloatingPointConstants.largestNormal:
stringComponents =
('0', '1' * exponentWidth, '${'1' * (mantissaWidth - 1)}0');
case FloatingPointConstants.nan:
stringComponents =
('0', '${'1' * (exponentWidth - 1)}1', '1' * mantissaWidth);
case FloatingPointConstants.positiveInfinity:
case FloatingPointConstants.negativeInfinity:
throw InfinityNotSupportedException(
'Infinity is not representable in E4M3 format');
case _:
return null;
}
return (
sign: LogicValue.of(stringComponents.$1),
exponent: LogicValue.of(stringComponents.$2),
mantissa: LogicValue.of(stringComponents.$3)
);
}