From 36362f7750c16903703b79d9f2bb57bc1cbe4d65 Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Sat, 27 Jul 2024 18:02:15 +0200 Subject: [PATCH] Implement Send & Sync, rename round_ties_to_even to round_ties_even (#100) --- ITF1788 | 2 +- src/_docs/conformance.md | 2 +- src/integer.rs | 30 ++++++------- src/interval.rs | 6 +++ src/simd/aarch64.rs | 2 +- src/simd/unimplemented.rs | 2 +- src/simd/x86_64.rs | 2 +- tests/itf1788_tests/libieeep1788_elem.rs | 54 ++++++++++++------------ 8 files changed, 53 insertions(+), 47 deletions(-) diff --git a/ITF1788 b/ITF1788 index 52095ff..d8c2a64 160000 --- a/ITF1788 +++ b/ITF1788 @@ -1 +1 @@ -Subproject commit 52095ffa7a3d7d6b1b2943849f2bb050e312f82a +Subproject commit d8c2a64478ebdc9cbde6ccef33eaad3bed60ed81 diff --git a/src/_docs/conformance.md b/src/_docs/conformance.md index d647931..5bcaae9 100644 --- a/src/_docs/conformance.md +++ b/src/_docs/conformance.md @@ -55,7 +55,7 @@ Some operations are only available when the crate is built with the conditional | ceil(_x_) | [`x.ceil()`](`Interval::ceil`) | - | | floor(_x_) | [`x.floor()`](`Interval::floor`) | - | | trunc(_x_) | [`x.trunc()`](`Interval::trunc`) | - | -| roundTiesToEven(_x_) | [`x.round_ties_to_even()`](`Interval::round_ties_to_even`) | - | +| roundTiesToEven(_x_) | [`x.round_ties_even()`](`Interval::round_ties_even`) | - | | roundTiesToAway(_x_) | [`x.round()`](`Interval::round`) | - | | abs(_x_) | [`x.abs()`](`Interval::abs`) | - | | min(_x_, _y_) | [`x.min(y)`](`Interval::min`) | - | diff --git a/src/integer.rs b/src/integer.rs index 4bdd4a3..9d41ba1 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -82,7 +82,7 @@ impl Interval { /// assert_eq!(Interval::ENTIRE.round(), Interval::ENTIRE); /// ``` /// - /// See also: [`Interval::round_ties_to_even`]. + /// See also: [`Interval::round_ties_even`]. #[must_use] pub fn round(self) -> Self { Self { @@ -102,21 +102,21 @@ impl Interval { /// /// ``` /// use inari::*; - /// assert_eq!(const_interval!(0.2, 1.2).round_ties_to_even(), const_interval!(0.0, 1.0)); - /// assert_eq!(const_interval!(0.5, 1.5).round_ties_to_even(), const_interval!(0.0, 2.0)); - /// assert_eq!(const_interval!(0.8, 1.8).round_ties_to_even(), const_interval!(1.0, 2.0)); - /// assert_eq!(const_interval!(-1.2, -0.2).round_ties_to_even(), const_interval!(-1.0, 0.0)); - /// assert_eq!(const_interval!(-1.5, -0.5).round_ties_to_even(), const_interval!(-2.0, 0.0)); - /// assert_eq!(const_interval!(-1.8, -0.8).round_ties_to_even(), const_interval!(-2.0, -1.0)); - /// assert_eq!(Interval::EMPTY.round_ties_to_even(), Interval::EMPTY); - /// assert_eq!(Interval::ENTIRE.round_ties_to_even(), Interval::ENTIRE); + /// assert_eq!(const_interval!(0.2, 1.2).round_ties_even(), const_interval!(0.0, 1.0)); + /// assert_eq!(const_interval!(0.5, 1.5).round_ties_even(), const_interval!(0.0, 2.0)); + /// assert_eq!(const_interval!(0.8, 1.8).round_ties_even(), const_interval!(1.0, 2.0)); + /// assert_eq!(const_interval!(-1.2, -0.2).round_ties_even(), const_interval!(-1.0, 0.0)); + /// assert_eq!(const_interval!(-1.5, -0.5).round_ties_even(), const_interval!(-2.0, 0.0)); + /// assert_eq!(const_interval!(-1.8, -0.8).round_ties_even(), const_interval!(-2.0, -1.0)); + /// assert_eq!(Interval::EMPTY.round_ties_even(), Interval::EMPTY); + /// assert_eq!(Interval::ENTIRE.round_ties_even(), Interval::ENTIRE); /// ``` /// /// See also: [`Interval::round`]. #[must_use] - pub fn round_ties_to_even(self) -> Self { + pub fn round_ties_even(self) -> Self { Self { - rep: round_ties_to_even(self.rep), + rep: round_ties_even(self.rep), } } @@ -234,7 +234,7 @@ impl DecInterval { let abs_b = x.sup_raw().abs(); (abs_a - abs_a.trunc() == 0.5) || (abs_b - abs_b.trunc() == 0.5) }); - impl_dec!(round_ties_to_even, x, y, { + impl_dec!(round_ties_even, x, y, { let abs_a = x.inf_raw().abs(); let abs_b = x.sup_raw().abs(); (abs_a - abs_a.trunc() == 0.5) || (abs_b - abs_b.trunc() == 0.5) @@ -264,14 +264,14 @@ mod tests { assert!(I::EMPTY.ceil().is_empty()); assert!(I::EMPTY.floor().is_empty()); assert!(I::EMPTY.round().is_empty()); - assert!(I::EMPTY.round_ties_to_even().is_empty()); + assert!(I::EMPTY.round_ties_even().is_empty()); assert!(I::EMPTY.sign().is_empty()); assert!(I::EMPTY.trunc().is_empty()); assert!(DI::EMPTY.ceil().is_empty()); assert!(DI::EMPTY.floor().is_empty()); assert!(DI::EMPTY.round().is_empty()); - assert!(DI::EMPTY.round_ties_to_even().is_empty()); + assert!(DI::EMPTY.round_ties_even().is_empty()); assert!(DI::EMPTY.sign().is_empty()); assert!(DI::EMPTY.trunc().is_empty()); } @@ -281,7 +281,7 @@ mod tests { assert!(DI::NAI.ceil().is_nai()); assert!(DI::NAI.floor().is_nai()); assert!(DI::NAI.round().is_nai()); - assert!(DI::NAI.round_ties_to_even().is_nai()); + assert!(DI::NAI.round_ties_even().is_nai()); assert!(DI::NAI.sign().is_nai()); assert!(DI::NAI.trunc().is_nai()); } diff --git a/src/interval.rs b/src/interval.rs index cc0fefa..ee439f6 100644 --- a/src/interval.rs +++ b/src/interval.rs @@ -61,6 +61,9 @@ pub struct Interval { pub(crate) rep: F64X2, } +unsafe impl Send for Interval {} +unsafe impl Sync for Interval {} + impl Interval { pub(crate) fn inf_raw(self) -> f64 { -extract0(self.rep) @@ -145,6 +148,9 @@ pub struct DecInterval { pub(crate) d: Decoration, } +unsafe impl Send for DecInterval {} +unsafe impl Sync for DecInterval {} + impl DecInterval { /// Creates a [`DecInterval`] from the given interval and the decoration below: /// diff --git a/src/simd/aarch64.rs b/src/simd/aarch64.rs index 98607c9..d521daa 100644 --- a/src/simd/aarch64.rs +++ b/src/simd/aarch64.rs @@ -112,7 +112,7 @@ pub(crate) fn round(x: F64X2) -> F64X2 { unsafe { vrndaq_f64(x) } } -pub(crate) fn round_ties_to_even(x: F64X2) -> F64X2 { +pub(crate) fn round_ties_even(x: F64X2) -> F64X2 { unsafe { vrndnq_f64(x) } } diff --git a/src/simd/unimplemented.rs b/src/simd/unimplemented.rs index 22cecfd..5cba6ca 100644 --- a/src/simd/unimplemented.rs +++ b/src/simd/unimplemented.rs @@ -122,7 +122,7 @@ pub(crate) fn round(_: F64X2) -> F64X2 { unimplemented!() } -pub(crate) fn round_ties_to_even(_: F64X2) -> F64X2 { +pub(crate) fn round_ties_even(_: F64X2) -> F64X2 { unimplemented!() } diff --git a/src/simd/x86_64.rs b/src/simd/x86_64.rs index 16c2c3e..23e163c 100644 --- a/src/simd/x86_64.rs +++ b/src/simd/x86_64.rs @@ -118,7 +118,7 @@ pub(crate) fn round(x: F64X2) -> F64X2 { constant(extract0(x).round(), extract1(x).round()) } -pub(crate) fn round_ties_to_even(x: F64X2) -> F64X2 { +pub(crate) fn round_ties_even(x: F64X2) -> F64X2 { unsafe { _mm_round_pd(x, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC) } } diff --git a/tests/itf1788_tests/libieeep1788_elem.rs b/tests/itf1788_tests/libieeep1788_elem.rs index 229da75..d0ff471 100644 --- a/tests/itf1788_tests/libieeep1788_elem.rs +++ b/tests/itf1788_tests/libieeep1788_elem.rs @@ -10392,57 +10392,57 @@ fn minimal_trunc_dec_test() { } #[test] -fn minimal_round_ties_to_even_test() { - assert_eq2!(I::EMPTY.round_ties_to_even(), I::EMPTY); - assert_eq2!(I::ENTIRE.round_ties_to_even(), I::ENTIRE); - assert_eq2!(n2i(1.1, 2.1).round_ties_to_even(), n2i(1.0, 2.0)); - assert_eq2!(n2i(-1.1, 2.0).round_ties_to_even(), n2i(-1.0, 2.0)); - assert_eq2!(n2i(-1.1, -0.4).round_ties_to_even(), n2i(-1.0, 0.0)); - assert_eq2!(n2i(-1.1, 0.0).round_ties_to_even(), n2i(-1.0, 0.0)); - assert_eq2!(n2i(-1.1, -0.0).round_ties_to_even(), n2i(-1.0, 0.0)); - assert_eq2!(n2i(-1.9, 2.2).round_ties_to_even(), n2i(-2.0, 2.0)); - assert_eq2!(n2i(-1.0, 2.2).round_ties_to_even(), n2i(-1.0, 2.0)); - assert_eq2!(n2i(1.5, 2.1).round_ties_to_even(), n2i(2.0, 2.0)); - assert_eq2!(n2i(-1.5, 2.0).round_ties_to_even(), n2i(-2.0, 2.0)); - assert_eq2!(n2i(-1.1, -0.5).round_ties_to_even(), n2i(-1.0, 0.0)); - assert_eq2!(n2i(-1.9, 2.5).round_ties_to_even(), n2i(-2.0, 2.0)); - assert_eq2!(n2i(0.0, 2.5).round_ties_to_even(), n2i(0.0, 2.0)); - assert_eq2!(n2i(-0.0, 2.5).round_ties_to_even(), n2i(0.0, 2.0)); - assert_eq2!(n2i(-1.5, 2.5).round_ties_to_even(), n2i(-2.0, 2.0)); - assert_eq2!( - n2i(-1.5, f64::INFINITY).round_ties_to_even(), +fn minimal_round_ties_even_test() { + assert_eq2!(I::EMPTY.round_ties_even(), I::EMPTY); + assert_eq2!(I::ENTIRE.round_ties_even(), I::ENTIRE); + assert_eq2!(n2i(1.1, 2.1).round_ties_even(), n2i(1.0, 2.0)); + assert_eq2!(n2i(-1.1, 2.0).round_ties_even(), n2i(-1.0, 2.0)); + assert_eq2!(n2i(-1.1, -0.4).round_ties_even(), n2i(-1.0, 0.0)); + assert_eq2!(n2i(-1.1, 0.0).round_ties_even(), n2i(-1.0, 0.0)); + assert_eq2!(n2i(-1.1, -0.0).round_ties_even(), n2i(-1.0, 0.0)); + assert_eq2!(n2i(-1.9, 2.2).round_ties_even(), n2i(-2.0, 2.0)); + assert_eq2!(n2i(-1.0, 2.2).round_ties_even(), n2i(-1.0, 2.0)); + assert_eq2!(n2i(1.5, 2.1).round_ties_even(), n2i(2.0, 2.0)); + assert_eq2!(n2i(-1.5, 2.0).round_ties_even(), n2i(-2.0, 2.0)); + assert_eq2!(n2i(-1.1, -0.5).round_ties_even(), n2i(-1.0, 0.0)); + assert_eq2!(n2i(-1.9, 2.5).round_ties_even(), n2i(-2.0, 2.0)); + assert_eq2!(n2i(0.0, 2.5).round_ties_even(), n2i(0.0, 2.0)); + assert_eq2!(n2i(-0.0, 2.5).round_ties_even(), n2i(0.0, 2.0)); + assert_eq2!(n2i(-1.5, 2.5).round_ties_even(), n2i(-2.0, 2.0)); + assert_eq2!( + n2i(-1.5, f64::INFINITY).round_ties_even(), n2i(-2.0, f64::INFINITY) ); assert_eq2!( - n2i(f64::NEG_INFINITY, 2.2).round_ties_to_even(), + n2i(f64::NEG_INFINITY, 2.2).round_ties_even(), n2i(f64::NEG_INFINITY, 2.0) ); } #[test] -fn minimal_round_ties_to_even_dec_test() { +fn minimal_round_ties_even_dec_test() { assert_eq2!( - nd2di(1.1, 2.1, D::Com).round_ties_to_even(), + nd2di(1.1, 2.1, D::Com).round_ties_even(), nd2di(1.0, 2.0, D::Def) ); assert_eq2!( - nd2di(-1.1, 2.0, D::Trv).round_ties_to_even(), + nd2di(-1.1, 2.0, D::Trv).round_ties_even(), nd2di(-1.0, 2.0, D::Trv) ); assert_eq2!( - nd2di(-1.6, -1.5, D::Com).round_ties_to_even(), + nd2di(-1.6, -1.5, D::Com).round_ties_even(), nd2di(-2.0, -2.0, D::Dac) ); assert_eq2!( - nd2di(-1.6, -1.4, D::Com).round_ties_to_even(), + nd2di(-1.6, -1.4, D::Com).round_ties_even(), nd2di(-2.0, -1.0, D::Def) ); assert_eq2!( - nd2di(-1.5, f64::INFINITY, D::Dac).round_ties_to_even(), + nd2di(-1.5, f64::INFINITY, D::Dac).round_ties_even(), nd2di(-2.0, f64::INFINITY, D::Def) ); assert_eq2!( - nd2di(f64::NEG_INFINITY, 2.2, D::Trv).round_ties_to_even(), + nd2di(f64::NEG_INFINITY, 2.2, D::Trv).round_ties_even(), nd2di(f64::NEG_INFINITY, 2.0, D::Trv) ); }