FloatingPoint8E4M3Value.getFloatingPointConstant constructor

FloatingPoint8E4M3Value.getFloatingPointConstant(
  1. FloatingPointConstants constantFloatingPoint
)

Return the FloatingPointValue representing the constant specified. Special case for 8E4M3 type.

Implementation

factory FloatingPoint8E4M3Value.getFloatingPointConstant(
    FloatingPointConstants constantFloatingPoint) {
  switch (constantFloatingPoint) {
    /// Largest positive number, most positive exponent, full mantissa
    case FloatingPointConstants.largestNormal:
      return FloatingPoint8E4M3Value.ofBinaryStrings(
          '0', '1' * exponentWidth, '${'1' * (mantissaWidth - 1)}0');
    case FloatingPointConstants.nan:
      return FloatingPoint8E4M3Value.ofBinaryStrings(
          '0', '${'1' * (exponentWidth - 1)}1', '1' * mantissaWidth);
    case FloatingPointConstants.infinity:
    case FloatingPointConstants.negativeInfinity:
      throw RohdHclException('Infinity is not representable in this format');
    case _:
      return FloatingPointValue.getFloatingPointConstant(
              constantFloatingPoint, exponentWidth, mantissaWidth)
          as FloatingPoint8E4M3Value;
  }
}