@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,383 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/e_j1f.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::{cosf, fabsf, logf, sinf, sqrtf};
|
|
17
|
+
|
|
18
|
+
const INVSQRTPI: f32 = 5.6418961287e-01; /* 0x3f106ebb */
|
|
19
|
+
const TPI: f32 = 6.3661974669e-01; /* 0x3f22f983 */
|
|
20
|
+
|
|
21
|
+
fn common(ix: u32, x: f32, y1: bool, sign: bool) -> f32 {
|
|
22
|
+
let z: f64;
|
|
23
|
+
let mut s: f64;
|
|
24
|
+
let c: f64;
|
|
25
|
+
let mut ss: f64;
|
|
26
|
+
let mut cc: f64;
|
|
27
|
+
|
|
28
|
+
s = sinf(x) as f64;
|
|
29
|
+
if y1 {
|
|
30
|
+
s = -s;
|
|
31
|
+
}
|
|
32
|
+
c = cosf(x) as f64;
|
|
33
|
+
cc = s - c;
|
|
34
|
+
if ix < 0x7f000000 {
|
|
35
|
+
ss = -s - c;
|
|
36
|
+
z = cosf(2.0 * x) as f64;
|
|
37
|
+
if s * c > 0.0 {
|
|
38
|
+
cc = z / ss;
|
|
39
|
+
} else {
|
|
40
|
+
ss = z / cc;
|
|
41
|
+
}
|
|
42
|
+
if ix < 0x58800000 {
|
|
43
|
+
if y1 {
|
|
44
|
+
ss = -ss;
|
|
45
|
+
}
|
|
46
|
+
cc = (ponef(x) as f64) * cc - (qonef(x) as f64) * ss;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if sign {
|
|
50
|
+
cc = -cc;
|
|
51
|
+
}
|
|
52
|
+
return (((INVSQRTPI as f64) * cc) / (sqrtf(x) as f64)) as f32;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* R0/S0 on [0,2] */
|
|
56
|
+
const R00: f32 = -6.2500000000e-02; /* 0xbd800000 */
|
|
57
|
+
const R01: f32 = 1.4070566976e-03; /* 0x3ab86cfd */
|
|
58
|
+
const R02: f32 = -1.5995563444e-05; /* 0xb7862e36 */
|
|
59
|
+
const R03: f32 = 4.9672799207e-08; /* 0x335557d2 */
|
|
60
|
+
const S01: f32 = 1.9153760746e-02; /* 0x3c9ce859 */
|
|
61
|
+
const S02: f32 = 1.8594678841e-04; /* 0x3942fab6 */
|
|
62
|
+
const S03: f32 = 1.1771846857e-06; /* 0x359dffc2 */
|
|
63
|
+
const S04: f32 = 5.0463624390e-09; /* 0x31ad6446 */
|
|
64
|
+
const S05: f32 = 1.2354227016e-11; /* 0x2d59567e */
|
|
65
|
+
|
|
66
|
+
/// First order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f32).
|
|
67
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
68
|
+
pub fn j1f(x: f32) -> f32 {
|
|
69
|
+
let mut z: f32;
|
|
70
|
+
let r: f32;
|
|
71
|
+
let s: f32;
|
|
72
|
+
let mut ix: u32;
|
|
73
|
+
let sign: bool;
|
|
74
|
+
|
|
75
|
+
ix = x.to_bits();
|
|
76
|
+
sign = (ix >> 31) != 0;
|
|
77
|
+
ix &= 0x7fffffff;
|
|
78
|
+
if ix >= 0x7f800000 {
|
|
79
|
+
return 1.0 / (x * x);
|
|
80
|
+
}
|
|
81
|
+
if ix >= 0x40000000 {
|
|
82
|
+
/* |x| >= 2 */
|
|
83
|
+
return common(ix, fabsf(x), false, sign);
|
|
84
|
+
}
|
|
85
|
+
if ix >= 0x39000000 {
|
|
86
|
+
/* |x| >= 2**-13 */
|
|
87
|
+
z = x * x;
|
|
88
|
+
r = z * (R00 + z * (R01 + z * (R02 + z * R03)));
|
|
89
|
+
s = 1.0 + z * (S01 + z * (S02 + z * (S03 + z * (S04 + z * S05))));
|
|
90
|
+
z = 0.5 + r / s;
|
|
91
|
+
} else {
|
|
92
|
+
z = 0.5;
|
|
93
|
+
}
|
|
94
|
+
return z * x;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const U0: [f32; 5] = [
|
|
98
|
+
-1.9605709612e-01, /* 0xbe48c331 */
|
|
99
|
+
5.0443872809e-02, /* 0x3d4e9e3c */
|
|
100
|
+
-1.9125689287e-03, /* 0xbafaaf2a */
|
|
101
|
+
2.3525259166e-05, /* 0x37c5581c */
|
|
102
|
+
-9.1909917899e-08, /* 0xb3c56003 */
|
|
103
|
+
];
|
|
104
|
+
const V0: [f32; 5] = [
|
|
105
|
+
1.9916731864e-02, /* 0x3ca3286a */
|
|
106
|
+
2.0255257550e-04, /* 0x3954644b */
|
|
107
|
+
1.3560879779e-06, /* 0x35b602d4 */
|
|
108
|
+
6.2274145840e-09, /* 0x31d5f8eb */
|
|
109
|
+
1.6655924903e-11, /* 0x2d9281cf */
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
/// First order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f32).
|
|
113
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
114
|
+
pub fn y1f(x: f32) -> f32 {
|
|
115
|
+
let z: f32;
|
|
116
|
+
let u: f32;
|
|
117
|
+
let v: f32;
|
|
118
|
+
let ix: u32;
|
|
119
|
+
|
|
120
|
+
ix = x.to_bits();
|
|
121
|
+
if (ix & 0x7fffffff) == 0 {
|
|
122
|
+
return -1.0 / 0.0;
|
|
123
|
+
}
|
|
124
|
+
if (ix >> 31) != 0 {
|
|
125
|
+
return 0.0 / 0.0;
|
|
126
|
+
}
|
|
127
|
+
if ix >= 0x7f800000 {
|
|
128
|
+
return 1.0 / x;
|
|
129
|
+
}
|
|
130
|
+
if ix >= 0x40000000 {
|
|
131
|
+
/* |x| >= 2.0 */
|
|
132
|
+
return common(ix, x, true, false);
|
|
133
|
+
}
|
|
134
|
+
if ix < 0x33000000 {
|
|
135
|
+
/* x < 2**-25 */
|
|
136
|
+
return -TPI / x;
|
|
137
|
+
}
|
|
138
|
+
z = x * x;
|
|
139
|
+
u = U0[0] + z * (U0[1] + z * (U0[2] + z * (U0[3] + z * U0[4])));
|
|
140
|
+
v = 1.0 + z * (V0[0] + z * (V0[1] + z * (V0[2] + z * (V0[3] + z * V0[4]))));
|
|
141
|
+
return x * (u / v) + TPI * (j1f(x) * logf(x) - 1.0 / x);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* For x >= 8, the asymptotic expansions of pone is
|
|
145
|
+
* 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
|
|
146
|
+
* We approximate pone by
|
|
147
|
+
* pone(x) = 1 + (R/S)
|
|
148
|
+
* where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
|
|
149
|
+
* S = 1 + ps0*s^2 + ... + ps4*s^10
|
|
150
|
+
* and
|
|
151
|
+
* | pone(x)-1-R/S | <= 2 ** ( -60.06)
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
const PR8: [f32; 6] = [
|
|
155
|
+
/* for x in [inf, 8]=1/[0,0.125] */
|
|
156
|
+
0.0000000000e+00, /* 0x00000000 */
|
|
157
|
+
1.1718750000e-01, /* 0x3df00000 */
|
|
158
|
+
1.3239480972e+01, /* 0x4153d4ea */
|
|
159
|
+
4.1205184937e+02, /* 0x43ce06a3 */
|
|
160
|
+
3.8747453613e+03, /* 0x45722bed */
|
|
161
|
+
7.9144794922e+03, /* 0x45f753d6 */
|
|
162
|
+
];
|
|
163
|
+
const PS8: [f32; 5] = [
|
|
164
|
+
1.1420736694e+02, /* 0x42e46a2c */
|
|
165
|
+
3.6509309082e+03, /* 0x45642ee5 */
|
|
166
|
+
3.6956207031e+04, /* 0x47105c35 */
|
|
167
|
+
9.7602796875e+04, /* 0x47bea166 */
|
|
168
|
+
3.0804271484e+04, /* 0x46f0a88b */
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const PR5: [f32; 6] = [
|
|
172
|
+
/* for x in [8,4.5454]=1/[0.125,0.22001] */
|
|
173
|
+
1.3199052094e-11, /* 0x2d68333f */
|
|
174
|
+
1.1718749255e-01, /* 0x3defffff */
|
|
175
|
+
6.8027510643e+00, /* 0x40d9b023 */
|
|
176
|
+
1.0830818176e+02, /* 0x42d89dca */
|
|
177
|
+
5.1763616943e+02, /* 0x440168b7 */
|
|
178
|
+
5.2871520996e+02, /* 0x44042dc6 */
|
|
179
|
+
];
|
|
180
|
+
const PS5: [f32; 5] = [
|
|
181
|
+
5.9280597687e+01, /* 0x426d1f55 */
|
|
182
|
+
9.9140142822e+02, /* 0x4477d9b1 */
|
|
183
|
+
5.3532670898e+03, /* 0x45a74a23 */
|
|
184
|
+
7.8446904297e+03, /* 0x45f52586 */
|
|
185
|
+
1.5040468750e+03, /* 0x44bc0180 */
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
const PR3: [f32; 6] = [
|
|
189
|
+
3.0250391081e-09, /* 0x314fe10d */
|
|
190
|
+
1.1718686670e-01, /* 0x3defffab */
|
|
191
|
+
3.9329774380e+00, /* 0x407bb5e7 */
|
|
192
|
+
3.5119403839e+01, /* 0x420c7a45 */
|
|
193
|
+
9.1055007935e+01, /* 0x42b61c2a */
|
|
194
|
+
4.8559066772e+01, /* 0x42423c7c */
|
|
195
|
+
];
|
|
196
|
+
const PS3: [f32; 5] = [
|
|
197
|
+
3.4791309357e+01, /* 0x420b2a4d */
|
|
198
|
+
3.3676245117e+02, /* 0x43a86198 */
|
|
199
|
+
1.0468714600e+03, /* 0x4482dbe3 */
|
|
200
|
+
8.9081134033e+02, /* 0x445eb3ed */
|
|
201
|
+
1.0378793335e+02, /* 0x42cf936c */
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
const PR2: [f32; 6] = [
|
|
205
|
+
/* for x in [2.8570,2]=1/[0.3499,0.5] */
|
|
206
|
+
1.0771083225e-07, /* 0x33e74ea8 */
|
|
207
|
+
1.1717621982e-01, /* 0x3deffa16 */
|
|
208
|
+
2.3685150146e+00, /* 0x401795c0 */
|
|
209
|
+
1.2242610931e+01, /* 0x4143e1bc */
|
|
210
|
+
1.7693971634e+01, /* 0x418d8d41 */
|
|
211
|
+
5.0735230446e+00, /* 0x40a25a4d */
|
|
212
|
+
];
|
|
213
|
+
const PS2: [f32; 5] = [
|
|
214
|
+
2.1436485291e+01, /* 0x41ab7dec */
|
|
215
|
+
1.2529022980e+02, /* 0x42fa9499 */
|
|
216
|
+
2.3227647400e+02, /* 0x436846c7 */
|
|
217
|
+
1.1767937469e+02, /* 0x42eb5bd7 */
|
|
218
|
+
8.3646392822e+00, /* 0x4105d590 */
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
fn ponef(x: f32) -> f32 {
|
|
222
|
+
let p: &[f32; 6];
|
|
223
|
+
let q: &[f32; 5];
|
|
224
|
+
let z: f32;
|
|
225
|
+
let r: f32;
|
|
226
|
+
let s: f32;
|
|
227
|
+
let mut ix: u32;
|
|
228
|
+
|
|
229
|
+
ix = x.to_bits();
|
|
230
|
+
ix &= 0x7fffffff;
|
|
231
|
+
if ix >= 0x41000000 {
|
|
232
|
+
p = &PR8;
|
|
233
|
+
q = &PS8;
|
|
234
|
+
} else if ix >= 0x409173eb {
|
|
235
|
+
p = &PR5;
|
|
236
|
+
q = &PS5;
|
|
237
|
+
} else if ix >= 0x4036d917 {
|
|
238
|
+
p = &PR3;
|
|
239
|
+
q = &PS3;
|
|
240
|
+
} else
|
|
241
|
+
/*ix >= 0x40000000*/
|
|
242
|
+
{
|
|
243
|
+
p = &PR2;
|
|
244
|
+
q = &PS2;
|
|
245
|
+
}
|
|
246
|
+
z = 1.0 / (x * x);
|
|
247
|
+
r = p[0] + z * (p[1] + z * (p[2] + z * (p[3] + z * (p[4] + z * p[5]))));
|
|
248
|
+
s = 1.0 + z * (q[0] + z * (q[1] + z * (q[2] + z * (q[3] + z * q[4]))));
|
|
249
|
+
return 1.0 + r / s;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* For x >= 8, the asymptotic expansions of qone is
|
|
253
|
+
* 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
|
|
254
|
+
* We approximate pone by
|
|
255
|
+
* qone(x) = s*(0.375 + (R/S))
|
|
256
|
+
* where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
|
|
257
|
+
* S = 1 + qs1*s^2 + ... + qs6*s^12
|
|
258
|
+
* and
|
|
259
|
+
* | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
const QR8: [f32; 6] = [
|
|
263
|
+
/* for x in [inf, 8]=1/[0,0.125] */
|
|
264
|
+
0.0000000000e+00, /* 0x00000000 */
|
|
265
|
+
-1.0253906250e-01, /* 0xbdd20000 */
|
|
266
|
+
-1.6271753311e+01, /* 0xc1822c8d */
|
|
267
|
+
-7.5960174561e+02, /* 0xc43de683 */
|
|
268
|
+
-1.1849806641e+04, /* 0xc639273a */
|
|
269
|
+
-4.8438511719e+04, /* 0xc73d3683 */
|
|
270
|
+
];
|
|
271
|
+
const QS8: [f32; 6] = [
|
|
272
|
+
1.6139537048e+02, /* 0x43216537 */
|
|
273
|
+
7.8253862305e+03, /* 0x45f48b17 */
|
|
274
|
+
1.3387534375e+05, /* 0x4802bcd6 */
|
|
275
|
+
7.1965775000e+05, /* 0x492fb29c */
|
|
276
|
+
6.6660125000e+05, /* 0x4922be94 */
|
|
277
|
+
-2.9449025000e+05, /* 0xc88fcb48 */
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
const QR5: [f32; 6] = [
|
|
281
|
+
/* for x in [8,4.5454]=1/[0.125,0.22001] */
|
|
282
|
+
-2.0897993405e-11, /* 0xadb7d219 */
|
|
283
|
+
-1.0253904760e-01, /* 0xbdd1fffe */
|
|
284
|
+
-8.0564479828e+00, /* 0xc100e736 */
|
|
285
|
+
-1.8366960144e+02, /* 0xc337ab6b */
|
|
286
|
+
-1.3731937256e+03, /* 0xc4aba633 */
|
|
287
|
+
-2.6124443359e+03, /* 0xc523471c */
|
|
288
|
+
];
|
|
289
|
+
const QS5: [f32; 6] = [
|
|
290
|
+
8.1276550293e+01, /* 0x42a28d98 */
|
|
291
|
+
1.9917987061e+03, /* 0x44f8f98f */
|
|
292
|
+
1.7468484375e+04, /* 0x468878f8 */
|
|
293
|
+
4.9851425781e+04, /* 0x4742bb6d */
|
|
294
|
+
2.7948074219e+04, /* 0x46da5826 */
|
|
295
|
+
-4.7191835938e+03, /* 0xc5937978 */
|
|
296
|
+
];
|
|
297
|
+
|
|
298
|
+
const QR3: [f32; 6] = [
|
|
299
|
+
-5.0783124372e-09, /* 0xb1ae7d4f */
|
|
300
|
+
-1.0253783315e-01, /* 0xbdd1ff5b */
|
|
301
|
+
-4.6101160049e+00, /* 0xc0938612 */
|
|
302
|
+
-5.7847221375e+01, /* 0xc267638e */
|
|
303
|
+
-2.2824453735e+02, /* 0xc3643e9a */
|
|
304
|
+
-2.1921012878e+02, /* 0xc35b35cb */
|
|
305
|
+
];
|
|
306
|
+
const QS3: [f32; 6] = [
|
|
307
|
+
4.7665153503e+01, /* 0x423ea91e */
|
|
308
|
+
6.7386511230e+02, /* 0x4428775e */
|
|
309
|
+
3.3801528320e+03, /* 0x45534272 */
|
|
310
|
+
5.5477290039e+03, /* 0x45ad5dd5 */
|
|
311
|
+
1.9031191406e+03, /* 0x44ede3d0 */
|
|
312
|
+
-1.3520118713e+02, /* 0xc3073381 */
|
|
313
|
+
];
|
|
314
|
+
|
|
315
|
+
const QR2: [f32; 6] = [
|
|
316
|
+
/* for x in [2.8570,2]=1/[0.3499,0.5] */
|
|
317
|
+
-1.7838172539e-07, /* 0xb43f8932 */
|
|
318
|
+
-1.0251704603e-01, /* 0xbdd1f475 */
|
|
319
|
+
-2.7522056103e+00, /* 0xc0302423 */
|
|
320
|
+
-1.9663616180e+01, /* 0xc19d4f16 */
|
|
321
|
+
-4.2325313568e+01, /* 0xc2294d1f */
|
|
322
|
+
-2.1371921539e+01, /* 0xc1aaf9b2 */
|
|
323
|
+
];
|
|
324
|
+
const QS2: [f32; 6] = [
|
|
325
|
+
2.9533363342e+01, /* 0x41ec4454 */
|
|
326
|
+
2.5298155212e+02, /* 0x437cfb47 */
|
|
327
|
+
7.5750280762e+02, /* 0x443d602e */
|
|
328
|
+
7.3939318848e+02, /* 0x4438d92a */
|
|
329
|
+
1.5594900513e+02, /* 0x431bf2f2 */
|
|
330
|
+
-4.9594988823e+00, /* 0xc09eb437 */
|
|
331
|
+
];
|
|
332
|
+
|
|
333
|
+
fn qonef(x: f32) -> f32 {
|
|
334
|
+
let p: &[f32; 6];
|
|
335
|
+
let q: &[f32; 6];
|
|
336
|
+
let s: f32;
|
|
337
|
+
let r: f32;
|
|
338
|
+
let z: f32;
|
|
339
|
+
let mut ix: u32;
|
|
340
|
+
|
|
341
|
+
ix = x.to_bits();
|
|
342
|
+
ix &= 0x7fffffff;
|
|
343
|
+
if ix >= 0x41000000 {
|
|
344
|
+
p = &QR8;
|
|
345
|
+
q = &QS8;
|
|
346
|
+
} else if ix >= 0x409173eb {
|
|
347
|
+
p = &QR5;
|
|
348
|
+
q = &QS5;
|
|
349
|
+
} else if ix >= 0x4036d917 {
|
|
350
|
+
p = &QR3;
|
|
351
|
+
q = &QS3;
|
|
352
|
+
} else
|
|
353
|
+
/*ix >= 0x40000000*/
|
|
354
|
+
{
|
|
355
|
+
p = &QR2;
|
|
356
|
+
q = &QS2;
|
|
357
|
+
}
|
|
358
|
+
z = 1.0 / (x * x);
|
|
359
|
+
r = p[0] + z * (p[1] + z * (p[2] + z * (p[3] + z * (p[4] + z * p[5]))));
|
|
360
|
+
s = 1.0 + z * (q[0] + z * (q[1] + z * (q[2] + z * (q[3] + z * (q[4] + z * q[5])))));
|
|
361
|
+
return (0.375 + r / s) / x;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
#[cfg(test)]
|
|
365
|
+
mod tests {
|
|
366
|
+
use super::{j1f, y1f};
|
|
367
|
+
#[test]
|
|
368
|
+
fn test_j1f_2488() {
|
|
369
|
+
// 0x401F3E49
|
|
370
|
+
assert_eq!(j1f(2.4881766_f32), 0.49999475_f32);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
#[test]
|
|
374
|
+
fn test_y1f_2002() {
|
|
375
|
+
//allow slightly different result on x87
|
|
376
|
+
let res = y1f(2.0000002_f32);
|
|
377
|
+
if cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) && (res == -0.10703231_f32)
|
|
378
|
+
{
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
assert_eq!(res, -0.10703229_f32);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/e_jn.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
|
+
/*
|
|
13
|
+
* jn(n, x), yn(n, x)
|
|
14
|
+
* floating point Bessel's function of the 1st and 2nd kind
|
|
15
|
+
* of order n
|
|
16
|
+
*
|
|
17
|
+
* Special cases:
|
|
18
|
+
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
|
|
19
|
+
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
|
|
20
|
+
* Note 2. About jn(n,x), yn(n,x)
|
|
21
|
+
* For n=0, j0(x) is called,
|
|
22
|
+
* for n=1, j1(x) is called,
|
|
23
|
+
* for n<=x, forward recursion is used starting
|
|
24
|
+
* from values of j0(x) and j1(x).
|
|
25
|
+
* for n>x, a continued fraction approximation to
|
|
26
|
+
* j(n,x)/j(n-1,x) is evaluated and then backward
|
|
27
|
+
* recursion is used starting from a supposed value
|
|
28
|
+
* for j(n,x). The resulting value of j(0,x) is
|
|
29
|
+
* compared with the actual value to correct the
|
|
30
|
+
* supposed value of j(n,x).
|
|
31
|
+
*
|
|
32
|
+
* yn(n,x) is similar in all respects, except
|
|
33
|
+
* that forward recursion is used for all
|
|
34
|
+
* values of n>1.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
use super::{cos, fabs, get_high_word, get_low_word, j0, j1, log, sin, sqrt, y0, y1};
|
|
38
|
+
|
|
39
|
+
const INVSQRTPI: f64 = 5.64189583547756279280e-01; /* 0x3FE20DD7, 0x50429B6D */
|
|
40
|
+
|
|
41
|
+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f64).
|
|
42
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
43
|
+
pub fn jn(n: i32, mut x: f64) -> f64 {
|
|
44
|
+
let mut ix: u32;
|
|
45
|
+
let lx: u32;
|
|
46
|
+
let nm1: i32;
|
|
47
|
+
let mut i: i32;
|
|
48
|
+
let mut sign: bool;
|
|
49
|
+
let mut a: f64;
|
|
50
|
+
let mut b: f64;
|
|
51
|
+
let mut temp: f64;
|
|
52
|
+
|
|
53
|
+
ix = get_high_word(x);
|
|
54
|
+
lx = get_low_word(x);
|
|
55
|
+
sign = (ix >> 31) != 0;
|
|
56
|
+
ix &= 0x7fffffff;
|
|
57
|
+
|
|
58
|
+
// -lx == !lx + 1
|
|
59
|
+
if ix | ((lx | (!lx).wrapping_add(1)) >> 31) > 0x7ff00000 {
|
|
60
|
+
/* nan */
|
|
61
|
+
return x;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
|
|
65
|
+
* Thus, J(-n,x) = J(n,-x)
|
|
66
|
+
*/
|
|
67
|
+
/* nm1 = |n|-1 is used instead of |n| to handle n==INT_MIN */
|
|
68
|
+
if n == 0 {
|
|
69
|
+
return j0(x);
|
|
70
|
+
}
|
|
71
|
+
if n < 0 {
|
|
72
|
+
nm1 = -(n + 1);
|
|
73
|
+
x = -x;
|
|
74
|
+
sign = !sign;
|
|
75
|
+
} else {
|
|
76
|
+
nm1 = n - 1;
|
|
77
|
+
}
|
|
78
|
+
if nm1 == 0 {
|
|
79
|
+
return j1(x);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
sign &= (n & 1) != 0; /* even n: 0, odd n: signbit(x) */
|
|
83
|
+
x = fabs(x);
|
|
84
|
+
if (ix | lx) == 0 || ix == 0x7ff00000 {
|
|
85
|
+
/* if x is 0 or inf */
|
|
86
|
+
b = 0.0;
|
|
87
|
+
} else if (nm1 as f64) < x {
|
|
88
|
+
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
|
|
89
|
+
if ix >= 0x52d00000 {
|
|
90
|
+
/* x > 2**302 */
|
|
91
|
+
/* (x >> n**2)
|
|
92
|
+
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
|
|
93
|
+
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
|
|
94
|
+
* Let s=sin(x), c=cos(x),
|
|
95
|
+
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
|
|
96
|
+
*
|
|
97
|
+
* n sin(xn)*sqt2 cos(xn)*sqt2
|
|
98
|
+
* ----------------------------------
|
|
99
|
+
* 0 s-c c+s
|
|
100
|
+
* 1 -s-c -c+s
|
|
101
|
+
* 2 -s+c -c-s
|
|
102
|
+
* 3 s+c c-s
|
|
103
|
+
*/
|
|
104
|
+
temp = match nm1 & 3 {
|
|
105
|
+
0 => -cos(x) + sin(x),
|
|
106
|
+
1 => -cos(x) - sin(x),
|
|
107
|
+
2 => cos(x) - sin(x),
|
|
108
|
+
// 3
|
|
109
|
+
_ => cos(x) + sin(x),
|
|
110
|
+
};
|
|
111
|
+
b = INVSQRTPI * temp / sqrt(x);
|
|
112
|
+
} else {
|
|
113
|
+
a = j0(x);
|
|
114
|
+
b = j1(x);
|
|
115
|
+
i = 0;
|
|
116
|
+
while i < nm1 {
|
|
117
|
+
i += 1;
|
|
118
|
+
temp = b;
|
|
119
|
+
b = b * (2.0 * (i as f64) / x) - a; /* avoid underflow */
|
|
120
|
+
a = temp;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else if ix < 0x3e100000 {
|
|
124
|
+
/* x < 2**-29 */
|
|
125
|
+
/* x is tiny, return the first Taylor expansion of J(n,x)
|
|
126
|
+
* J(n,x) = 1/n!*(x/2)^n - ...
|
|
127
|
+
*/
|
|
128
|
+
if nm1 > 32 {
|
|
129
|
+
/* underflow */
|
|
130
|
+
b = 0.0;
|
|
131
|
+
} else {
|
|
132
|
+
temp = x * 0.5;
|
|
133
|
+
b = temp;
|
|
134
|
+
a = 1.0;
|
|
135
|
+
i = 2;
|
|
136
|
+
while i <= nm1 + 1 {
|
|
137
|
+
a *= i as f64; /* a = n! */
|
|
138
|
+
b *= temp; /* b = (x/2)^n */
|
|
139
|
+
i += 1;
|
|
140
|
+
}
|
|
141
|
+
b = b / a;
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
/* use backward recurrence */
|
|
145
|
+
/* x x^2 x^2
|
|
146
|
+
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
|
|
147
|
+
* 2n - 2(n+1) - 2(n+2)
|
|
148
|
+
*
|
|
149
|
+
* 1 1 1
|
|
150
|
+
* (for large x) = ---- ------ ------ .....
|
|
151
|
+
* 2n 2(n+1) 2(n+2)
|
|
152
|
+
* -- - ------ - ------ -
|
|
153
|
+
* x x x
|
|
154
|
+
*
|
|
155
|
+
* Let w = 2n/x and h=2/x, then the above quotient
|
|
156
|
+
* is equal to the continued fraction:
|
|
157
|
+
* 1
|
|
158
|
+
* = -----------------------
|
|
159
|
+
* 1
|
|
160
|
+
* w - -----------------
|
|
161
|
+
* 1
|
|
162
|
+
* w+h - ---------
|
|
163
|
+
* w+2h - ...
|
|
164
|
+
*
|
|
165
|
+
* To determine how many terms needed, let
|
|
166
|
+
* Q(0) = w, Q(1) = w(w+h) - 1,
|
|
167
|
+
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
|
|
168
|
+
* When Q(k) > 1e4 good for single
|
|
169
|
+
* When Q(k) > 1e9 good for double
|
|
170
|
+
* When Q(k) > 1e17 good for quadruple
|
|
171
|
+
*/
|
|
172
|
+
/* determine k */
|
|
173
|
+
let mut t: f64;
|
|
174
|
+
let mut q0: f64;
|
|
175
|
+
let mut q1: f64;
|
|
176
|
+
let mut w: f64;
|
|
177
|
+
let h: f64;
|
|
178
|
+
let mut z: f64;
|
|
179
|
+
let mut tmp: f64;
|
|
180
|
+
let nf: f64;
|
|
181
|
+
|
|
182
|
+
let mut k: i32;
|
|
183
|
+
|
|
184
|
+
nf = (nm1 as f64) + 1.0;
|
|
185
|
+
w = 2.0 * nf / x;
|
|
186
|
+
h = 2.0 / x;
|
|
187
|
+
z = w + h;
|
|
188
|
+
q0 = w;
|
|
189
|
+
q1 = w * z - 1.0;
|
|
190
|
+
k = 1;
|
|
191
|
+
while q1 < 1.0e9 {
|
|
192
|
+
k += 1;
|
|
193
|
+
z += h;
|
|
194
|
+
tmp = z * q1 - q0;
|
|
195
|
+
q0 = q1;
|
|
196
|
+
q1 = tmp;
|
|
197
|
+
}
|
|
198
|
+
t = 0.0;
|
|
199
|
+
i = k;
|
|
200
|
+
while i >= 0 {
|
|
201
|
+
t = 1.0 / (2.0 * ((i as f64) + nf) / x - t);
|
|
202
|
+
i -= 1;
|
|
203
|
+
}
|
|
204
|
+
a = t;
|
|
205
|
+
b = 1.0;
|
|
206
|
+
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
|
|
207
|
+
* Hence, if n*(log(2n/x)) > ...
|
|
208
|
+
* single 8.8722839355e+01
|
|
209
|
+
* double 7.09782712893383973096e+02
|
|
210
|
+
* long double 1.1356523406294143949491931077970765006170e+04
|
|
211
|
+
* then recurrent value may overflow and the result is
|
|
212
|
+
* likely underflow to zero
|
|
213
|
+
*/
|
|
214
|
+
tmp = nf * log(fabs(w));
|
|
215
|
+
if tmp < 7.09782712893383973096e+02 {
|
|
216
|
+
i = nm1;
|
|
217
|
+
while i > 0 {
|
|
218
|
+
temp = b;
|
|
219
|
+
b = b * (2.0 * (i as f64)) / x - a;
|
|
220
|
+
a = temp;
|
|
221
|
+
i -= 1;
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
i = nm1;
|
|
225
|
+
while i > 0 {
|
|
226
|
+
temp = b;
|
|
227
|
+
b = b * (2.0 * (i as f64)) / x - a;
|
|
228
|
+
a = temp;
|
|
229
|
+
/* scale b to avoid spurious overflow */
|
|
230
|
+
let x1p500 = f64::from_bits(0x5f30000000000000); // 0x1p500 == 2^500
|
|
231
|
+
if b > x1p500 {
|
|
232
|
+
a /= b;
|
|
233
|
+
t /= b;
|
|
234
|
+
b = 1.0;
|
|
235
|
+
}
|
|
236
|
+
i -= 1;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
z = j0(x);
|
|
240
|
+
w = j1(x);
|
|
241
|
+
if fabs(z) >= fabs(w) {
|
|
242
|
+
b = t * z / b;
|
|
243
|
+
} else {
|
|
244
|
+
b = t * w / a;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if sign { -b } else { b }
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f64).
|
|
252
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
253
|
+
pub fn yn(n: i32, x: f64) -> f64 {
|
|
254
|
+
let mut ix: u32;
|
|
255
|
+
let lx: u32;
|
|
256
|
+
let mut ib: u32;
|
|
257
|
+
let nm1: i32;
|
|
258
|
+
let mut sign: bool;
|
|
259
|
+
let mut i: i32;
|
|
260
|
+
let mut a: f64;
|
|
261
|
+
let mut b: f64;
|
|
262
|
+
let mut temp: f64;
|
|
263
|
+
|
|
264
|
+
ix = get_high_word(x);
|
|
265
|
+
lx = get_low_word(x);
|
|
266
|
+
sign = (ix >> 31) != 0;
|
|
267
|
+
ix &= 0x7fffffff;
|
|
268
|
+
|
|
269
|
+
// -lx == !lx + 1
|
|
270
|
+
if ix | ((lx | (!lx).wrapping_add(1)) >> 31) > 0x7ff00000 {
|
|
271
|
+
/* nan */
|
|
272
|
+
return x;
|
|
273
|
+
}
|
|
274
|
+
if sign && (ix | lx) != 0 {
|
|
275
|
+
/* x < 0 */
|
|
276
|
+
return 0.0 / 0.0;
|
|
277
|
+
}
|
|
278
|
+
if ix == 0x7ff00000 {
|
|
279
|
+
return 0.0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if n == 0 {
|
|
283
|
+
return y0(x);
|
|
284
|
+
}
|
|
285
|
+
if n < 0 {
|
|
286
|
+
nm1 = -(n + 1);
|
|
287
|
+
sign = (n & 1) != 0;
|
|
288
|
+
} else {
|
|
289
|
+
nm1 = n - 1;
|
|
290
|
+
sign = false;
|
|
291
|
+
}
|
|
292
|
+
if nm1 == 0 {
|
|
293
|
+
if sign {
|
|
294
|
+
return -y1(x);
|
|
295
|
+
} else {
|
|
296
|
+
return y1(x);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if ix >= 0x52d00000 {
|
|
301
|
+
/* x > 2**302 */
|
|
302
|
+
/* (x >> n**2)
|
|
303
|
+
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
|
|
304
|
+
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
|
|
305
|
+
* Let s=sin(x), c=cos(x),
|
|
306
|
+
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
|
|
307
|
+
*
|
|
308
|
+
* n sin(xn)*sqt2 cos(xn)*sqt2
|
|
309
|
+
* ----------------------------------
|
|
310
|
+
* 0 s-c c+s
|
|
311
|
+
* 1 -s-c -c+s
|
|
312
|
+
* 2 -s+c -c-s
|
|
313
|
+
* 3 s+c c-s
|
|
314
|
+
*/
|
|
315
|
+
temp = match nm1 & 3 {
|
|
316
|
+
0 => -sin(x) - cos(x),
|
|
317
|
+
1 => -sin(x) + cos(x),
|
|
318
|
+
2 => sin(x) + cos(x),
|
|
319
|
+
// 3
|
|
320
|
+
_ => sin(x) - cos(x),
|
|
321
|
+
};
|
|
322
|
+
b = INVSQRTPI * temp / sqrt(x);
|
|
323
|
+
} else {
|
|
324
|
+
a = y0(x);
|
|
325
|
+
b = y1(x);
|
|
326
|
+
/* quit if b is -inf */
|
|
327
|
+
ib = get_high_word(b);
|
|
328
|
+
i = 0;
|
|
329
|
+
while i < nm1 && ib != 0xfff00000 {
|
|
330
|
+
i += 1;
|
|
331
|
+
temp = b;
|
|
332
|
+
b = (2.0 * (i as f64) / x) * b - a;
|
|
333
|
+
ib = get_high_word(b);
|
|
334
|
+
a = temp;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if sign { -b } else { b }
|
|
339
|
+
}
|