operator * method

FixedPointValue operator *(
  1. FixedPointValue other
)

Multiplication operation that returns a FixedPointValue. The result is signed if one of the operands is signed. The result fraction width is the sum of fraction widths of operands.

Implementation

FixedPointValue operator *(FixedPointValue other) {
  if (!value.isValid | !other.value.isValid) {
    throw RohdHclException('Inputs must be valid.');
  }
  final s = signed | other.signed;
  final mr = s
      ? integerWidth + other.integerWidth + 1
      : integerWidth + other.integerWidth;
  final nr = fractionWidth + other.fractionWidth;
  final tr = mr + nr;
  final val1 = FixedPointValue.populator(
          integerWidth: tr - fractionWidth,
          fractionWidth: fractionWidth,
          signed: s)
      .widen(this)
      .value;
  final val2 = FixedPointValue.populator(
          integerWidth: tr - other.fractionWidth,
          fractionWidth: other.fractionWidth,
          signed: s)
      .widen(other)
      .value;
  return FixedPointValue.populator(
          integerWidth: mr, fractionWidth: nr, signed: s)
      .ofLogicValue(val1 * val2);
}