@xort/rcmg 0.0.0-stage → 0.1.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +21 -0
- package/PROVENANCE.json +1601 -0
- package/README.md +152 -2
- package/licenses/registry/allocator-api2-0.2.22-c19b7c6f923b/LICENSE-APACHE +176 -0
- package/licenses/registry/allocator-api2-0.2.22-c19b7c6f923b/LICENSE-MIT +23 -0
- package/licenses/registry/autocfg-1.5.1-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/autocfg-1.5.1-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/alloc.rs +794 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/mod.rs +93 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/raw_vec.rs +781 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/str/lossy.rs +209 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/str/mod.rs +43 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/string.rs +2191 -0
- package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/vec.rs +3051 -0
- package/licenses/registry/cfg-if-1.0.5-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/cfg-if-1.0.5-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/equivalent-1.0.3-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/equivalent-1.0.3-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/foldhash-0.2.0-c19b7c6f923b/LICENSE +19 -0
- package/licenses/registry/hashbrown-0.16.1-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/hashbrown-0.16.1-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/LICENSE.txt +258 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/acos.rs +112 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/acosf.rs +79 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/asin.rs +115 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/asinf.rs +68 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atan.rs +180 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atan2.rs +131 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atan2f.rs +90 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atanf.rs +108 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cbrt.rs +219 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cbrtf.rs +73 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cos.rs +77 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cosf.rs +86 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/erf.rs +314 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/erff.rs +226 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/exp.rs +156 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/exp2.rs +400 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/exp2f.rs +141 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/expf.rs +103 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/expm1.rs +142 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/expm1f.rs +134 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/fma.rs +171 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/ceil.rs +174 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/floor.rs +157 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fma.rs +278 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmax.rs +23 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmaximum.rs +27 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmaximum_num.rs +29 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmin.rs +23 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fminimum.rs +27 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fminimum_num.rs +29 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmod.rs +116 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/rint.rs +130 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/sqrt.rs +541 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/trunc.rs +148 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j0.rs +426 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j0f.rs +363 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j1.rs +418 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j1f.rs +383 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/jn.rs +339 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/jnf.rs +253 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_cos.rs +62 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_cosf.rs +29 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_sin.rs +57 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_sinf.rs +30 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_tan.rs +105 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_tanf.rs +46 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/lgamma_r.rs +321 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/lgammaf_r.rs +256 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log.rs +118 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log10.rs +116 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log10f.rs +90 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log1p.rs +142 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log1pf.rs +97 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log2.rs +105 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log2f.rs +86 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/logf.rs +66 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/pow.rs +624 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/powf.rs +343 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/rem_pio2.rs +235 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/rem_pio2_large.rs +476 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/rem_pio2f.rs +65 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sin.rs +95 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sincos.rs +137 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sincosf.rs +176 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sinf.rs +96 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/support/int_traits/narrowing_div.rs +175 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/support/modular.rs +304 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/tan.rs +74 -0
- package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/tanf.rs +81 -0
- package/licenses/registry/num-traits-0.2.19-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/num-traits-0.2.19-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/num-traits-0.2.19-c19b7c6f923b/src/lib.rs +635 -0
- package/licenses/registry/once_cell-1.21.4-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/once_cell-1.21.4-c19b7c6f923b/LICENSE-MIT +23 -0
- package/licenses/registry/proc-macro2-1.0.107-c19b7c6f923b/LICENSE-APACHE +176 -0
- package/licenses/registry/proc-macro2-1.0.107-c19b7c6f923b/LICENSE-MIT +23 -0
- package/licenses/registry/quote-1.0.47-c19b7c6f923b/LICENSE-APACHE +176 -0
- package/licenses/registry/quote-1.0.47-c19b7c6f923b/LICENSE-MIT +23 -0
- package/licenses/registry/robust-1.2.0-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/robust-1.2.0-c19b7c6f923b/LICENSE-MIT +26 -0
- package/licenses/registry/robust-1.2.0-c19b7c6f923b/src/lib.rs +2224 -0
- package/licenses/registry/rustversion-1.0.23-c19b7c6f923b/LICENSE-APACHE +176 -0
- package/licenses/registry/rustversion-1.0.23-c19b7c6f923b/LICENSE-MIT +23 -0
- package/licenses/registry/smallvec-1.16.6-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/smallvec-1.16.6-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/spade-2.15.1-c19b7c6f923b/LICENSE-APACHE +202 -0
- package/licenses/registry/spade-2.15.1-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/syn-2.0.119-c19b7c6f923b/LICENSE-APACHE +176 -0
- package/licenses/registry/syn-2.0.119-c19b7c6f923b/LICENSE-MIT +23 -0
- package/licenses/registry/unicode-ident-1.0.27-c19b7c6f923b/LICENSE-APACHE +176 -0
- package/licenses/registry/unicode-ident-1.0.27-c19b7c6f923b/LICENSE-MIT +23 -0
- package/licenses/registry/unicode-ident-1.0.27-c19b7c6f923b/LICENSE-UNICODE +39 -0
- package/licenses/registry/wasm-bindgen-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/wasm-bindgen-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/wasm-bindgen-macro-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/wasm-bindgen-macro-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/wasm-bindgen-macro-support-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/wasm-bindgen-macro-support-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry/wasm-bindgen-shared-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
- package/licenses/registry/wasm-bindgen-shared-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
- package/licenses/registry-licenses.json +1413 -0
- package/licenses/source/LICENSE-APACHE +176 -0
- package/licenses/source/LICENSE-MIT +21 -0
- package/licenses/source/crates/rcmg-mesh/src/isosurface/LICENSE-PyMCubes +27 -0
- package/licenses/source/crates/rcmg-mesh/src/isosurface/NOTICE.md +11 -0
- package/licenses/source/vendor/cadcraft-dxf/LICENSE-APACHE +177 -0
- package/licenses/source/vendor/cadcraft-dxf/LICENSE-MIT +21 -0
- package/node/index.mjs +2 -0
- package/node/package.json +3 -0
- package/node/rcmg_ffi.d.ts +51 -0
- package/node/rcmg_ffi.js +269 -0
- package/node/rcmg_ffi_bg.wasm +0 -0
- package/node/rcmg_ffi_bg.wasm.d.ts +32 -0
- package/package.json +57 -6
- package/web/rcmg_ffi.d.ts +108 -0
- package/web/rcmg_ffi.js +358 -0
- package/web/rcmg_ffi_bg.wasm +0 -0
- package/web/rcmg_ffi_bg.wasm.d.ts +32 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/* origin: core-math/src/binary64/cbrt/cbrt.c
|
|
3
|
+
* Copyright (c) 2021-2022 Alexei Sibidanov.
|
|
4
|
+
* Ported to Rust in 2025 by Trevor Gross.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
use super::Float;
|
|
8
|
+
use super::support::{FpResult, Round, cold_path};
|
|
9
|
+
|
|
10
|
+
/// Compute the cube root of the argument.
|
|
11
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
12
|
+
pub fn cbrt(x: f64) -> f64 {
|
|
13
|
+
cbrt_round(x, Round::Nearest).val
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
pub fn cbrt_round(x: f64, round: Round) -> FpResult<f64> {
|
|
17
|
+
const ESCALE: [f64; 3] = [
|
|
18
|
+
1.0,
|
|
19
|
+
hf64!("0x1.428a2f98d728bp+0"), /* 2^(1/3) */
|
|
20
|
+
hf64!("0x1.965fea53d6e3dp+0"), /* 2^(2/3) */
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/* the polynomial c0+c1*x+c2*x^2+c3*x^3 approximates x^(1/3) on [1,2]
|
|
24
|
+
with maximal error < 9.2e-5 (attained at x=2) */
|
|
25
|
+
const C: [f64; 4] = [
|
|
26
|
+
hf64!("0x1.1b0babccfef9cp-1"),
|
|
27
|
+
hf64!("0x1.2c9a3e94d1da5p-1"),
|
|
28
|
+
hf64!("-0x1.4dc30b1a1ddbap-3"),
|
|
29
|
+
hf64!("0x1.7a8d3e4ec9b07p-6"),
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
let u0: f64 = hf64!("0x1.5555555555555p-2");
|
|
33
|
+
let u1: f64 = hf64!("0x1.c71c71c71c71cp-3");
|
|
34
|
+
|
|
35
|
+
let rsc = [1.0, -1.0, 0.5, -0.5, 0.25, -0.25];
|
|
36
|
+
|
|
37
|
+
let off = [hf64!("0x1p-53"), 0.0, 0.0, 0.0];
|
|
38
|
+
|
|
39
|
+
/* rm=0 for rounding to nearest, and other values for directed roundings */
|
|
40
|
+
let hx: u64 = x.to_bits();
|
|
41
|
+
let mut mant: u64 = hx & f64::SIG_MASK;
|
|
42
|
+
let sign: u64 = hx >> 63;
|
|
43
|
+
|
|
44
|
+
let mut e: u32 = (hx >> f64::SIG_BITS) as u32 & f64::EXP_SAT;
|
|
45
|
+
|
|
46
|
+
if ((e + 1) & f64::EXP_SAT) < 2 {
|
|
47
|
+
cold_path();
|
|
48
|
+
|
|
49
|
+
let ix: u64 = hx & !f64::SIGN_MASK;
|
|
50
|
+
|
|
51
|
+
/* 0, inf, nan: we return x + x instead of simply x,
|
|
52
|
+
to that for x a signaling NaN, it correctly triggers
|
|
53
|
+
the invalid exception. */
|
|
54
|
+
if e == f64::EXP_SAT || ix == 0 {
|
|
55
|
+
return FpResult::ok(x + x);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let nz = ix.leading_zeros() - 11; /* subnormal */
|
|
59
|
+
mant <<= nz;
|
|
60
|
+
mant &= f64::SIG_MASK;
|
|
61
|
+
e = e.wrapping_sub(nz - 1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
e = e.wrapping_add(3072);
|
|
65
|
+
let cvt1: u64 = mant | (0x3ffu64 << 52);
|
|
66
|
+
let mut cvt5: u64 = cvt1;
|
|
67
|
+
|
|
68
|
+
let et: u32 = e / 3;
|
|
69
|
+
let it: u32 = e % 3;
|
|
70
|
+
|
|
71
|
+
/* 2^(3k+it) <= x < 2^(3k+it+1), with 0 <= it <= 3 */
|
|
72
|
+
cvt5 += u64::from(it) << f64::SIG_BITS;
|
|
73
|
+
cvt5 |= sign << 63;
|
|
74
|
+
let zz: f64 = f64::from_bits(cvt5);
|
|
75
|
+
|
|
76
|
+
/* cbrt(x) = cbrt(zz)*2^(et-1365) where 1 <= zz < 8 */
|
|
77
|
+
let mut isc: u64 = ESCALE[it as usize].to_bits(); // todo: index
|
|
78
|
+
isc |= sign << 63;
|
|
79
|
+
let cvt2: u64 = isc;
|
|
80
|
+
let z: f64 = f64::from_bits(cvt1);
|
|
81
|
+
|
|
82
|
+
/* cbrt(zz) = cbrt(z)*isc, where isc encodes 1, 2^(1/3) or 2^(2/3),
|
|
83
|
+
and 1 <= z < 2 */
|
|
84
|
+
let r: f64 = 1.0 / z;
|
|
85
|
+
let rr: f64 = r * rsc[((it as usize) << 1) | sign as usize];
|
|
86
|
+
let z2: f64 = z * z;
|
|
87
|
+
let c0: f64 = C[0] + z * C[1];
|
|
88
|
+
let c2: f64 = C[2] + z * C[3];
|
|
89
|
+
let mut y: f64 = c0 + z2 * c2;
|
|
90
|
+
let mut y2: f64 = y * y;
|
|
91
|
+
|
|
92
|
+
/* y is an approximation of z^(1/3) */
|
|
93
|
+
let mut h: f64 = y2 * (y * r) - 1.0;
|
|
94
|
+
|
|
95
|
+
/* h determines the error between y and z^(1/3) */
|
|
96
|
+
y -= (h * y) * (u0 - u1 * h);
|
|
97
|
+
|
|
98
|
+
/* The correction y -= (h*y)*(u0 - u1*h) corresponds to a cubic variant
|
|
99
|
+
of Newton's method, with the function f(y) = 1-z/y^3. */
|
|
100
|
+
y *= f64::from_bits(cvt2);
|
|
101
|
+
|
|
102
|
+
/* Now y is an approximation of zz^(1/3),
|
|
103
|
+
* and rr an approximation of 1/zz. We now perform another iteration of
|
|
104
|
+
* Newton-Raphson, this time with a linear approximation only. */
|
|
105
|
+
y2 = y * y;
|
|
106
|
+
let mut y2l: f64 = y.fma(y, -y2);
|
|
107
|
+
|
|
108
|
+
/* y2 + y2l = y^2 exactly */
|
|
109
|
+
let mut y3: f64 = y2 * y;
|
|
110
|
+
let mut y3l: f64 = y.fma(y2, -y3) + y * y2l;
|
|
111
|
+
|
|
112
|
+
/* y3 + y3l approximates y^3 with about 106 bits of accuracy */
|
|
113
|
+
h = ((y3 - zz) + y3l) * rr;
|
|
114
|
+
let mut dy: f64 = h * (y * u0);
|
|
115
|
+
|
|
116
|
+
/* the approximation of zz^(1/3) is y - dy */
|
|
117
|
+
let mut y1: f64 = y - dy;
|
|
118
|
+
dy = (y - y1) - dy;
|
|
119
|
+
|
|
120
|
+
/* the approximation of zz^(1/3) is now y1 + dy, where |dy| < 1/2 ulp(y)
|
|
121
|
+
* (for rounding to nearest) */
|
|
122
|
+
let mut ady: f64 = dy.abs();
|
|
123
|
+
|
|
124
|
+
/* For directed roundings, ady0 is tiny when dy is tiny, or ady0 is near
|
|
125
|
+
* from ulp(1);
|
|
126
|
+
* for rounding to nearest, ady0 is tiny when dy is near from 1/2 ulp(1),
|
|
127
|
+
* or from 3/2 ulp(1). */
|
|
128
|
+
let mut ady0: f64 = (ady - off[round as usize]).abs();
|
|
129
|
+
let mut ady1: f64 = (ady - (hf64!("0x1p-52") + off[round as usize])).abs();
|
|
130
|
+
|
|
131
|
+
if ady0 < hf64!("0x1p-75") || ady1 < hf64!("0x1p-75") {
|
|
132
|
+
cold_path();
|
|
133
|
+
|
|
134
|
+
y2 = y1 * y1;
|
|
135
|
+
y2l = y1.fma(y1, -y2);
|
|
136
|
+
y3 = y2 * y1;
|
|
137
|
+
y3l = y1.fma(y2, -y3) + y1 * y2l;
|
|
138
|
+
h = ((y3 - zz) + y3l) * rr;
|
|
139
|
+
dy = h * (y1 * u0);
|
|
140
|
+
y = y1 - dy;
|
|
141
|
+
dy = (y1 - y) - dy;
|
|
142
|
+
y1 = y;
|
|
143
|
+
ady = dy.abs();
|
|
144
|
+
ady0 = (ady - off[round as usize]).abs();
|
|
145
|
+
ady1 = (ady - (hf64!("0x1p-52") + off[round as usize])).abs();
|
|
146
|
+
|
|
147
|
+
if ady0 < hf64!("0x1p-98") || ady1 < hf64!("0x1p-98") {
|
|
148
|
+
cold_path();
|
|
149
|
+
let azz: f64 = zz.abs();
|
|
150
|
+
|
|
151
|
+
// ~ 0x1.79d15d0e8d59b80000000000000ffc3dp+0
|
|
152
|
+
if azz == hf64!("0x1.9b78223aa307cp+1") {
|
|
153
|
+
y1 = hf64!("0x1.79d15d0e8d59cp+0").copysign(zz);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ~ 0x1.de87aa837820e80000000000001c0f08p+0
|
|
157
|
+
if azz == hf64!("0x1.a202bfc89ddffp+2") {
|
|
158
|
+
y1 = hf64!("0x1.de87aa837820fp+0").copysign(zz);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if round != Round::Nearest {
|
|
162
|
+
let wlist = [
|
|
163
|
+
(hf64!("0x1.3a9ccd7f022dbp+0"), hf64!("0x1.1236160ba9b93p+0")), // ~ 0x1.1236160ba9b930000000000001e7e8fap+0
|
|
164
|
+
(hf64!("0x1.7845d2faac6fep+0"), hf64!("0x1.23115e657e49cp+0")), // ~ 0x1.23115e657e49c0000000000001d7a799p+0
|
|
165
|
+
(hf64!("0x1.d1ef81cbbbe71p+0"), hf64!("0x1.388fb44cdcf5ap+0")), // ~ 0x1.388fb44cdcf5a0000000000002202c55p+0
|
|
166
|
+
(hf64!("0x1.0a2014f62987cp+1"), hf64!("0x1.46bcbf47dc1e8p+0")), // ~ 0x1.46bcbf47dc1e8000000000000303aa2dp+0
|
|
167
|
+
(hf64!("0x1.fe18a044a5501p+1"), hf64!("0x1.95decfec9c904p+0")), // ~ 0x1.95decfec9c9040000000000000159e8ep+0
|
|
168
|
+
(hf64!("0x1.a6bb8c803147bp+2"), hf64!("0x1.e05335a6401dep+0")), // ~ 0x1.e05335a6401de00000000000027ca017p+0
|
|
169
|
+
(hf64!("0x1.ac8538a031cbdp+2"), hf64!("0x1.e281d87098de8p+0")), // ~ 0x1.e281d87098de80000000000000ee9314p+0
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
for (a, b) in wlist {
|
|
173
|
+
if azz == a {
|
|
174
|
+
let tmp = if round as u64 + sign == 2 {
|
|
175
|
+
hf64!("0x1p-52")
|
|
176
|
+
} else {
|
|
177
|
+
0.0
|
|
178
|
+
};
|
|
179
|
+
y1 = (b + tmp).copysign(zz);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let mut cvt3: u64 = y1.to_bits();
|
|
187
|
+
cvt3 = cvt3.wrapping_add(((et.wrapping_sub(342).wrapping_sub(1023)) as u64) << 52);
|
|
188
|
+
let m0: u64 = cvt3 << 30;
|
|
189
|
+
let m1 = m0 >> 63;
|
|
190
|
+
|
|
191
|
+
if (m0 ^ m1) <= (1u64 << 30) {
|
|
192
|
+
cold_path();
|
|
193
|
+
|
|
194
|
+
let mut cvt4: u64 = y1.to_bits();
|
|
195
|
+
cvt4 = (cvt4 + (164 << 15)) & 0xffffffffffff0000u64;
|
|
196
|
+
|
|
197
|
+
if ((f64::from_bits(cvt4) - y1) - dy).abs() < hf64!("0x1p-60") || (zz).abs() == 1.0 {
|
|
198
|
+
cvt3 = (cvt3 + (1u64 << 15)) & 0xffffffffffff0000u64;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
FpResult::ok(f64::from_bits(cvt3))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
#[cfg(test)]
|
|
206
|
+
mod tests {
|
|
207
|
+
use super::*;
|
|
208
|
+
|
|
209
|
+
#[test]
|
|
210
|
+
fn spot_checks() {
|
|
211
|
+
if !cfg!(x86_no_sse) {
|
|
212
|
+
// Exposes a rounding mode problem. Ignored on i586 because of inaccurate FMA.
|
|
213
|
+
assert_biteq!(
|
|
214
|
+
cbrt(f64::from_bits(0xf7f792b28f600000)),
|
|
215
|
+
f64::from_bits(0xd29ce68655d962f3)
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtf.c */
|
|
2
|
+
/*
|
|
3
|
+
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
4
|
+
* Debugged and optimized by Bruce D. Evans.
|
|
5
|
+
*/
|
|
6
|
+
/*
|
|
7
|
+
* ====================================================
|
|
8
|
+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
9
|
+
*
|
|
10
|
+
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
11
|
+
* Permission to use, copy, modify, and distribute this
|
|
12
|
+
* software is freely granted, provided that this notice
|
|
13
|
+
* is preserved.
|
|
14
|
+
* ====================================================
|
|
15
|
+
*/
|
|
16
|
+
/* cbrtf(x)
|
|
17
|
+
* Return cube root of x
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const B1: u32 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */
|
|
21
|
+
const B2: u32 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
|
|
22
|
+
|
|
23
|
+
/// Cube root (f32)
|
|
24
|
+
///
|
|
25
|
+
/// Computes the cube root of the argument.
|
|
26
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
27
|
+
pub fn cbrtf(x: f32) -> f32 {
|
|
28
|
+
let x1p24 = f32::from_bits(0x4b800000); // 0x1p24f === 2 ^ 24
|
|
29
|
+
|
|
30
|
+
let mut r: f64;
|
|
31
|
+
let mut t: f64;
|
|
32
|
+
let mut ui: u32 = x.to_bits();
|
|
33
|
+
let mut hx: u32 = ui & 0x7fffffff;
|
|
34
|
+
|
|
35
|
+
if hx >= 0x7f800000 {
|
|
36
|
+
/* cbrt(NaN,INF) is itself */
|
|
37
|
+
return x + x;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* rough cbrt to 5 bits */
|
|
41
|
+
if hx < 0x00800000 {
|
|
42
|
+
/* zero or subnormal? */
|
|
43
|
+
if hx == 0 {
|
|
44
|
+
return x; /* cbrt(+-0) is itself */
|
|
45
|
+
}
|
|
46
|
+
ui = (x * x1p24).to_bits();
|
|
47
|
+
hx = ui & 0x7fffffff;
|
|
48
|
+
hx = hx / 3 + B2;
|
|
49
|
+
} else {
|
|
50
|
+
hx = hx / 3 + B1;
|
|
51
|
+
}
|
|
52
|
+
ui &= 0x80000000;
|
|
53
|
+
ui |= hx;
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In
|
|
57
|
+
* double precision so that its terms can be arranged for efficiency
|
|
58
|
+
* without causing overflow or underflow.
|
|
59
|
+
*/
|
|
60
|
+
t = f32::from_bits(ui) as f64;
|
|
61
|
+
r = t * t * t;
|
|
62
|
+
t = t * (x as f64 + x as f64 + r) / (x as f64 + r + r);
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* Second step Newton iteration to 47 bits. In double precision for
|
|
66
|
+
* efficiency and accuracy.
|
|
67
|
+
*/
|
|
68
|
+
r = t * t * t;
|
|
69
|
+
t = t * (x as f64 + x as f64 + r) / (x as f64 + r + r);
|
|
70
|
+
|
|
71
|
+
/* rounding to 24 bits is perfect in round-to-nearest mode */
|
|
72
|
+
t as f32
|
|
73
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// origin: FreeBSD /usr/src/lib/msun/src/s_cos.c */
|
|
2
|
+
//
|
|
3
|
+
// ====================================================
|
|
4
|
+
// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
7
|
+
// Permission to use, copy, modify, and distribute this
|
|
8
|
+
// software is freely granted, provided that this notice
|
|
9
|
+
// is preserved.
|
|
10
|
+
// ====================================================
|
|
11
|
+
|
|
12
|
+
use super::{k_cos, k_sin, rem_pio2};
|
|
13
|
+
|
|
14
|
+
// cos(x)
|
|
15
|
+
// Return cosine function of x.
|
|
16
|
+
//
|
|
17
|
+
// kernel function:
|
|
18
|
+
// k_sin ... sine function on [-pi/4,pi/4]
|
|
19
|
+
// k_cos ... cosine function on [-pi/4,pi/4]
|
|
20
|
+
// rem_pio2 ... argument reduction routine
|
|
21
|
+
//
|
|
22
|
+
// Method.
|
|
23
|
+
// Let S,C and T denote the sin, cos and tan respectively on
|
|
24
|
+
// [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
|
|
25
|
+
// in [-pi/4 , +pi/4], and let n = k mod 4.
|
|
26
|
+
// We have
|
|
27
|
+
//
|
|
28
|
+
// n sin(x) cos(x) tan(x)
|
|
29
|
+
// ----------------------------------------------------------
|
|
30
|
+
// 0 S C T
|
|
31
|
+
// 1 C -S -1/T
|
|
32
|
+
// 2 -S -C T
|
|
33
|
+
// 3 -C S -1/T
|
|
34
|
+
// ----------------------------------------------------------
|
|
35
|
+
//
|
|
36
|
+
// Special cases:
|
|
37
|
+
// Let trig be any of sin, cos, or tan.
|
|
38
|
+
// trig(+-INF) is NaN, with signals;
|
|
39
|
+
// trig(NaN) is that NaN;
|
|
40
|
+
//
|
|
41
|
+
// Accuracy:
|
|
42
|
+
// TRIG(x) returns trig(x) nearly rounded
|
|
43
|
+
//
|
|
44
|
+
|
|
45
|
+
/// The cosine of `x` (f64).
|
|
46
|
+
///
|
|
47
|
+
/// `x` is specified in radians.
|
|
48
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
49
|
+
pub fn cos(x: f64) -> f64 {
|
|
50
|
+
let ix = (f64::to_bits(x) >> 32) as u32 & 0x7fffffff;
|
|
51
|
+
|
|
52
|
+
/* |x| ~< pi/4 */
|
|
53
|
+
if ix <= 0x3fe921fb {
|
|
54
|
+
if ix < 0x3e46a09e {
|
|
55
|
+
/* if x < 2**-27 * sqrt(2) */
|
|
56
|
+
/* raise inexact if x != 0 */
|
|
57
|
+
if x as i32 == 0 {
|
|
58
|
+
return 1.0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return k_cos(x, 0.0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* cos(Inf or NaN) is NaN */
|
|
65
|
+
if ix >= 0x7ff00000 {
|
|
66
|
+
return x - x;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* argument reduction needed */
|
|
70
|
+
let (n, y0, y1) = rem_pio2(x);
|
|
71
|
+
match n & 3 {
|
|
72
|
+
0 => k_cos(y0, y1),
|
|
73
|
+
1 => -k_sin(y0, y1, 1),
|
|
74
|
+
2 => -k_cos(y0, y1),
|
|
75
|
+
_ => k_sin(y0, y1, 1),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/s_cosf.c */
|
|
2
|
+
/*
|
|
3
|
+
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
4
|
+
* Optimized by Bruce D. Evans.
|
|
5
|
+
*/
|
|
6
|
+
/*
|
|
7
|
+
* ====================================================
|
|
8
|
+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
9
|
+
*
|
|
10
|
+
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
11
|
+
* Permission to use, copy, modify, and distribute this
|
|
12
|
+
* software is freely granted, provided that this notice
|
|
13
|
+
* is preserved.
|
|
14
|
+
* ====================================================
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
use core::f64::consts::FRAC_PI_2;
|
|
18
|
+
|
|
19
|
+
use super::{k_cosf, k_sinf, rem_pio2f};
|
|
20
|
+
|
|
21
|
+
/* Small multiples of pi/2 rounded to double precision. */
|
|
22
|
+
const C1_PIO2: f64 = 1. * FRAC_PI_2; /* 0x3FF921FB, 0x54442D18 */
|
|
23
|
+
const C2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */
|
|
24
|
+
const C3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */
|
|
25
|
+
const C4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */
|
|
26
|
+
|
|
27
|
+
/// The cosine of `x` (f32).
|
|
28
|
+
///
|
|
29
|
+
/// `x` is specified in radians.
|
|
30
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
31
|
+
pub fn cosf(x: f32) -> f32 {
|
|
32
|
+
let x64 = x as f64;
|
|
33
|
+
|
|
34
|
+
let x1p120 = f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120
|
|
35
|
+
|
|
36
|
+
let mut ix = x.to_bits();
|
|
37
|
+
let sign = (ix >> 31) != 0;
|
|
38
|
+
ix &= 0x7fffffff;
|
|
39
|
+
|
|
40
|
+
if ix <= 0x3f490fda {
|
|
41
|
+
/* |x| ~<= pi/4 */
|
|
42
|
+
if ix < 0x39800000 {
|
|
43
|
+
/* |x| < 2**-12 */
|
|
44
|
+
/* raise inexact if x != 0 */
|
|
45
|
+
force_eval!(x + x1p120);
|
|
46
|
+
return 1.;
|
|
47
|
+
}
|
|
48
|
+
return k_cosf(x64);
|
|
49
|
+
}
|
|
50
|
+
if ix <= 0x407b53d1 {
|
|
51
|
+
/* |x| ~<= 5*pi/4 */
|
|
52
|
+
if ix > 0x4016cbe3 {
|
|
53
|
+
/* |x| ~> 3*pi/4 */
|
|
54
|
+
return -k_cosf(if sign { x64 + C2_PIO2 } else { x64 - C2_PIO2 });
|
|
55
|
+
} else if sign {
|
|
56
|
+
return k_sinf(x64 + C1_PIO2);
|
|
57
|
+
} else {
|
|
58
|
+
return k_sinf(C1_PIO2 - x64);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if ix <= 0x40e231d5 {
|
|
62
|
+
/* |x| ~<= 9*pi/4 */
|
|
63
|
+
if ix > 0x40afeddf {
|
|
64
|
+
/* |x| ~> 7*pi/4 */
|
|
65
|
+
return k_cosf(if sign { x64 + C4_PIO2 } else { x64 - C4_PIO2 });
|
|
66
|
+
} else if sign {
|
|
67
|
+
return k_sinf(-x64 - C3_PIO2);
|
|
68
|
+
} else {
|
|
69
|
+
return k_sinf(x64 - C3_PIO2);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* cos(Inf or NaN) is NaN */
|
|
74
|
+
if ix >= 0x7f800000 {
|
|
75
|
+
return x - x;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* general argument reduction needed */
|
|
79
|
+
let (n, y) = rem_pio2f(x);
|
|
80
|
+
match n & 3 {
|
|
81
|
+
0 => k_cosf(y),
|
|
82
|
+
1 => k_sinf(-y),
|
|
83
|
+
2 => -k_cosf(y),
|
|
84
|
+
_ => k_sinf(y),
|
|
85
|
+
}
|
|
86
|
+
}
|