ofConstant method

FpvType ofConstant(
  1. FloatingPointConstants constantFloatingPoint
)

Creates a new FloatingPointValue represented by the given constantFloatingPoint.

Implementation

FpvType ofConstant(FloatingPointConstants constantFloatingPoint) {
  if (explicitJBit) {
    if (mantissaWidth < 2) {
      throw ArgumentError.value(mantissaWidth, 'mantissaWidth',
          'explicit-J-bit formats require a NaN payload bit');
    }
    if (constantFloatingPoint == FloatingPointConstants.nan) {
      return populate(
          sign: LogicValue.zero,
          exponent: LogicValue.filled(exponentWidth, LogicValue.one),
          mantissa: [
            LogicValue.one,
            LogicValue.one,
            LogicValue.filled(mantissaWidth - 2, LogicValue.zero)
          ].swizzle());
    }
    final implicit = FloatingPointValue.populator(
            exponentWidth: exponentWidth, mantissaWidth: mantissaWidth - 1)
        .ofConstant(constantFloatingPoint);
    final explicitJBitValue =
        implicit.isNormal() || implicit.isAnInfinity || implicit.isNaN;
    return populate(
        sign: implicit.sign,
        exponent: implicit.exponent,
        mantissa: [LogicValue.ofBool(explicitJBitValue), implicit.mantissa]
            .swizzle());
  }
  final components = _constantComponents(constantFloatingPoint);

  return populate(
      sign: components.sign,
      exponent: components.exponent,
      mantissa: components.mantissa);
}