@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,137 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.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
|
+
|
|
13
|
+
use super::{get_high_word, k_cos, k_sin, rem_pio2};
|
|
14
|
+
|
|
15
|
+
/// Both the sine and cosine of `x` (f64).
|
|
16
|
+
///
|
|
17
|
+
/// `x` is specified in radians and the return value is (sin(x), cos(x)).
|
|
18
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
19
|
+
pub fn sincos(x: f64) -> (f64, f64) {
|
|
20
|
+
let s: f64;
|
|
21
|
+
let c: f64;
|
|
22
|
+
let mut ix: u32;
|
|
23
|
+
|
|
24
|
+
ix = get_high_word(x);
|
|
25
|
+
ix &= 0x7fffffff;
|
|
26
|
+
|
|
27
|
+
/* |x| ~< pi/4 */
|
|
28
|
+
if ix <= 0x3fe921fb {
|
|
29
|
+
/* if |x| < 2**-27 * sqrt(2) */
|
|
30
|
+
if ix < 0x3e46a09e {
|
|
31
|
+
/* raise inexact if x!=0 and underflow if subnormal */
|
|
32
|
+
let x1p120 = f64::from_bits(0x4770000000000000); // 0x1p120 == 2^120
|
|
33
|
+
if ix < 0x00100000 {
|
|
34
|
+
force_eval!(x / x1p120);
|
|
35
|
+
} else {
|
|
36
|
+
force_eval!(x + x1p120);
|
|
37
|
+
}
|
|
38
|
+
return (x, 1.0);
|
|
39
|
+
}
|
|
40
|
+
return (k_sin(x, 0.0, 0), k_cos(x, 0.0));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* sincos(Inf or NaN) is NaN */
|
|
44
|
+
if ix >= 0x7ff00000 {
|
|
45
|
+
let rv = x - x;
|
|
46
|
+
return (rv, rv);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* argument reduction needed */
|
|
50
|
+
let (n, y0, y1) = rem_pio2(x);
|
|
51
|
+
s = k_sin(y0, y1, 1);
|
|
52
|
+
c = k_cos(y0, y1);
|
|
53
|
+
match n & 3 {
|
|
54
|
+
0 => (s, c),
|
|
55
|
+
1 => (c, -s),
|
|
56
|
+
2 => (-s, -c),
|
|
57
|
+
3 => (-c, s),
|
|
58
|
+
#[cfg(debug_assertions)]
|
|
59
|
+
_ => unreachable!(),
|
|
60
|
+
#[cfg(not(debug_assertions))]
|
|
61
|
+
_ => (0.0, 1.0),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// These tests are based on those from sincosf.rs
|
|
66
|
+
#[cfg(test)]
|
|
67
|
+
mod tests {
|
|
68
|
+
use super::sincos;
|
|
69
|
+
|
|
70
|
+
const TOLERANCE: f64 = 1e-6;
|
|
71
|
+
|
|
72
|
+
#[test]
|
|
73
|
+
fn with_pi() {
|
|
74
|
+
let (s, c) = sincos(core::f64::consts::PI);
|
|
75
|
+
assert!(
|
|
76
|
+
(s - 0.0).abs() < TOLERANCE,
|
|
77
|
+
"|{} - {}| = {} >= {}",
|
|
78
|
+
s,
|
|
79
|
+
0.0,
|
|
80
|
+
(s - 0.0).abs(),
|
|
81
|
+
TOLERANCE
|
|
82
|
+
);
|
|
83
|
+
assert!(
|
|
84
|
+
(c + 1.0).abs() < TOLERANCE,
|
|
85
|
+
"|{} + {}| = {} >= {}",
|
|
86
|
+
c,
|
|
87
|
+
1.0,
|
|
88
|
+
(s + 1.0).abs(),
|
|
89
|
+
TOLERANCE
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#[test]
|
|
94
|
+
fn rotational_symmetry() {
|
|
95
|
+
use core::f64::consts::PI;
|
|
96
|
+
const N: usize = 24;
|
|
97
|
+
for n in 0..N {
|
|
98
|
+
let theta = 2. * PI * (n as f64) / (N as f64);
|
|
99
|
+
let (s, c) = sincos(theta);
|
|
100
|
+
let (s_plus, c_plus) = sincos(theta + 2. * PI);
|
|
101
|
+
let (s_minus, c_minus) = sincos(theta - 2. * PI);
|
|
102
|
+
|
|
103
|
+
assert!(
|
|
104
|
+
(s - s_plus).abs() < TOLERANCE,
|
|
105
|
+
"|{} - {}| = {} >= {}",
|
|
106
|
+
s,
|
|
107
|
+
s_plus,
|
|
108
|
+
(s - s_plus).abs(),
|
|
109
|
+
TOLERANCE
|
|
110
|
+
);
|
|
111
|
+
assert!(
|
|
112
|
+
(s - s_minus).abs() < TOLERANCE,
|
|
113
|
+
"|{} - {}| = {} >= {}",
|
|
114
|
+
s,
|
|
115
|
+
s_minus,
|
|
116
|
+
(s - s_minus).abs(),
|
|
117
|
+
TOLERANCE
|
|
118
|
+
);
|
|
119
|
+
assert!(
|
|
120
|
+
(c - c_plus).abs() < TOLERANCE,
|
|
121
|
+
"|{} - {}| = {} >= {}",
|
|
122
|
+
c,
|
|
123
|
+
c_plus,
|
|
124
|
+
(c - c_plus).abs(),
|
|
125
|
+
TOLERANCE
|
|
126
|
+
);
|
|
127
|
+
assert!(
|
|
128
|
+
(c - c_minus).abs() < TOLERANCE,
|
|
129
|
+
"|{} - {}| = {} >= {}",
|
|
130
|
+
c,
|
|
131
|
+
c_minus,
|
|
132
|
+
(c - c_minus).abs(),
|
|
133
|
+
TOLERANCE
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/s_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
|
+
use super::{k_cosf, k_sinf, rem_pio2f};
|
|
18
|
+
|
|
19
|
+
/* Small multiples of pi/2 rounded to double precision. */
|
|
20
|
+
const PI_2: f64 = 0.5 * 3.1415926535897931160E+00;
|
|
21
|
+
const S1PIO2: f64 = 1.0 * PI_2; /* 0x3FF921FB, 0x54442D18 */
|
|
22
|
+
const S2PIO2: f64 = 2.0 * PI_2; /* 0x400921FB, 0x54442D18 */
|
|
23
|
+
const S3PIO2: f64 = 3.0 * PI_2; /* 0x4012D97C, 0x7F3321D2 */
|
|
24
|
+
const S4PIO2: f64 = 4.0 * PI_2; /* 0x401921FB, 0x54442D18 */
|
|
25
|
+
|
|
26
|
+
/// Both the sine and cosine of `x` (f32).
|
|
27
|
+
///
|
|
28
|
+
/// `x` is specified in radians and the return value is (sin(x), cos(x)).
|
|
29
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
30
|
+
pub fn sincosf(x: f32) -> (f32, f32) {
|
|
31
|
+
let s: f32;
|
|
32
|
+
let c: f32;
|
|
33
|
+
let mut ix: u32;
|
|
34
|
+
let sign: bool;
|
|
35
|
+
|
|
36
|
+
ix = x.to_bits();
|
|
37
|
+
sign = (ix >> 31) != 0;
|
|
38
|
+
ix &= 0x7fffffff;
|
|
39
|
+
|
|
40
|
+
/* |x| ~<= pi/4 */
|
|
41
|
+
if ix <= 0x3f490fda {
|
|
42
|
+
/* |x| < 2**-12 */
|
|
43
|
+
if ix < 0x39800000 {
|
|
44
|
+
/* raise inexact if x!=0 and underflow if subnormal */
|
|
45
|
+
|
|
46
|
+
let x1p120 = f32::from_bits(0x7b800000); // 0x1p120 == 2^120
|
|
47
|
+
if ix < 0x00100000 {
|
|
48
|
+
force_eval!(x / x1p120);
|
|
49
|
+
} else {
|
|
50
|
+
force_eval!(x + x1p120);
|
|
51
|
+
}
|
|
52
|
+
return (x, 1.0);
|
|
53
|
+
}
|
|
54
|
+
return (k_sinf(x as f64), k_cosf(x as f64));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* |x| ~<= 5*pi/4 */
|
|
58
|
+
if ix <= 0x407b53d1 {
|
|
59
|
+
if ix <= 0x4016cbe3 {
|
|
60
|
+
/* |x| ~<= 3pi/4 */
|
|
61
|
+
if sign {
|
|
62
|
+
s = -k_cosf(x as f64 + S1PIO2);
|
|
63
|
+
c = k_sinf(x as f64 + S1PIO2);
|
|
64
|
+
} else {
|
|
65
|
+
s = k_cosf(S1PIO2 - x as f64);
|
|
66
|
+
c = k_sinf(S1PIO2 - x as f64);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */
|
|
70
|
+
else if sign {
|
|
71
|
+
s = -k_sinf(x as f64 + S2PIO2);
|
|
72
|
+
c = -k_cosf(x as f64 + S2PIO2);
|
|
73
|
+
} else {
|
|
74
|
+
s = -k_sinf(x as f64 - S2PIO2);
|
|
75
|
+
c = -k_cosf(x as f64 - S2PIO2);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (s, c);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* |x| ~<= 9*pi/4 */
|
|
82
|
+
if ix <= 0x40e231d5 {
|
|
83
|
+
if ix <= 0x40afeddf {
|
|
84
|
+
/* |x| ~<= 7*pi/4 */
|
|
85
|
+
if sign {
|
|
86
|
+
s = k_cosf(x as f64 + S3PIO2);
|
|
87
|
+
c = -k_sinf(x as f64 + S3PIO2);
|
|
88
|
+
} else {
|
|
89
|
+
s = -k_cosf(x as f64 - S3PIO2);
|
|
90
|
+
c = k_sinf(x as f64 - S3PIO2);
|
|
91
|
+
}
|
|
92
|
+
} else if sign {
|
|
93
|
+
s = k_sinf(x as f64 + S4PIO2);
|
|
94
|
+
c = k_cosf(x as f64 + S4PIO2);
|
|
95
|
+
} else {
|
|
96
|
+
s = k_sinf(x as f64 - S4PIO2);
|
|
97
|
+
c = k_cosf(x as f64 - S4PIO2);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (s, c);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* sin(Inf or NaN) is NaN */
|
|
104
|
+
if ix >= 0x7f800000 {
|
|
105
|
+
let rv = x - x;
|
|
106
|
+
return (rv, rv);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* general argument reduction needed */
|
|
110
|
+
let (n, y) = rem_pio2f(x);
|
|
111
|
+
s = k_sinf(y);
|
|
112
|
+
c = k_cosf(y);
|
|
113
|
+
match n & 3 {
|
|
114
|
+
0 => (s, c),
|
|
115
|
+
1 => (c, -s),
|
|
116
|
+
2 => (-s, -c),
|
|
117
|
+
3 => (-c, s),
|
|
118
|
+
#[cfg(debug_assertions)]
|
|
119
|
+
_ => unreachable!(),
|
|
120
|
+
#[cfg(not(debug_assertions))]
|
|
121
|
+
_ => (0.0, 1.0),
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
|
|
126
|
+
#[cfg(not(target_arch = "powerpc64"))]
|
|
127
|
+
#[cfg(test)]
|
|
128
|
+
mod tests {
|
|
129
|
+
use super::sincosf;
|
|
130
|
+
|
|
131
|
+
#[test]
|
|
132
|
+
fn rotational_symmetry() {
|
|
133
|
+
use core::f32::consts::PI;
|
|
134
|
+
const N: usize = 24;
|
|
135
|
+
for n in 0..N {
|
|
136
|
+
let theta = 2. * PI * (n as f32) / (N as f32);
|
|
137
|
+
let (s, c) = sincosf(theta);
|
|
138
|
+
let (s_plus, c_plus) = sincosf(theta + 2. * PI);
|
|
139
|
+
let (s_minus, c_minus) = sincosf(theta - 2. * PI);
|
|
140
|
+
|
|
141
|
+
const TOLERANCE: f32 = 1e-6;
|
|
142
|
+
assert!(
|
|
143
|
+
(s - s_plus).abs() < TOLERANCE,
|
|
144
|
+
"|{} - {}| = {} >= {}",
|
|
145
|
+
s,
|
|
146
|
+
s_plus,
|
|
147
|
+
(s - s_plus).abs(),
|
|
148
|
+
TOLERANCE
|
|
149
|
+
);
|
|
150
|
+
assert!(
|
|
151
|
+
(s - s_minus).abs() < TOLERANCE,
|
|
152
|
+
"|{} - {}| = {} >= {}",
|
|
153
|
+
s,
|
|
154
|
+
s_minus,
|
|
155
|
+
(s - s_minus).abs(),
|
|
156
|
+
TOLERANCE
|
|
157
|
+
);
|
|
158
|
+
assert!(
|
|
159
|
+
(c - c_plus).abs() < TOLERANCE,
|
|
160
|
+
"|{} - {}| = {} >= {}",
|
|
161
|
+
c,
|
|
162
|
+
c_plus,
|
|
163
|
+
(c - c_plus).abs(),
|
|
164
|
+
TOLERANCE
|
|
165
|
+
);
|
|
166
|
+
assert!(
|
|
167
|
+
(c - c_minus).abs() < TOLERANCE,
|
|
168
|
+
"|{} - {}| = {} >= {}",
|
|
169
|
+
c,
|
|
170
|
+
c_minus,
|
|
171
|
+
(c - c_minus).abs(),
|
|
172
|
+
TOLERANCE
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* origin: FreeBSD /usr/src/lib/msun/src/s_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
|
+
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 S1_PIO2: f64 = 1. * FRAC_PI_2; /* 0x3FF921FB, 0x54442D18 */
|
|
23
|
+
const S2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */
|
|
24
|
+
const S3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */
|
|
25
|
+
const S4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */
|
|
26
|
+
|
|
27
|
+
/// The sine of `x` (f32).
|
|
28
|
+
///
|
|
29
|
+
/// `x` is specified in radians.
|
|
30
|
+
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
|
|
31
|
+
pub fn sinf(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 and underflow if subnormal */
|
|
45
|
+
force_eval!(if ix < 0x00800000 {
|
|
46
|
+
x / x1p120
|
|
47
|
+
} else {
|
|
48
|
+
x + x1p120
|
|
49
|
+
});
|
|
50
|
+
return x;
|
|
51
|
+
}
|
|
52
|
+
return k_sinf(x64);
|
|
53
|
+
}
|
|
54
|
+
if ix <= 0x407b53d1 {
|
|
55
|
+
/* |x| ~<= 5*pi/4 */
|
|
56
|
+
if ix <= 0x4016cbe3 {
|
|
57
|
+
/* |x| ~<= 3pi/4 */
|
|
58
|
+
if sign {
|
|
59
|
+
return -k_cosf(x64 + S1_PIO2);
|
|
60
|
+
} else {
|
|
61
|
+
return k_cosf(x64 - S1_PIO2);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return k_sinf(if sign {
|
|
65
|
+
-(x64 + S2_PIO2)
|
|
66
|
+
} else {
|
|
67
|
+
-(x64 - S2_PIO2)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if ix <= 0x40e231d5 {
|
|
71
|
+
/* |x| ~<= 9*pi/4 */
|
|
72
|
+
if ix <= 0x40afeddf {
|
|
73
|
+
/* |x| ~<= 7*pi/4 */
|
|
74
|
+
if sign {
|
|
75
|
+
return k_cosf(x64 + S3_PIO2);
|
|
76
|
+
} else {
|
|
77
|
+
return -k_cosf(x64 - S3_PIO2);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return k_sinf(if sign { x64 + S4_PIO2 } else { x64 - S4_PIO2 });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* sin(Inf or NaN) is NaN */
|
|
84
|
+
if ix >= 0x7f800000 {
|
|
85
|
+
return x - x;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* general argument reduction needed */
|
|
89
|
+
let (n, y) = rem_pio2f(x);
|
|
90
|
+
match n & 3 {
|
|
91
|
+
0 => k_sinf(y),
|
|
92
|
+
1 => k_cosf(y),
|
|
93
|
+
2 => k_sinf(-y),
|
|
94
|
+
_ => -k_cosf(y),
|
|
95
|
+
}
|
|
96
|
+
}
|
package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/support/int_traits/narrowing_div.rs
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT OR Apache-2.0 */
|
|
2
|
+
use crate::support::{CastInto, DInt, HInt, Int, MinInt, u256};
|
|
3
|
+
|
|
4
|
+
/// Trait for unsigned division of a double-wide integer
|
|
5
|
+
/// when the quotient doesn't overflow.
|
|
6
|
+
///
|
|
7
|
+
/// This is the inverse of widening multiplication:
|
|
8
|
+
/// - for any `x` and nonzero `y`: `x.widen_mul(y).checked_narrowing_div_rem(y) == Some((x, 0))`,
|
|
9
|
+
/// - and for any `r in 0..y`: `x.carrying_mul(y, r).checked_narrowing_div_rem(y) == Some((x, r))`,
|
|
10
|
+
pub trait NarrowingDiv: DInt + MinInt<Unsigned = Self> {
|
|
11
|
+
/// Computes `(self / n, self % n))`
|
|
12
|
+
///
|
|
13
|
+
/// # Safety
|
|
14
|
+
/// The caller must ensure that `self.hi() < n`, or equivalently,
|
|
15
|
+
/// that the quotient does not overflow.
|
|
16
|
+
unsafe fn unchecked_narrowing_div_rem(self, n: Self::H) -> (Self::H, Self::H);
|
|
17
|
+
|
|
18
|
+
/// Returns `Some((self / n, self % n))` when `self.hi() < n`.
|
|
19
|
+
fn checked_narrowing_div_rem(self, n: Self::H) -> Option<(Self::H, Self::H)> {
|
|
20
|
+
if self.hi() < n {
|
|
21
|
+
Some(unsafe { self.unchecked_narrowing_div_rem(n) })
|
|
22
|
+
} else {
|
|
23
|
+
None
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// For primitive types we can just use the standard
|
|
29
|
+
// division operators in the double-wide type.
|
|
30
|
+
macro_rules! impl_narrowing_div_primitive {
|
|
31
|
+
($D:ident) => {
|
|
32
|
+
impl NarrowingDiv for $D {
|
|
33
|
+
unsafe fn unchecked_narrowing_div_rem(self, n: Self::H) -> (Self::H, Self::H) {
|
|
34
|
+
if self.hi() >= n {
|
|
35
|
+
unsafe { core::hint::unreachable_unchecked() }
|
|
36
|
+
}
|
|
37
|
+
((self / n.widen()).cast(), (self % n.widen()).cast())
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Extend division from `u2N / uN` to `u4N / u2N`
|
|
44
|
+
// This is not the most efficient algorithm, but it is
|
|
45
|
+
// relatively simple.
|
|
46
|
+
macro_rules! impl_narrowing_div_recurse {
|
|
47
|
+
($D:ident) => {
|
|
48
|
+
impl NarrowingDiv for $D {
|
|
49
|
+
unsafe fn unchecked_narrowing_div_rem(self, n: Self::H) -> (Self::H, Self::H) {
|
|
50
|
+
if self.hi() >= n {
|
|
51
|
+
unsafe { core::hint::unreachable_unchecked() }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Normalize the divisor by shifting the most significant one
|
|
55
|
+
// to the leading position. `n != 0` is implied by `self.hi() < n`
|
|
56
|
+
let lz = n.leading_zeros();
|
|
57
|
+
let a = self << lz;
|
|
58
|
+
let b = n << lz;
|
|
59
|
+
|
|
60
|
+
let ah = a.hi();
|
|
61
|
+
let (a0, a1) = a.lo().lo_hi();
|
|
62
|
+
// SAFETY: For both calls, `b.leading_zeros() == 0` by the above shift.
|
|
63
|
+
// SAFETY: `ah < b` follows from `self.hi() < n`
|
|
64
|
+
let (q1, r) = unsafe { div_three_digits_by_two(a1, ah, b) };
|
|
65
|
+
// SAFETY: `r < b` is given as the postcondition of the previous call
|
|
66
|
+
let (q0, r) = unsafe { div_three_digits_by_two(a0, r, b) };
|
|
67
|
+
|
|
68
|
+
// Undo the earlier normalization for the remainder
|
|
69
|
+
(Self::H::from_lo_hi(q0, q1), r >> lz)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
impl_narrowing_div_primitive!(u16);
|
|
76
|
+
impl_narrowing_div_primitive!(u32);
|
|
77
|
+
impl_narrowing_div_primitive!(u64);
|
|
78
|
+
impl_narrowing_div_primitive!(u128);
|
|
79
|
+
impl_narrowing_div_recurse!(u256);
|
|
80
|
+
|
|
81
|
+
/// Implement `u3N / u2N`-division on top of `u2N / uN`-division.
|
|
82
|
+
///
|
|
83
|
+
/// Returns the quotient and remainder of `(a * R + a0) / n`,
|
|
84
|
+
/// where `R = (1 << U::BITS)` is the digit size.
|
|
85
|
+
///
|
|
86
|
+
/// # Safety
|
|
87
|
+
/// Requires that `n.leading_zeros() == 0` and `a < n`.
|
|
88
|
+
unsafe fn div_three_digits_by_two<U>(a0: U, a: U::D, n: U::D) -> (U, U::D)
|
|
89
|
+
where
|
|
90
|
+
U: HInt,
|
|
91
|
+
U::D: Int + NarrowingDiv,
|
|
92
|
+
{
|
|
93
|
+
if n.leading_zeros() > 0 || a >= n {
|
|
94
|
+
unsafe { core::hint::unreachable_unchecked() }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// n = n1R + n0
|
|
98
|
+
let (n0, n1) = n.lo_hi();
|
|
99
|
+
// a = a2R + a1
|
|
100
|
+
let (a1, a2) = a.lo_hi();
|
|
101
|
+
|
|
102
|
+
let mut q;
|
|
103
|
+
let mut r;
|
|
104
|
+
let mut wrap;
|
|
105
|
+
// `a < n` is guaranteed by the caller, but `a2 == n1 && a1 < n0` is possible
|
|
106
|
+
if let Some((q0, r1)) = a.checked_narrowing_div_rem(n1) {
|
|
107
|
+
q = q0;
|
|
108
|
+
// a = qn1 + r1, where 0 <= r1 < n1
|
|
109
|
+
|
|
110
|
+
// Include the remainder with the low bits:
|
|
111
|
+
// r = a0 + r1R
|
|
112
|
+
r = U::D::from_lo_hi(a0, r1);
|
|
113
|
+
|
|
114
|
+
// Subtract the contribution of the divisor low bits with the estimated quotient
|
|
115
|
+
let d = q.widen_mul(n0);
|
|
116
|
+
(r, wrap) = r.overflowing_sub(d);
|
|
117
|
+
|
|
118
|
+
// Since `q` is the quotient of dividing with a slightly smaller divisor,
|
|
119
|
+
// it may be an overapproximation, but is never too small, and similarly,
|
|
120
|
+
// `r` is now either the correct remainder ...
|
|
121
|
+
if !wrap {
|
|
122
|
+
return (q, r);
|
|
123
|
+
}
|
|
124
|
+
// ... or the remainder went "negative" (by as much as `d = qn0 < RR`)
|
|
125
|
+
// and we have to adjust.
|
|
126
|
+
q -= U::ONE;
|
|
127
|
+
} else {
|
|
128
|
+
debug_assert!(a2 == n1 && a1 < n0);
|
|
129
|
+
// Otherwise, `a2 == n1`, and the estimated quotient would be
|
|
130
|
+
// `R + (a1 % n1)`, but the correct quotient can't overflow.
|
|
131
|
+
// We'll start from `q = R = (1 << U::BITS)`,
|
|
132
|
+
// so `r = aR + a0 - qn = (a - n)R + a0`
|
|
133
|
+
r = U::D::from_lo_hi(a0, a1.wrapping_sub(n0));
|
|
134
|
+
// Since `a < n`, the first decrement is always needed:
|
|
135
|
+
q = U::MAX; /* R - 1 */
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
(r, wrap) = r.overflowing_add(n);
|
|
139
|
+
if wrap {
|
|
140
|
+
return (q, r);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// If the remainder still didn't wrap, we need another step.
|
|
144
|
+
q -= U::ONE;
|
|
145
|
+
(r, wrap) = r.overflowing_add(n);
|
|
146
|
+
// Since `n >= RR/2`, at least one of the two `r += n` must have wrapped.
|
|
147
|
+
debug_assert!(wrap, "estimated quotient should be off by at most two");
|
|
148
|
+
(q, r)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#[cfg(test)]
|
|
152
|
+
mod test {
|
|
153
|
+
use super::{HInt, NarrowingDiv};
|
|
154
|
+
|
|
155
|
+
#[test]
|
|
156
|
+
fn inverse_mul() {
|
|
157
|
+
for x in 0..=u8::MAX {
|
|
158
|
+
for y in 1..=u8::MAX {
|
|
159
|
+
let xy = x.widen_mul(y);
|
|
160
|
+
assert_eq!(xy.checked_narrowing_div_rem(y), Some((x, 0)));
|
|
161
|
+
assert_eq!(
|
|
162
|
+
(xy + (y - 1) as u16).checked_narrowing_div_rem(y),
|
|
163
|
+
Some((x, y - 1))
|
|
164
|
+
);
|
|
165
|
+
if y > 1 {
|
|
166
|
+
assert_eq!((xy + 1).checked_narrowing_div_rem(y), Some((x, 1)));
|
|
167
|
+
assert_eq!(
|
|
168
|
+
(xy + (y - 2) as u16).checked_narrowing_div_rem(y),
|
|
169
|
+
Some((x, y - 2))
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|