Skip to content

Reading .Message from Log(x, newBase)'s domain error throws OverflowException for an extreme argument: #197's two new checks bypass DomainError (regression of #190) #202

Open

Description

@matt-edmondson

What happens

try { PreciseNumber.Log(PreciseNumber.Parse("-1e-2147483648", CultureInfo.InvariantCulture), 2.ToPreciseNumber()); }
catch (ArgumentOutOfRangeException e) { _ = e.Message; }
  • Actual: reading e.Message throws OverflowException: An exponent of -2147483648 needs more characters in fixed point notation than a string can hold.
    • The same happens when the bad value is the base: Log(2, -1e-2147483648) and Log(2, -1e2147483647, 5).
    • For Log(-1e-100000, 2), the message is 100,087 characters long.
  • Expected: the short E-notation message that every other domain check gives since Render a domain error's argument in E notation, so its message stays short [patch] #192. For example, Log(-1e-2147483648).Message is 98 characters ending in Actual value was -1E-2147483648., and Sqrt(-1e-2147483648) gives 101 characters.

Why

PreciseNumber/PreciseNumber.Exponentials.cs, lines 224 and 229 at f7fd71b, throw directly and pass the raw PreciseNumber as actualValue:

throw new ArgumentOutOfRangeException(nameof(x), x, NonPositiveLogarithmMessage);
throw new ArgumentOutOfRangeException(nameof(newBase), newBase, NonPositiveLogarithmMessage);

ArgumentOutOfRangeException.Message then formats the value with fixed-point ToString(), which is the #190 failure. #192 moved every domain check onto DomainError (line 91). #197 (bc7471f, fixing #196) landed in parallel and added these two throws without it. CLAUDE.md states that every domain check builds its exception through DomainError.

Suggested fix / acceptance

  • Change both throws to throw DomainError(nameof(x), x, NonPositiveLogarithmMessage); and throw DomainError(nameof(newBase), newBase, NonPositiveLogarithmMessage);.
  • Add cases to PreciseNumberDomainErrorTests for Log(x, base) with an extreme bad x and with an extreme bad newBase. In both, .Message must stay short and must not throw.
  • Update TestLogInABaseNamesTheArgumentOutsideTheDomain. It asserts ActualValue == -2, but with the fix ActualValue holds the rendered string ("-2E+000").

Activity

  1. matt-edmondson commented on Nov 12, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions