addNum static method

double addNum(
  1. num a,
  2. num b
)

add (without loosing precision). 两个数相加(防止精度丢失)

Throws ArgumentError if either operand cannot be parsed as a precise Decimal (e.g. non-finite doubles). The silent 0.0 fallback is intentionally removed so misuse surfaces.

Precision caveat: operands are routed through a.toString() and parsed back as a Decimal. For a literal like 0.1 the display value is "0.1" and the result is exact, but an already-computed double such as 0.1 + 0.2 (whose value is 0.30000000000000004) is parsed at that long display value, carrying the floating-point drift into the result. The final .toDouble() step can also lose precision for very large magnitudes. When exactness matters, prefer addDecString / addDec (exact decimal strings) and pass string operands directly.

Implementation

static double addNum(num a, num b) {
  final result = _addDecimal(a.toString(), b.toString());
  if (result == null) {
    throw ArgumentError(
      'addNum: operands must be finite numbers (a=$a, b=$b)',
    );
  }
  return result.toDouble();
}