buildOfLogicValue<T extends FloatingPointValue> static method

  1. @protected
T buildOfLogicValue<T extends FloatingPointValue>(
  1. T constructor({
    1. required LogicValue exponent,
    2. required LogicValue mantissa,
    3. required LogicValue sign,
    }),
  2. int exponentWidth,
  3. int mantissaWidth,
  4. LogicValue val,
)

A helper function for FloatingPointValue.ofLogicValue and base classes which performs some width checks and slicing.

Implementation

@protected
static T buildOfLogicValue<T extends FloatingPointValue>(
  T Function(
          {required LogicValue sign,
          required LogicValue exponent,
          required LogicValue mantissa})
      constructor,
  int exponentWidth,
  int mantissaWidth,
  LogicValue val,
) {
  final expectedWidth = 1 + exponentWidth + mantissaWidth;
  if (val.width != expectedWidth) {
    throw RohdHclException('Width of $val must be $expectedWidth');
  }

  return constructor(
      sign: val[-1],
      exponent: val.slice(exponentWidth + mantissaWidth - 1, mantissaWidth),
      mantissa: val.slice(mantissaWidth - 1, 0));
}