ofDouble method

FpvType ofDouble(
  1. double inDouble, {
  2. FloatingPointRoundingMode roundingMode = FloatingPointRoundingMode.roundNearestEven,
})

Convert from double using its native binary representation.

The input inDouble is decoded bit-exactly (no precision is lost in that step, since a Dart double is itself an IEEE 754 binary64 value) and then rounded exactly once into this format using roundingMode, via the same exact rounding engine used by add, multiply, squareRoot, and ofFloatingPointValueRounded. All FloatingPointRoundingModes are supported.

Implementation

FpvType ofDouble(double inDouble,
    {FloatingPointRoundingMode roundingMode =
        FloatingPointRoundingMode.roundNearestEven}) {
  if (inDouble.isNaN) {
    return nan;
  }
  if (inDouble.isInfinite) {
    return _infinityOrLargestFinite(
        negative: inDouble < 0.0, roundingMode: roundingMode);
  }

  final fp64 = FloatingPoint64Value.populator().ofDouble(inDouble);
  return _quantize(_decodeFinite(fp64),
      negative: fp64.sign.toBool(), roundingMode: roundingMode);
}