ofDouble method

FxvType ofDouble(
  1. double val
)

Constructs FixedPointValue from a Dart double rounding away from zero.

Implementation

FxvType ofDouble(double val) {
  final signed = _unpopulated.signed;
  if (!signed & (val < 0)) {
    throw RohdHclException('Negative input not allowed with unsigned');
  }
  if (!canStore(val,
      signed: signed,
      integerWidth: integerWidth,
      fractionWidth: fractionWidth)) {
    throw RohdHclException('Double is too long to store in '
        'FixedPointValue: $integerWidth, $fractionWidth');
  }
  final integerValue = BigInt.from(val * pow(2, fractionWidth));
  final w = signed
      ? 1 + integerWidth + fractionWidth
      : integerWidth + fractionWidth;
  final v = LogicValue.ofBigInt(integerValue, w);
  return ofLogicValue(v);
}