Support all `Real` types in the domain-checked functions #112
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 511 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.373
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #112"
general
weight: 0.35
oscardssmith
Fixes #95.
The bug
Every function in the
sin,cos,tan,asin,acos,acosh,atanh,log,log2,log10,log1pgroup threw aMethodErrorforBigFloat:The
::Realentry point was a trampoline that converted its argument withfloatand re-dispatched. Becausefloatis the identity onAbstractFloat, a guard threwMethodErrorto break the recursion, and concrete methods existed only forUnion{Float16, Float32, Float64}— soBigFloatalways reached the guard.sqrthad a worse variant of the same problem.sqrt(x::Real) = sqrt(float(x))has no guard, so aRealthat is its ownfloatfixed point and is not anAbstractFloatrecursed until it hit aStackOverflowError.The change
One
::Realmethod per function that converts withfloatexactly once and then callsBasedirectly, instead of re-dispatching on the converted value. That coversBigFloatand alsoRealtypes that are notAbstractFloatand thatfloatleaves unchanged, such asForwardDiff.Dual.sqrtgets the same treatment through an internal_sqrthelper, which keeps thesqrt_llvmintrinsic for the narrow float union.lgammakeeps the trampoline and its guard, since it has noBasecounterpart andNaNMath.lgamma(big"2.0")should stay aMethodError.Why
::Realand not::NumberA
::Numbersignature would also fix dimensionlessUnitfulquantities, which currently throw aDomainError. It was rejected because the opt-out list is open-ended — it is not justComplex:| type |
<:Real|<:Number|x < 0||---|---|---|---|
|
Quaternions.Quaternion| ✗ | ✓ | MethodError ||
TaylorSeries.Taylor1| ✗ | ✓ | compares constant term only ||
Unitful.Quantity| ✗ | ✓ | ✓ |NaNMath.logon a quaternion works today and would become aMethodError; on aTaylor1the domain check would be meaningless andoftype(x, NaN)silently truncates a 3rd-order series to 1st order.Realcarries a total-order contract,Numbercarries none, so the domain checks belong onRealand everything else keeps forwarding toBaseunchanged. Unitful is better served the wayForwardDiff,SymbolicsandSymbolicUtilsalready handle this, by defining their ownNaNMathmethods.Conditions are whitelists
Each condition is written so that only arguments inside the domain reach
Base. Besides being the safer default for third-partyRealtypes, it is slightly cheaper:sqrtfolds to a barefsqrtinstruction because the hardware already returnsNaNfor negative input, andsin,cosandtanlose two instructions each. All other functions are unchanged instruction-for-instruction.Behaviour changes beyond the fix
powno longer returns a finite value for a negative base with a non-integer exponent whose conversion to a float rounds to an integer.NaNMath.pow(-1.5, (2^60 + 1)//2)returnedInfand now returnsNaN, because the check looks at the original exponent rather than the promoted float.A
NaNargument's sign bit is no longer propagated bysin,cos,tan,asin,atanhandacosh. IEEE 754 assigns no meaning to it.Tests
BigFloat (#95), 147 assertions. Runs at two non-default precisions (64 and 1024 bits) and assertsprecision(y) == pand bit-exact equality withBase, so neither aFloat64detour nor a hard-coded precision can pass. Also pins that the result takes the global precision at call time, matchingBase.`
Realfixed points offloat, 49 assertions, against a test type that documents the full interface the domain checks rely on:float,promote_rule,<,abs,isfinite.
Regression tests for the powexponent-rounding case and forFloat16sqrt.Verified unchanged against ForwardDiff
,Symbolics,SymbolicUtils,TaylorSeries,Quaternions,UnitfulandComplex, and exhaustively over all 65536Float16bit patterns forsqrt`.🤖 Generated with Claude Code