FixedPointValue.ofDouble constructor

FixedPointValue.ofDouble(
  1. double val, {
  2. required bool signed,
  3. required int m,
  4. required int n,
})

Constructs FixedPointValue of a Dart double rounding away from zero.

Implementation

factory FixedPointValue.ofDouble(double val,
    {required bool signed, required int m, required int n}) {
  if (!signed & (val < 0)) {
    throw RohdHclException('Negative input not allowed with unsigned');
  }
  final integerValue = (val * pow(2, n)).toInt();
  final w = signed ? 1 + m + n : m + n;
  final v = LogicValue.ofInt(integerValue, w);
  return FixedPointValue(value: v, signed: signed, m: m, n: n);
}