From 15db2d80a8986140d03f70c19b353d9cd166714c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 02:23:45 +0000 Subject: [PATCH] Route Log in a base's domain errors through DomainError [patch] Log(x, newBase) threw ArgumentOutOfRangeException directly with the raw PreciseNumber as its actual value, so reading .Message formatted it in fixed point: an extreme argument threw OverflowException, and Log(-1e-100000, 2) carried a 100,087-character message. Both checks now build the exception through DomainError like every other domain check. Fixes #202 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW4B4xxTAPzAHBD4zKk --- PreciseNumber.Test/PreciseNumberDomainErrorTests.cs | 7 +++++++ PreciseNumber.Test/PreciseNumberExponentialTests.cs | 2 +- PreciseNumber/PreciseNumber.Exponentials.cs | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/PreciseNumber.Test/PreciseNumberDomainErrorTests.cs b/PreciseNumber.Test/PreciseNumberDomainErrorTests.cs index 7d19133..65fb0b4 100644 --- a/PreciseNumber.Test/PreciseNumberDomainErrorTests.cs +++ b/PreciseNumber.Test/PreciseNumberDomainErrorTests.cs @@ -23,6 +23,9 @@ public class PreciseNumberDomainErrorTests "Log" => PreciseNumber.Log(x), "Log2" => PreciseNumber.Log2(x), "Log10" => PreciseNumber.Log10(x), + "LogInBaseTwo" => PreciseNumber.Log(x, Parse("2")), + "LogOfTwoInBase" => PreciseNumber.Log(Parse("2"), x), + "LogOfTwoInBaseToFiveDigits" => PreciseNumber.Log(Parse("2"), x, 5), "LogP1" => PreciseNumber.LogP1(x), "Acosh" => PreciseNumber.Acosh(x), "Atanh" => PreciseNumber.Atanh(x), @@ -40,6 +43,10 @@ public class PreciseNumberDomainErrorTests [DataRow("Log", "-1e-2000000000")] [DataRow("Log", "-1e-2147483648")] [DataRow("Log", "-1e-200000000")] + [DataRow("LogInBaseTwo", "-1e-2147483648")] + [DataRow("LogInBaseTwo", "-1e-100000")] + [DataRow("LogOfTwoInBase", "-1e-2147483648")] + [DataRow("LogOfTwoInBaseToFiveDigits", "-1e2147483647")] [DataRow("Log2", "-1e2000000000")] [DataRow("Log2", "-1e-2147483648")] [DataRow("Log10", "-1e2000000000")] diff --git a/PreciseNumber.Test/PreciseNumberExponentialTests.cs b/PreciseNumber.Test/PreciseNumberExponentialTests.cs index 930071a..1014a24 100644 --- a/PreciseNumber.Test/PreciseNumberExponentialTests.cs +++ b/PreciseNumber.Test/PreciseNumberExponentialTests.cs @@ -150,7 +150,7 @@ public void TestLogInABaseNamesTheArgumentOutsideTheDomain() ArgumentOutOfRangeException negativeBase = Assert.ThrowsExactly( () => PreciseNumber.Log(5.ToPreciseNumber(), (-2).ToPreciseNumber())); Assert.AreEqual("newBase", negativeBase.ParamName); - Assert.AreEqual((-2).ToPreciseNumber(), negativeBase.ActualValue); + Assert.AreEqual("-2E+000", negativeBase.ActualValue); ArgumentOutOfRangeException zeroBase = Assert.ThrowsExactly( () => PreciseNumber.Log(5.ToPreciseNumber(), PreciseNumber.Zero, 20)); diff --git a/PreciseNumber/PreciseNumber.Exponentials.cs b/PreciseNumber/PreciseNumber.Exponentials.cs index 8c4aad4..a4bc1c6 100644 --- a/PreciseNumber/PreciseNumber.Exponentials.cs +++ b/PreciseNumber/PreciseNumber.Exponentials.cs @@ -221,12 +221,12 @@ public static PreciseNumber Log(PreciseNumber x, PreciseNumber newBase, int sign // base is not reported as a bad value by the single-argument Log it would otherwise reach. if (x.Significand.Sign <= 0) { - throw new ArgumentOutOfRangeException(nameof(x), x, NonPositiveLogarithmMessage); + throw DomainError(nameof(x), x, NonPositiveLogarithmMessage); } if (newBase.Significand.Sign <= 0) { - throw new ArgumentOutOfRangeException(nameof(newBase), newBase, NonPositiveLogarithmMessage); + throw DomainError(nameof(newBase), newBase, NonPositiveLogarithmMessage); } int working = significantDigits + ExponentialGuardDigits;