reciprocal calc function
.NET Test / .NET tests (push) Successful in 1m30s

This commit is contained in:
2026-09-15 01:25:57 +04:00
parent 1e14a72d1c
commit 210c2ebfcc
4 changed files with 219 additions and 2 deletions
+36
View File
@@ -12,6 +12,42 @@ public static partial class DDMath
return DoubleDouble.Abs(value);
}
/// <summary>Returns the reciprocal with double-double precision.</summary>
/// <remarks>
/// Specializes scalar/DD division for a numerator of one, omitting only its
/// redundant numerator checks. The arithmetic sequence and boundary handling
/// are unchanged, preserving the high and low component bits of <c>1.0 / value</c>.
/// Results are approximate, not guaranteed correctly rounded;
/// finite results are tested against a relative error bound of 2^-100 plus one
/// minimum binary64 subnormal. Precision decreases near underflow.
/// Signed zeros map to signed infinities, signed infinities to signed zeros,
/// and NaN to canonical NaN. Finite overflow produces signed infinity.
/// </remarks>
[Pure]
public static DoubleDouble Reciprocal(DoubleDouble value)
{
const double one = 1.0;
if (!DoubleDouble.IsFinite(value) || value._high == 0.0)
{
return new DoubleDouble(one / value._high);
}
if (!PreciseMathHelper.IsDivisionWithinFastRange(value._high))
{
return PreciseMathHelper.DivideBoundary(one, value);
}
double quotient = one / value._high;
double remainder = Math.FusedMultiplyAdd(-quotient, value._high, one);
remainder = Math.FusedMultiplyAdd(-quotient, value._low, remainder);
double correction = remainder / value._high;
// For normalized input, using the high denominator in the correction
// adds only O(u^2) error, with u=2^-53. The denominator exponent guard
// keeps the quotient normal and finite; it dominates the correction,
// so QuickTwoSum is ordered and its sum remains finite.
(double high, double low) = PreciseMathHelper.TwoQuickAdd(quotient, correction);
return new DoubleDouble(high, low == 0.0 ? 0.0 : low);
}
/// <summary>Returns the nonnegative square root with double-double precision.</summary>
/// <remarks>
/// Uses power-of-two scaling and an FMA-based Newton correction. Results are