@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,253 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/e_jnf.c */
|
|
2
|
+
/*
|
|
3
|
+
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
4
|
+
*/
|
|
5
|
+
/*
|
|
6
|
+
* ====================================================
|
|
7
|
+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
8
|
+
*
|
|
9
|
+
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
10
|
+
* Permission to use, copy, modify, and distribute this
|
|
11
|
+
* software is freely granted, provided that this notice
|
|
12
|
+
* is preserved.
|
|
13
|
+
* ====================================================
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
use super::{fabsf, j0f, j1f, logf, y0f, y1f};
|
|
17
|
+
|
|
18
|
+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f32).
|
|
19
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
20
|
+
pub fn jnf(n: i32, mut x: f32) -> f32 {
|
|
21
|
+
let mut ix: u32;
|
|
22
|
+
let mut nm1: i32;
|
|
23
|
+
let mut sign: bool;
|
|
24
|
+
let mut i: i32;
|
|
25
|
+
let mut a: f32;
|
|
26
|
+
let mut b: f32;
|
|
27
|
+
let mut temp: f32;
|
|
28
|
+
|
|
29
|
+
ix = x.to_bits();
|
|
30
|
+
sign = (ix >> 31) != 0;
|
|
31
|
+
ix &= 0x7fffffff;
|
|
32
|
+
if ix > 0x7f800000 {
|
|
33
|
+
/* nan */
|
|
34
|
+
return x;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* J(-n,x) = J(n,-x), use |n|-1 to avoid overflow in -n */
|
|
38
|
+
if n == 0 {
|
|
39
|
+
return j0f(x);
|
|
40
|
+
}
|
|
41
|
+
if n < 0 {
|
|
42
|
+
nm1 = -(n + 1);
|
|
43
|
+
x = -x;
|
|
44
|
+
sign = !sign;
|
|
45
|
+
} else {
|
|
46
|
+
nm1 = n - 1;
|
|
47
|
+
}
|
|
48
|
+
if nm1 == 0 {
|
|
49
|
+
return j1f(x);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
sign &= (n & 1) != 0; /* even n: 0, odd n: signbit(x) */
|
|
53
|
+
x = fabsf(x);
|
|
54
|
+
if ix == 0 || ix == 0x7f800000 {
|
|
55
|
+
/* if x is 0 or inf */
|
|
56
|
+
b = 0.0;
|
|
57
|
+
} else if (nm1 as f32) < x {
|
|
58
|
+
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
|
|
59
|
+
a = j0f(x);
|
|
60
|
+
b = j1f(x);
|
|
61
|
+
i = 0;
|
|
62
|
+
while i < nm1 {
|
|
63
|
+
i += 1;
|
|
64
|
+
temp = b;
|
|
65
|
+
b = b * (2.0 * (i as f32) / x) - a;
|
|
66
|
+
a = temp;
|
|
67
|
+
}
|
|
68
|
+
} else if ix < 0x35800000 {
|
|
69
|
+
/* x < 2**-20 */
|
|
70
|
+
/* x is tiny, return the first Taylor expansion of J(n,x)
|
|
71
|
+
* J(n,x) = 1/n!*(x/2)^n - ...
|
|
72
|
+
*/
|
|
73
|
+
if nm1 > 8 {
|
|
74
|
+
/* underflow */
|
|
75
|
+
nm1 = 8;
|
|
76
|
+
}
|
|
77
|
+
temp = 0.5 * x;
|
|
78
|
+
b = temp;
|
|
79
|
+
a = 1.0;
|
|
80
|
+
i = 2;
|
|
81
|
+
while i <= nm1 + 1 {
|
|
82
|
+
a *= i as f32; /* a = n! */
|
|
83
|
+
b *= temp; /* b = (x/2)^n */
|
|
84
|
+
i += 1;
|
|
85
|
+
}
|
|
86
|
+
b = b / a;
|
|
87
|
+
} else {
|
|
88
|
+
/* use backward recurrence */
|
|
89
|
+
/* x x^2 x^2
|
|
90
|
+
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
|
|
91
|
+
* 2n - 2(n+1) - 2(n+2)
|
|
92
|
+
*
|
|
93
|
+
* 1 1 1
|
|
94
|
+
* (for large x) = ---- ------ ------ .....
|
|
95
|
+
* 2n 2(n+1) 2(n+2)
|
|
96
|
+
* -- - ------ - ------ -
|
|
97
|
+
* x x x
|
|
98
|
+
*
|
|
99
|
+
* Let w = 2n/x and h=2/x, then the above quotient
|
|
100
|
+
* is equal to the continued fraction:
|
|
101
|
+
* 1
|
|
102
|
+
* = -----------------------
|
|
103
|
+
* 1
|
|
104
|
+
* w - -----------------
|
|
105
|
+
* 1
|
|
106
|
+
* w+h - ---------
|
|
107
|
+
* w+2h - ...
|
|
108
|
+
*
|
|
109
|
+
* To determine how many terms needed, let
|
|
110
|
+
* Q(0) = w, Q(1) = w(w+h) - 1,
|
|
111
|
+
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
|
|
112
|
+
* When Q(k) > 1e4 good for single
|
|
113
|
+
* When Q(k) > 1e9 good for double
|
|
114
|
+
* When Q(k) > 1e17 good for quadruple
|
|
115
|
+
*/
|
|
116
|
+
/* determine k */
|
|
117
|
+
let mut t: f32;
|
|
118
|
+
let mut q0: f32;
|
|
119
|
+
let mut q1: f32;
|
|
120
|
+
let mut w: f32;
|
|
121
|
+
let h: f32;
|
|
122
|
+
let mut z: f32;
|
|
123
|
+
let mut tmp: f32;
|
|
124
|
+
let nf: f32;
|
|
125
|
+
let mut k: i32;
|
|
126
|
+
|
|
127
|
+
nf = (nm1 as f32) + 1.0;
|
|
128
|
+
w = 2.0 * nf / x;
|
|
129
|
+
h = 2.0 / x;
|
|
130
|
+
z = w + h;
|
|
131
|
+
q0 = w;
|
|
132
|
+
q1 = w * z - 1.0;
|
|
133
|
+
k = 1;
|
|
134
|
+
while q1 < 1.0e4 {
|
|
135
|
+
k += 1;
|
|
136
|
+
z += h;
|
|
137
|
+
tmp = z * q1 - q0;
|
|
138
|
+
q0 = q1;
|
|
139
|
+
q1 = tmp;
|
|
140
|
+
}
|
|
141
|
+
t = 0.0;
|
|
142
|
+
i = k;
|
|
143
|
+
while i >= 0 {
|
|
144
|
+
t = 1.0 / (2.0 * ((i as f32) + nf) / x - t);
|
|
145
|
+
i -= 1;
|
|
146
|
+
}
|
|
147
|
+
a = t;
|
|
148
|
+
b = 1.0;
|
|
149
|
+
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
|
|
150
|
+
* Hence, if n*(log(2n/x)) > ...
|
|
151
|
+
* single 8.8722839355e+01
|
|
152
|
+
* double 7.09782712893383973096e+02
|
|
153
|
+
* long double 1.1356523406294143949491931077970765006170e+04
|
|
154
|
+
* then recurrent value may overflow and the result is
|
|
155
|
+
* likely underflow to zero
|
|
156
|
+
*/
|
|
157
|
+
tmp = nf * logf(fabsf(w));
|
|
158
|
+
if tmp < 88.721679688 {
|
|
159
|
+
i = nm1;
|
|
160
|
+
while i > 0 {
|
|
161
|
+
temp = b;
|
|
162
|
+
b = 2.0 * (i as f32) * b / x - a;
|
|
163
|
+
a = temp;
|
|
164
|
+
i -= 1;
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
i = nm1;
|
|
168
|
+
while i > 0 {
|
|
169
|
+
temp = b;
|
|
170
|
+
b = 2.0 * (i as f32) * b / x - a;
|
|
171
|
+
a = temp;
|
|
172
|
+
/* scale b to avoid spurious overflow */
|
|
173
|
+
let x1p60 = f32::from_bits(0x5d800000); // 0x1p60 == 2^60
|
|
174
|
+
if b > x1p60 {
|
|
175
|
+
a /= b;
|
|
176
|
+
t /= b;
|
|
177
|
+
b = 1.0;
|
|
178
|
+
}
|
|
179
|
+
i -= 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
z = j0f(x);
|
|
183
|
+
w = j1f(x);
|
|
184
|
+
if fabsf(z) >= fabsf(w) {
|
|
185
|
+
b = t * z / b;
|
|
186
|
+
} else {
|
|
187
|
+
b = t * w / a;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if sign { -b } else { b }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f32).
|
|
195
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
196
|
+
pub fn ynf(n: i32, x: f32) -> f32 {
|
|
197
|
+
let mut ix: u32;
|
|
198
|
+
let mut ib: u32;
|
|
199
|
+
let nm1: i32;
|
|
200
|
+
let mut sign: bool;
|
|
201
|
+
let mut i: i32;
|
|
202
|
+
let mut a: f32;
|
|
203
|
+
let mut b: f32;
|
|
204
|
+
let mut temp: f32;
|
|
205
|
+
|
|
206
|
+
ix = x.to_bits();
|
|
207
|
+
sign = (ix >> 31) != 0;
|
|
208
|
+
ix &= 0x7fffffff;
|
|
209
|
+
if ix > 0x7f800000 {
|
|
210
|
+
/* nan */
|
|
211
|
+
return x;
|
|
212
|
+
}
|
|
213
|
+
if sign && ix != 0 {
|
|
214
|
+
/* x < 0 */
|
|
215
|
+
return 0.0 / 0.0;
|
|
216
|
+
}
|
|
217
|
+
if ix == 0x7f800000 {
|
|
218
|
+
return 0.0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if n == 0 {
|
|
222
|
+
return y0f(x);
|
|
223
|
+
}
|
|
224
|
+
if n < 0 {
|
|
225
|
+
nm1 = -(n + 1);
|
|
226
|
+
sign = (n & 1) != 0;
|
|
227
|
+
} else {
|
|
228
|
+
nm1 = n - 1;
|
|
229
|
+
sign = false;
|
|
230
|
+
}
|
|
231
|
+
if nm1 == 0 {
|
|
232
|
+
if sign {
|
|
233
|
+
return -y1f(x);
|
|
234
|
+
} else {
|
|
235
|
+
return y1f(x);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
a = y0f(x);
|
|
240
|
+
b = y1f(x);
|
|
241
|
+
/* quit if b is -inf */
|
|
242
|
+
ib = b.to_bits();
|
|
243
|
+
i = 0;
|
|
244
|
+
while i < nm1 && ib != 0xff800000 {
|
|
245
|
+
i += 1;
|
|
246
|
+
temp = b;
|
|
247
|
+
b = (2.0 * (i as f32) / x) * b - a;
|
|
248
|
+
ib = b.to_bits();
|
|
249
|
+
a = temp;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if sign { -b } else { b }
|
|
253
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// origin: FreeBSD /usr/src/lib/msun/src/k_cos.c
|
|
2
|
+
//
|
|
3
|
+
// ====================================================
|
|
4
|
+
// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Developed at SunSoft, 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
|
+
const C1: f64 = 4.16666666666666019037e-02; /* 0x3FA55555, 0x5555554C */
|
|
13
|
+
const C2: f64 = -1.38888888888741095749e-03; /* 0xBF56C16C, 0x16C15177 */
|
|
14
|
+
const C3: f64 = 2.48015872894767294178e-05; /* 0x3EFA01A0, 0x19CB1590 */
|
|
15
|
+
const C4: f64 = -2.75573143513906633035e-07; /* 0xBE927E4F, 0x809C52AD */
|
|
16
|
+
const C5: f64 = 2.08757232129817482790e-09; /* 0x3E21EE9E, 0xBDB4B1C4 */
|
|
17
|
+
const C6: f64 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
|
|
18
|
+
|
|
19
|
+
// kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
|
|
20
|
+
// Input x is assumed to be bounded by ~pi/4 in magnitude.
|
|
21
|
+
// Input y is the tail of x.
|
|
22
|
+
//
|
|
23
|
+
// Algorithm
|
|
24
|
+
// 1. Since cos(-x) = cos(x), we need only to consider positive x.
|
|
25
|
+
// 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
|
|
26
|
+
// 3. cos(x) is approximated by a polynomial of degree 14 on
|
|
27
|
+
// [0,pi/4]
|
|
28
|
+
// 4 14
|
|
29
|
+
// cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
|
|
30
|
+
// where the remez error is
|
|
31
|
+
//
|
|
32
|
+
// | 2 4 6 8 10 12 14 | -58
|
|
33
|
+
// |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
|
|
34
|
+
// | |
|
|
35
|
+
//
|
|
36
|
+
// 4 6 8 10 12 14
|
|
37
|
+
// 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
|
|
38
|
+
// cos(x) ~ 1 - x*x/2 + r
|
|
39
|
+
// since cos(x+y) ~ cos(x) - sin(x)*y
|
|
40
|
+
// ~ cos(x) - x*y,
|
|
41
|
+
// a correction term is necessary in cos(x) and hence
|
|
42
|
+
// cos(x+y) = 1 - (x*x/2 - (r - x*y))
|
|
43
|
+
// For better accuracy, rearrange to
|
|
44
|
+
// cos(x+y) ~ w + (tmp + (r-x*y))
|
|
45
|
+
// where w = 1 - x*x/2 and tmp is a tiny correction term
|
|
46
|
+
// (1 - x*x/2 == w + tmp exactly in infinite precision).
|
|
47
|
+
// The exactness of w + tmp in infinite precision depends on w
|
|
48
|
+
// and tmp having the same precision as x. If they have extra
|
|
49
|
+
// precision due to compiler bugs, then the extra precision is
|
|
50
|
+
// only good provided it is retained in all terms of the final
|
|
51
|
+
// expression for cos(). Retention happens in all cases tested
|
|
52
|
+
// under FreeBSD, so don't pessimize things by forcibly clipping
|
|
53
|
+
// any extra precision in w.
|
|
54
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
55
|
+
pub(crate) fn k_cos(x: f64, y: f64) -> f64 {
|
|
56
|
+
let z = x * x;
|
|
57
|
+
let w = z * z;
|
|
58
|
+
let r = z * (C1 + z * (C2 + z * C3)) + w * w * (C4 + z * (C5 + z * C6));
|
|
59
|
+
let hz = 0.5 * z;
|
|
60
|
+
let w = 1.0 - hz;
|
|
61
|
+
w + (((1.0 - w) - hz) + (z * r - x * y))
|
|
62
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/k_cosf.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
|
+
|
|
17
|
+
/* |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). */
|
|
18
|
+
const C0: f64 = -0.499999997251031003120; /* -0x1ffffffd0c5e81.0p-54 */
|
|
19
|
+
const C1: f64 = 0.0416666233237390631894; /* 0x155553e1053a42.0p-57 */
|
|
20
|
+
const C2: f64 = -0.00138867637746099294692; /* -0x16c087e80f1e27.0p-62 */
|
|
21
|
+
const C3: f64 = 0.0000243904487962774090654; /* 0x199342e0ee5069.0p-68 */
|
|
22
|
+
|
|
23
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
24
|
+
pub(crate) fn k_cosf(x: f64) -> f32 {
|
|
25
|
+
let z = x * x;
|
|
26
|
+
let w = z * z;
|
|
27
|
+
let r = C2 + z * C3;
|
|
28
|
+
(((1.0 + z * C0) + w * C1) + (w * z) * r) as f32
|
|
29
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// origin: FreeBSD /usr/src/lib/msun/src/k_sin.c
|
|
2
|
+
//
|
|
3
|
+
// ====================================================
|
|
4
|
+
// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Developed at SunSoft, 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
|
+
const S1: f64 = -1.66666666666666324348e-01; /* 0xBFC55555, 0x55555549 */
|
|
13
|
+
const S2: f64 = 8.33333333332248946124e-03; /* 0x3F811111, 0x1110F8A6 */
|
|
14
|
+
const S3: f64 = -1.98412698298579493134e-04; /* 0xBF2A01A0, 0x19C161D5 */
|
|
15
|
+
const S4: f64 = 2.75573137070700676789e-06; /* 0x3EC71DE3, 0x57B1FE7D */
|
|
16
|
+
const S5: f64 = -2.50507602534068634195e-08; /* 0xBE5AE5E6, 0x8A2B9CEB */
|
|
17
|
+
const S6: f64 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
|
|
18
|
+
|
|
19
|
+
// kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
|
|
20
|
+
// Input x is assumed to be bounded by ~pi/4 in magnitude.
|
|
21
|
+
// Input y is the tail of x.
|
|
22
|
+
// Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
|
|
23
|
+
//
|
|
24
|
+
// Algorithm
|
|
25
|
+
// 1. Since sin(-x) = -sin(x), we need only to consider positive x.
|
|
26
|
+
// 2. Callers must return sin(-0) = -0 without calling here since our
|
|
27
|
+
// odd polynomial is not evaluated in a way that preserves -0.
|
|
28
|
+
// Callers may do the optimization sin(x) ~ x for tiny x.
|
|
29
|
+
// 3. sin(x) is approximated by a polynomial of degree 13 on
|
|
30
|
+
// [0,pi/4]
|
|
31
|
+
// 3 13
|
|
32
|
+
// sin(x) ~ x + S1*x + ... + S6*x
|
|
33
|
+
// where
|
|
34
|
+
//
|
|
35
|
+
// |sin(x) 2 4 6 8 10 12 | -58
|
|
36
|
+
// |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
|
|
37
|
+
// | x |
|
|
38
|
+
//
|
|
39
|
+
// 4. sin(x+y) = sin(x) + sin'(x')*y
|
|
40
|
+
// ~ sin(x) + (1-x*x/2)*y
|
|
41
|
+
// For better accuracy, let
|
|
42
|
+
// 3 2 2 2 2
|
|
43
|
+
// r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
|
|
44
|
+
// then 3 2
|
|
45
|
+
// sin(x) = x + (S1*x + (x *(r-y/2)+y))
|
|
46
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
47
|
+
pub(crate) fn k_sin(x: f64, y: f64, iy: i32) -> f64 {
|
|
48
|
+
let z = x * x;
|
|
49
|
+
let w = z * z;
|
|
50
|
+
let r = S2 + z * (S3 + z * S4) + z * w * (S5 + z * S6);
|
|
51
|
+
let v = z * x;
|
|
52
|
+
if iy == 0 {
|
|
53
|
+
x + v * (S1 + z * r)
|
|
54
|
+
} else {
|
|
55
|
+
x - ((z * (0.5 * y - v * r) - y) - v * S1)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/k_sinf.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
|
+
/* |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]). */
|
|
18
|
+
const S1: f64 = -0.166666666416265235595; /* -0x15555554cbac77.0p-55 */
|
|
19
|
+
const S2: f64 = 0.0083333293858894631756; /* 0x111110896efbb2.0p-59 */
|
|
20
|
+
const S3: f64 = -0.000198393348360966317347; /* -0x1a00f9e2cae774.0p-65 */
|
|
21
|
+
const S4: f64 = 0.0000027183114939898219064; /* 0x16cd878c3b46a7.0p-71 */
|
|
22
|
+
|
|
23
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
24
|
+
pub(crate) fn k_sinf(x: f64) -> f32 {
|
|
25
|
+
let z = x * x;
|
|
26
|
+
let w = z * z;
|
|
27
|
+
let r = S3 + z * S4;
|
|
28
|
+
let s = z * x;
|
|
29
|
+
((x + s * (S1 + z * S2)) + s * w * r) as f32
|
|
30
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// origin: FreeBSD /usr/src/lib/msun/src/k_tan.c */
|
|
2
|
+
//
|
|
3
|
+
// ====================================================
|
|
4
|
+
// Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
|
|
5
|
+
//
|
|
6
|
+
// Permission to use, copy, modify, and distribute this
|
|
7
|
+
// software is freely granted, provided that this notice
|
|
8
|
+
// is preserved.
|
|
9
|
+
// ====================================================
|
|
10
|
+
|
|
11
|
+
// kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
|
|
12
|
+
// Input x is assumed to be bounded by ~pi/4 in magnitude.
|
|
13
|
+
// Input y is the tail of x.
|
|
14
|
+
// Input odd indicates whether tan (if odd = 0) or -1/tan (if odd = 1) is returned.
|
|
15
|
+
//
|
|
16
|
+
// Algorithm
|
|
17
|
+
// 1. Since tan(-x) = -tan(x), we need only to consider positive x.
|
|
18
|
+
// 2. Callers must return tan(-0) = -0 without calling here since our
|
|
19
|
+
// odd polynomial is not evaluated in a way that preserves -0.
|
|
20
|
+
// Callers may do the optimization tan(x) ~ x for tiny x.
|
|
21
|
+
// 3. tan(x) is approximated by a odd polynomial of degree 27 on
|
|
22
|
+
// [0,0.67434]
|
|
23
|
+
// 3 27
|
|
24
|
+
// tan(x) ~ x + T1*x + ... + T13*x
|
|
25
|
+
// where
|
|
26
|
+
//
|
|
27
|
+
// |tan(x) 2 4 26 | -59.2
|
|
28
|
+
// |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
|
|
29
|
+
// | x |
|
|
30
|
+
//
|
|
31
|
+
// Note: tan(x+y) = tan(x) + tan'(x)*y
|
|
32
|
+
// ~ tan(x) + (1+x*x)*y
|
|
33
|
+
// Therefore, for better accuracy in computing tan(x+y), let
|
|
34
|
+
// 3 2 2 2 2
|
|
35
|
+
// r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
|
|
36
|
+
// then
|
|
37
|
+
// 3 2
|
|
38
|
+
// tan(x+y) = x + (T1*x + (x *(r+y)+y))
|
|
39
|
+
//
|
|
40
|
+
// 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
|
|
41
|
+
// tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
|
|
42
|
+
// = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
|
|
43
|
+
static T: [f64; 13] = [
|
|
44
|
+
3.33333333333334091986e-01, /* 3FD55555, 55555563 */
|
|
45
|
+
1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */
|
|
46
|
+
5.39682539762260521377e-02, /* 3FABA1BA, 1BB341FE */
|
|
47
|
+
2.18694882948595424599e-02, /* 3F9664F4, 8406D637 */
|
|
48
|
+
8.86323982359930005737e-03, /* 3F8226E3, E96E8493 */
|
|
49
|
+
3.59207910759131235356e-03, /* 3F6D6D22, C9560328 */
|
|
50
|
+
1.45620945432529025516e-03, /* 3F57DBC8, FEE08315 */
|
|
51
|
+
5.88041240820264096874e-04, /* 3F4344D8, F2F26501 */
|
|
52
|
+
2.46463134818469906812e-04, /* 3F3026F7, 1A8D1068 */
|
|
53
|
+
7.81794442939557092300e-05, /* 3F147E88, A03792A6 */
|
|
54
|
+
7.14072491382608190305e-05, /* 3F12B80F, 32F0A7E9 */
|
|
55
|
+
-1.85586374855275456654e-05, /* BEF375CB, DB605373 */
|
|
56
|
+
2.59073051863633712884e-05, /* 3EFB2A70, 74BF7AD4 */
|
|
57
|
+
];
|
|
58
|
+
const PIO4: f64 = 7.85398163397448278999e-01; /* 3FE921FB, 54442D18 */
|
|
59
|
+
const PIO4_LO: f64 = 3.06161699786838301793e-17; /* 3C81A626, 33145C07 */
|
|
60
|
+
|
|
61
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
62
|
+
pub(crate) fn k_tan(mut x: f64, mut y: f64, odd: i32) -> f64 {
|
|
63
|
+
let hx = (f64::to_bits(x) >> 32) as u32;
|
|
64
|
+
let big = (hx & 0x7fffffff) >= 0x3FE59428; /* |x| >= 0.6744 */
|
|
65
|
+
if big {
|
|
66
|
+
let sign = hx >> 31;
|
|
67
|
+
if sign != 0 {
|
|
68
|
+
x = -x;
|
|
69
|
+
y = -y;
|
|
70
|
+
}
|
|
71
|
+
x = (PIO4 - x) + (PIO4_LO - y);
|
|
72
|
+
y = 0.0;
|
|
73
|
+
}
|
|
74
|
+
let z = x * x;
|
|
75
|
+
let w = z * z;
|
|
76
|
+
/*
|
|
77
|
+
* Break x^5*(T[1]+x^2*T[2]+...) into
|
|
78
|
+
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
|
|
79
|
+
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
|
|
80
|
+
*/
|
|
81
|
+
let r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] + w * T[11]))));
|
|
82
|
+
let v = z * (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] + w * T[12])))));
|
|
83
|
+
let s = z * x;
|
|
84
|
+
let r = y + z * (s * (r + v) + y) + s * T[0];
|
|
85
|
+
let w = x + r;
|
|
86
|
+
if big {
|
|
87
|
+
let sign = hx >> 31;
|
|
88
|
+
let s = 1.0 - 2.0 * odd as f64;
|
|
89
|
+
let v = s - 2.0 * (x + (r - w * w / (w + s)));
|
|
90
|
+
return if sign != 0 { -v } else { v };
|
|
91
|
+
}
|
|
92
|
+
if odd == 0 {
|
|
93
|
+
return w;
|
|
94
|
+
}
|
|
95
|
+
/* -1.0/(x+r) has up to 2ulp error, so compute it accurately */
|
|
96
|
+
let w0 = zero_low_word(w);
|
|
97
|
+
let v = r - (w0 - x); /* w0+v = r+x */
|
|
98
|
+
let a = -1.0 / w;
|
|
99
|
+
let a0 = zero_low_word(a);
|
|
100
|
+
a0 + a * (1.0 + a0 * w0 + a0 * v)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fn zero_low_word(x: f64) -> f64 {
|
|
104
|
+
f64::from_bits(f64::to_bits(x) & 0xFFFF_FFFF_0000_0000)
|
|
105
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/k_tan.c */
|
|
2
|
+
/*
|
|
3
|
+
* ====================================================
|
|
4
|
+
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Permission to use, copy, modify, and distribute this
|
|
7
|
+
* software is freely granted, provided that this notice
|
|
8
|
+
* is preserved.
|
|
9
|
+
* ====================================================
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */
|
|
13
|
+
const T: [f64; 6] = [
|
|
14
|
+
0.333331395030791399758, /* 0x15554d3418c99f.0p-54 */
|
|
15
|
+
0.133392002712976742718, /* 0x1112fd38999f72.0p-55 */
|
|
16
|
+
0.0533812378445670393523, /* 0x1b54c91d865afe.0p-57 */
|
|
17
|
+
0.0245283181166547278873, /* 0x191df3908c33ce.0p-58 */
|
|
18
|
+
0.00297435743359967304927, /* 0x185dadfcecf44e.0p-61 */
|
|
19
|
+
0.00946564784943673166728, /* 0x1362b9bf971bcd.0p-59 */
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
23
|
+
pub(crate) fn k_tanf(x: f64, odd: bool) -> f32 {
|
|
24
|
+
let z = x * x;
|
|
25
|
+
/*
|
|
26
|
+
* Split up the polynomial into small independent terms to give
|
|
27
|
+
* opportunities for parallel evaluation. The chosen splitting is
|
|
28
|
+
* micro-optimized for Athlons (XP, X64). It costs 2 multiplications
|
|
29
|
+
* relative to Horner's method on sequential machines.
|
|
30
|
+
*
|
|
31
|
+
* We add the small terms from lowest degree up for efficiency on
|
|
32
|
+
* non-sequential machines (the lowest degree terms tend to be ready
|
|
33
|
+
* earlier). Apart from this, we don't care about order of
|
|
34
|
+
* operations, and don't need to to care since we have precision to
|
|
35
|
+
* spare. However, the chosen splitting is good for accuracy too,
|
|
36
|
+
* and would give results as accurate as Horner's method if the
|
|
37
|
+
* small terms were added from highest degree down.
|
|
38
|
+
*/
|
|
39
|
+
let mut r = T[4] + z * T[5];
|
|
40
|
+
let t = T[2] + z * T[3];
|
|
41
|
+
let w = z * z;
|
|
42
|
+
let s = z * x;
|
|
43
|
+
let u = T[0] + z * T[1];
|
|
44
|
+
r = (x + s * u) + (s * w) * (t + w * r);
|
|
45
|
+
(if odd { -1. / r } else { r }) as f32
|
|
46
|
+
}
|