Skip to content

Sdcb.Arithmetic 1.2.2

Latest

Choose a tag to compare

@sdcb sdcb released this 29 Oct 13:53

Sdcb.Arithmetic 1.2.2

dotnet add package Sdcb.Arithmetic --version 1.2.2

Fix: explicit precision is now validated on every public Real API (#7)

Thanks to @inkydragon for reporting this.

Previously only a few entry points (Real.DefaultPrecision, WithPrecision, and the FromBigInt(m, exponent, precision) overload) rejected an invalid precision. Elsewhere, an explicit precision outside the supported range was passed straight to the rounding core:

Example 1.2.1 1.2.2
Real.FromBigInt(new BigInt(1), precision: 1) / -1 Corrupt value (invalid significand) ArgumentOutOfRangeException
Real.FromBigInt(BigInt.Zero, precision: -1) Zero with an invalid precision (the zero early-return skipped validation) ArgumentOutOfRangeException
Real.Exp(x, precision: 1), Real.Add(a, b, precision: -5), … Same as above ArgumentOutOfRangeException

All public Real methods with a precision parameter now share one rule: 0 selects the default precision; any other value must be in [2, int.MaxValue / 64].

Behavior change

Calls that pass an explicit precision of 1, a negative value, or a value above int.MaxValue / 64 now throw ArgumentOutOfRangeException instead of returning an invalid value. Valid precisions behave exactly as before.

Tests

  • New RealPrecisionValidationTests: covers the issue's cases, including the exponent-overflow cases already fixed in 1.2.1, plus a reflection-based check that every public method with a precision parameter rejects 1, -1 and int.MaxValue / 64 + 1.
  • All 349 unit tests pass; bit-exact comparison against native MPFR (56,370 checks) reports 0 failures.

Full changelog: v1.2.1...v1.2.2