code wiki / _hdl_build / _pe_f64erf_full.nx
_pe_f64erf_full.nx source
↩ module page · 33 lines · 1552 B
1// _pe_f64erf_full.nx -- FULL-DOMAIN f64 erf: closes erf's OWN LOUD-NAN hole (1.75..6) by
2// composing the two proven rungs, so erf becomes a complete function over all reals.
3// |x| <= 1.75 -> nx_f64_erf (the Taylor series; handles 0/subnormal/sign/specials)
4// 1.75 < |x| < 6 -> sign * (1 - erfc(|x|)) [nx_f64_erfc, the Laplace CF]
5// |x| >= 6 -> sign * 1 (erf saturates sub-ulp)
6// NaN -> NaN
7// Parallel to the gamma reflection: a named gap retired by composition of proven kernels,
8// never fabricated. f64 software-IEEE throughout.
9// license_tier: ORIGINAL
10//
11// module: nishi-core.math.f64_erf_full
12// depends: nishi-core.math.f64, nishi-core.math.f64_erf, nishi-core.math.f64_erfc
13// capability: F64_ERF_FULL_DOMAIN
14import "nx_syscalls.nx"
15import "nx_f64.nx"
16import "_pe_f64erf.nx"
17import "_pe_f64erfc.nx"
18
19const EF_ONE: i64 = 0x3FF0000000000000 // 1.0
20const EF_HI: i64 = 0x3FFC000000000000 // 1.75
21const EF_SIX: i64 = 0x4018000000000000 // 6.0
22const EF_INF: i64 = 0x7FF0000000000000 // +inf bits
23
24func nx_f64_erf_full(x: i64) -> i64 {
25 let ax: i64 = x & 0x7FFFFFFFFFFFFFFF
26 if ax > EF_INF { return x } // NaN passes through
27 if ax <= EF_HI { return nx_f64_erf(x) } // series region (incl 0 / subnormal / sign)
28 let sgn: i64 = x & 0x8000000000000000
29 if ax >= EF_SIX { return sgn | EF_ONE } // saturate to +-1 (also +-inf)
30 // gap 1.75 < |x| < 6: erf(x) = sign * (1 - erfc(|x|))
31 let ec: i64 = nx_f64_erfc(ax)
32 return sgn | nx_f64_sub(EF_ONE, ec)
33}