ofFloatingPointValue method

FloatingPointValue ofFloatingPointValue(
  1. FloatingPointValue fpv, {
  2. bool canonicalizeExplicit = false,
})

Convert to from one FloatingPointValue to another, canonicalizing the mantissa as requested if the output FloatingPointValue has an explicit J bit.

Implementation

FloatingPointValue ofFloatingPointValue(FloatingPointValue fpv,
    {bool canonicalizeExplicit = false}) {
  final components = _components(fpv,
      canonicalizeExplicit:
          fpv.explicitJBit & (canonicalizeExplicit | !explicitJBit));
  if (exponentWidth != fpv.exponentWidth) {
    throw RohdHclException(
        'Cannot convert FloatingPointValue with exponent width '
        '${fpv.exponentWidth} to one with width $exponentWidth');
  }
  if (mantissaWidth - (explicitJBit ? 1 : 0) !=
      fpv.mantissaWidth - (fpv.explicitJBit ? 1 : 0)) {
    throw RohdHclException(
        'Cannot convert FloatingPointValue with mantissa width '
        '${fpv.mantissaWidth} to one with width $mantissaWidth');
  }

  final extendedMantissa = [
    if (fpv.isNormal() & !(fpv.isAnInfinity | fpv.isNaN))
      LogicValue.one
    else
      LogicValue.zero,
    components.mantissa
  ].swizzle();
  return FloatingPointValue(
      sign: components.sign,
      exponent: components.exponent,
      mantissa: (explicitJBit != fpv.explicitJBit)
          ? extendedMantissa.getRange(
              0,
              components.mantissa.width +
                  (explicitJBit ? 1 : 0) -
                  (fpv.explicitJBit ? 1 : 0))
          : components.mantissa,
      explicitjBit: explicitJBit);
}