@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,116 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT OR Apache-2.0 */
|
|
2
|
+
use crate::support::{CastFrom, CastInto, Float, HInt, Int, MinInt, NarrowingDiv};
|
|
3
|
+
|
|
4
|
+
#[inline]
|
|
5
|
+
pub fn fmod<F: Float>(x: F, y: F) -> F
|
|
6
|
+
where
|
|
7
|
+
F::Int: HInt,
|
|
8
|
+
<F::Int as HInt>::D: NarrowingDiv,
|
|
9
|
+
{
|
|
10
|
+
let _1 = F::Int::ONE;
|
|
11
|
+
let sx = x.to_bits() & F::SIGN_MASK;
|
|
12
|
+
let ux = x.to_bits() & !F::SIGN_MASK;
|
|
13
|
+
let uy = y.to_bits() & !F::SIGN_MASK;
|
|
14
|
+
|
|
15
|
+
// Cases that return NaN:
|
|
16
|
+
// NaN % _
|
|
17
|
+
// Inf % _
|
|
18
|
+
// _ % NaN
|
|
19
|
+
// _ % 0
|
|
20
|
+
let x_nan_or_inf = ux & F::EXP_MASK == F::EXP_MASK;
|
|
21
|
+
let y_nan_or_zero = uy.wrapping_sub(_1) & F::EXP_MASK == F::EXP_MASK;
|
|
22
|
+
if x_nan_or_inf | y_nan_or_zero {
|
|
23
|
+
return (x * y) / (x * y);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if ux < uy {
|
|
27
|
+
// |x| < |y|
|
|
28
|
+
return x;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let (num, ex) = into_sig_exp::<F>(ux);
|
|
32
|
+
let (div, ey) = into_sig_exp::<F>(uy);
|
|
33
|
+
|
|
34
|
+
// To compute `(num << ex) % (div << ey)`, first
|
|
35
|
+
// evaluate `rem = (num << (ex - ey)) % div` ...
|
|
36
|
+
let rem = reduction::<F>(num, ex - ey, div);
|
|
37
|
+
// ... so the result will be `rem << ey`
|
|
38
|
+
|
|
39
|
+
if rem.is_zero() {
|
|
40
|
+
// Return zero with the sign of `x`
|
|
41
|
+
return F::from_bits(sx);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// We would shift `rem` up by `ey`, but have to stop at `F::SIG_BITS`
|
|
45
|
+
let shift = ey.min(F::SIG_BITS - rem.ilog2());
|
|
46
|
+
// Anything past that is added to the exponent field
|
|
47
|
+
let bits = (rem << shift) + (F::Int::cast_from(ey - shift) << F::SIG_BITS);
|
|
48
|
+
F::from_bits(sx + bits)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Given the bits of a finite float, return a tuple of
|
|
52
|
+
/// - the mantissa with the implicit bit (0 if subnormal, 1 otherwise)
|
|
53
|
+
/// - the additional exponent past 1, (0 for subnormal, 0 or more otherwise)
|
|
54
|
+
fn into_sig_exp<F: Float>(mut bits: F::Int) -> (F::Int, u32) {
|
|
55
|
+
bits &= !F::SIGN_MASK;
|
|
56
|
+
// Subtract 1 from the exponent, clamping at 0
|
|
57
|
+
let sat = bits.checked_sub(F::IMPLICIT_BIT).unwrap_or(F::Int::ZERO);
|
|
58
|
+
(
|
|
59
|
+
bits - (sat & F::EXP_MASK),
|
|
60
|
+
u32::cast_from(sat >> F::SIG_BITS),
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Compute the remainder `(x * 2.pow(e)) % y` without overflow.
|
|
65
|
+
fn reduction<F>(mut x: F::Int, e: u32, y: F::Int) -> F::Int
|
|
66
|
+
where
|
|
67
|
+
F: Float,
|
|
68
|
+
F::Int: HInt,
|
|
69
|
+
<<F as Float>::Int as HInt>::D: NarrowingDiv,
|
|
70
|
+
{
|
|
71
|
+
// `f16` only has 5 exponent bits, so even `f16::MAX = 65504.0` is only
|
|
72
|
+
// a 40-bit integer multiple of the smallest subnormal.
|
|
73
|
+
if F::BITS == 16 {
|
|
74
|
+
debug_assert!(F::EXP_MAX - F::EXP_MIN == 29);
|
|
75
|
+
debug_assert!(e <= 29);
|
|
76
|
+
let u: u16 = x.cast();
|
|
77
|
+
let v: u16 = y.cast();
|
|
78
|
+
let u = (u as u64) << e;
|
|
79
|
+
let v = v as u64;
|
|
80
|
+
return F::Int::cast_from((u % v) as u16);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Ensure `x < 2y` for later steps
|
|
84
|
+
if x >= (y << 1) {
|
|
85
|
+
// This case is only reached with subnormal divisors,
|
|
86
|
+
// but it might be better to just normalize all significands
|
|
87
|
+
// to make this unnecessary. The further calls could potentially
|
|
88
|
+
// benefit from assuming a specific fixed leading bit position.
|
|
89
|
+
x %= y;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The simple implementation seems to be fastest for a short reduction
|
|
93
|
+
// at this size. The limit here was chosen empirically on an Intel Nehalem.
|
|
94
|
+
// Less old CPUs that have faster `u64 * u64 -> u128` might not benefit,
|
|
95
|
+
// and 32-bit systems or architectures without hardware multipliers might
|
|
96
|
+
// want to do this in more cases.
|
|
97
|
+
if F::BITS == 64 && e < 32 {
|
|
98
|
+
// Assumes `x < 2y`
|
|
99
|
+
for _ in 0..e {
|
|
100
|
+
x = x.checked_sub(y).unwrap_or(x);
|
|
101
|
+
x <<= 1;
|
|
102
|
+
}
|
|
103
|
+
return x.checked_sub(y).unwrap_or(x);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Fast path for short reductions
|
|
107
|
+
if e < F::BITS {
|
|
108
|
+
let w = x.widen() << e;
|
|
109
|
+
if let Some((_, r)) = w.checked_narrowing_div_rem(y) {
|
|
110
|
+
return r;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Assumes `x < 2y`
|
|
115
|
+
crate::support::linear_mul_reduction(x, e, y)
|
|
116
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/* origin: musl src/math/rint.c */
|
|
3
|
+
|
|
4
|
+
use crate::support::{Float, FpResult, Round};
|
|
5
|
+
|
|
6
|
+
/// IEEE 754-2019 `roundToIntegralExact`, which respects rounding mode and raises inexact if
|
|
7
|
+
/// applicable.
|
|
8
|
+
#[inline]
|
|
9
|
+
pub fn rint_round<F: Float>(x: F, _round: Round) -> FpResult<F> {
|
|
10
|
+
let toint = F::ONE / F::EPSILON;
|
|
11
|
+
let e = x.ex();
|
|
12
|
+
let positive = x.is_sign_positive();
|
|
13
|
+
|
|
14
|
+
// On i386 `force_eval!` must be used to force rounding via storage to memory. Otherwise,
|
|
15
|
+
// the excess precission from x87 would cause an incorrect final result.
|
|
16
|
+
let force = |x| {
|
|
17
|
+
if cfg!(x86_no_sse) && (F::BITS == 32 || F::BITS == 64) {
|
|
18
|
+
force_eval!(x)
|
|
19
|
+
} else {
|
|
20
|
+
x
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
let res = if e >= F::EXP_BIAS + F::SIG_BITS {
|
|
25
|
+
// No fractional part; exact result can be returned.
|
|
26
|
+
x
|
|
27
|
+
} else {
|
|
28
|
+
// Apply a net-zero adjustment that nudges `y` in the direction of the rounding mode. For
|
|
29
|
+
// Rust this is always nearest, but ideally it would take `round` into account.
|
|
30
|
+
let y = if positive {
|
|
31
|
+
force(force(x) + toint) - toint
|
|
32
|
+
} else {
|
|
33
|
+
force(force(x) - toint) + toint
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if y == F::ZERO {
|
|
37
|
+
// A zero result takes the sign of the input.
|
|
38
|
+
if positive { F::ZERO } else { F::NEG_ZERO }
|
|
39
|
+
} else {
|
|
40
|
+
y
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
FpResult::ok(res)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[cfg(test)]
|
|
48
|
+
mod tests {
|
|
49
|
+
use super::*;
|
|
50
|
+
use crate::support::{Hexf, Status};
|
|
51
|
+
|
|
52
|
+
fn spec_test<F: Float>(cases: &[(F, F, Status)]) {
|
|
53
|
+
let roundtrip = [
|
|
54
|
+
F::ZERO,
|
|
55
|
+
F::ONE,
|
|
56
|
+
F::NEG_ONE,
|
|
57
|
+
F::NEG_ZERO,
|
|
58
|
+
F::INFINITY,
|
|
59
|
+
F::NEG_INFINITY,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
for x in roundtrip {
|
|
63
|
+
let FpResult { val, status } = rint_round(x, Round::Nearest);
|
|
64
|
+
assert_biteq!(val, x, "rint_round({})", Hexf(x));
|
|
65
|
+
assert_eq!(status, Status::OK, "{}", Hexf(x));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for &(x, res, res_stat) in cases {
|
|
69
|
+
let FpResult { val, status } = rint_round(x, Round::Nearest);
|
|
70
|
+
assert_biteq!(val, res, "rint_round({})", Hexf(x));
|
|
71
|
+
assert_eq!(status, res_stat, "{}", Hexf(x));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[test]
|
|
76
|
+
#[cfg(f16_enabled)]
|
|
77
|
+
fn spec_tests_f16() {
|
|
78
|
+
let cases = [];
|
|
79
|
+
spec_test::<f16>(&cases);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[test]
|
|
83
|
+
fn spec_tests_f32() {
|
|
84
|
+
let cases = [
|
|
85
|
+
(0.1, 0.0, Status::OK),
|
|
86
|
+
(-0.1, -0.0, Status::OK),
|
|
87
|
+
(0.5, 0.0, Status::OK),
|
|
88
|
+
(-0.5, -0.0, Status::OK),
|
|
89
|
+
(0.9, 1.0, Status::OK),
|
|
90
|
+
(-0.9, -1.0, Status::OK),
|
|
91
|
+
(1.1, 1.0, Status::OK),
|
|
92
|
+
(-1.1, -1.0, Status::OK),
|
|
93
|
+
(1.5, 2.0, Status::OK),
|
|
94
|
+
(-1.5, -2.0, Status::OK),
|
|
95
|
+
(1.9, 2.0, Status::OK),
|
|
96
|
+
(-1.9, -2.0, Status::OK),
|
|
97
|
+
(2.8, 3.0, Status::OK),
|
|
98
|
+
(-2.8, -3.0, Status::OK),
|
|
99
|
+
];
|
|
100
|
+
spec_test::<f32>(&cases);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#[test]
|
|
104
|
+
fn spec_tests_f64() {
|
|
105
|
+
let cases = [
|
|
106
|
+
(0.1, 0.0, Status::OK),
|
|
107
|
+
(-0.1, -0.0, Status::OK),
|
|
108
|
+
(0.5, 0.0, Status::OK),
|
|
109
|
+
(-0.5, -0.0, Status::OK),
|
|
110
|
+
(0.9, 1.0, Status::OK),
|
|
111
|
+
(-0.9, -1.0, Status::OK),
|
|
112
|
+
(1.1, 1.0, Status::OK),
|
|
113
|
+
(-1.1, -1.0, Status::OK),
|
|
114
|
+
(1.5, 2.0, Status::OK),
|
|
115
|
+
(-1.5, -2.0, Status::OK),
|
|
116
|
+
(1.9, 2.0, Status::OK),
|
|
117
|
+
(-1.9, -2.0, Status::OK),
|
|
118
|
+
(2.8, 3.0, Status::OK),
|
|
119
|
+
(-2.8, -3.0, Status::OK),
|
|
120
|
+
];
|
|
121
|
+
spec_test::<f64>(&cases);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[test]
|
|
125
|
+
#[cfg(f128_enabled)]
|
|
126
|
+
fn spec_tests_f128() {
|
|
127
|
+
let cases = [];
|
|
128
|
+
spec_test::<f128>(&cases);
|
|
129
|
+
}
|
|
130
|
+
}
|