FloatingPointValue.getFloatingPointConstant constructor
- FloatingPointConstants constantFloatingPoint,
- int exponentWidth,
- int mantissaWidth
Return the FloatingPointValue representing the constant specified
Implementation
factory FloatingPointValue.getFloatingPointConstant(
FloatingPointConstants constantFloatingPoint,
int exponentWidth,
int mantissaWidth) {
switch (constantFloatingPoint) {
/// smallest possible number
case FloatingPointConstants.negativeInfinity:
return FloatingPointValue.ofBinaryStrings(
'1', '1' * exponentWidth, '0' * mantissaWidth);
/// -0.0
case FloatingPointConstants.negativeZero:
return FloatingPointValue.ofBinaryStrings(
'1', '0' * exponentWidth, '0' * mantissaWidth);
/// 0.0
case FloatingPointConstants.positiveZero:
return FloatingPointValue.ofBinaryStrings(
'0', '0' * exponentWidth, '0' * mantissaWidth);
/// Smallest possible number, most exponent negative, LSB set in mantissa
case FloatingPointConstants.smallestPositiveSubnormal:
return FloatingPointValue.ofBinaryStrings(
'0', '0' * exponentWidth, '${'0' * (mantissaWidth - 1)}1');
/// Largest possible subnormal, most negative exponent, mantissa all 1s
case FloatingPointConstants.largestPositiveSubnormal:
return FloatingPointValue.ofBinaryStrings(
'0', '0' * exponentWidth, '1' * mantissaWidth);
/// Smallest possible positive number, most negative exponent, mantissa 0
case FloatingPointConstants.smallestPositiveNormal:
return FloatingPointValue.ofBinaryStrings(
'0', '${'0' * (exponentWidth - 1)}1', '0' * mantissaWidth);
/// Largest number smaller than one
case FloatingPointConstants.largestLessThanOne:
return FloatingPointValue.ofBinaryStrings(
'0', '0${'1' * (exponentWidth - 2)}0', '1' * mantissaWidth);
/// The number '1.0'
case FloatingPointConstants.one:
return FloatingPointValue.ofBinaryStrings(
'0', '0${'1' * (exponentWidth - 1)}', '0' * mantissaWidth);
/// Smallest number greater than one
case FloatingPointConstants.smallestLargerThanOne:
return FloatingPointValue.ofBinaryStrings('0',
'0${'1' * (exponentWidth - 2)}0', '${'0' * (mantissaWidth - 1)}1');
/// Largest positive number, most positive exponent, full mantissa
case FloatingPointConstants.largestNormal:
return FloatingPointValue.ofBinaryStrings(
'0', '0' * exponentWidth, '1' * mantissaWidth);
/// Largest possible number
case FloatingPointConstants.infinity:
return FloatingPointValue.ofBinaryStrings(
'0', '1' * exponentWidth, '0' * mantissaWidth);
}
}