Skip to content

Commit

Permalink
Implement Send & Sync, rename round_ties_to_even to round_ties_even (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris00 authored Jul 27, 2024
1 parent 3660fa0 commit 36362f7
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion ITF1788
2 changes: 1 addition & 1 deletion src/_docs/conformance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`) | - |
Expand Down
30 changes: 15 additions & 15 deletions src/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down
6 changes: 6 additions & 0 deletions src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
///
Expand Down
2 changes: 1 addition & 1 deletion src/simd/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down
2 changes: 1 addition & 1 deletion src/simd/unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
}

Expand Down
2 changes: 1 addition & 1 deletion src/simd/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down
54 changes: 27 additions & 27 deletions tests/itf1788_tests/libieeep1788_elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down

0 comments on commit 36362f7

Please sign in to comment.