Skip to content

6.3.4

@dankogai dankogai tagged this 21 Aug 11:05
Three classes of fix, each pinned by a mutation-verified test:

1/x inversions rounded at the wrong precision.  BigFloat's bare `/`
keeps operand-width + Self.precision (the static default) bits and
ignores the caller's px, so a narrow operand capped the whole call:
log(0.75, precision:1024) delivered 130 bits, atan(3, 1024) 132,
pow(3/4, 1/4, 1024) 132.  log, atan, pow, atan2, binaryLog and
logByNewtonRaphson now spell their inversions divided(by:precision:).

acos is now the half-angle 2*atan(sqrt((1-x)/(1+x))), in which every
step rounds relatively.  pi/2 - asin(x) subtracted O(1) values, so near
1 -- where acos(1-d) ~ sqrt(2d) is all cancellation -- it kept 99 of
the 128 bits asked, and no working width could save it.

The exp/log family worked *at* the asked-for precision and delivered a
few bits under it (exp 130, log1p 119 of 128).  exp, expMinusOne, exp2,
log, log2, log10, asin, tan and tanh now carry 32 guard bits like the
trig family, and log's atanh series is factored as t * sum(t^2k/(2k+1))
so the sum stays O(1), where truncate's absolute grid is a relative
grid.  Delivered bits at precision:128 rise from 119-138 to 159-204.

Also: atan's series never truncated its running term, whose exact
BigRat denominator grew by (2i+1)(x^2+1) every iteration -- a 328-bit
asin took minutes in a debug build and the full test suite appeared to
hang.  One truncate makes the debug suite finish in 29s and asin twice
as fast in release.

Tried and deliberately not kept, with measurements in the comments:
dedicated small-x branches for atanh/asinh/log1p (the log rewrite alone
fixes them; atanh's branch measured 161 bits against the naive route's
191) and a log1p form of acosh (identical to the classic).  The test
arguments are exactly-representable non-dyadic values (3 * 2^-k): 2^-k
lands next to powers of two where losses hide, and unrepresentable
arguments like 0.001 measure the input's rounding, not the function's.

Unchanged because they measured fine: pow's core, cbrt, hypot, erf,
erfc, gamma, logGamma, sinhcosh.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Assets 2
Loading