FloatingPoint32Value.ofDouble constructor

FloatingPoint32Value.ofDouble(
  1. double inDouble
)

Numeric conversion of a FloatingPoint32Value from a host double

Implementation

factory FloatingPoint32Value.ofDouble(double inDouble) {
  final byteData = ByteData(4)..setFloat32(0, inDouble);
  final accum = byteData.buffer
      .asUint8List()
      .map((b) => LogicValue.ofInt(b, 32))
      .reduce((accum, v) => (accum << 8) | v);

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