rust ffast-math (defunct, use lower)
-rw-r--r--src/lib.rs27
-rw-r--r--src/trait.rs4
2 files changed, 17 insertions, 14 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c74092c..f077f2e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,7 +27,7 @@ use r#trait::FastFloat;
/// assert_eq!(*result, 1136943.0);
/// # }
/// ```
-#[derive(Copy, Clone, PartialEq, PartialOrd)]
+#[derive(Copy, Clone, PartialEq)]
pub struct FFloat<T>(T);
impl<T: FastFloat> std::fmt::Debug for FFloat<T> {
@@ -162,31 +162,36 @@ assign!(sub_assign, sub);
// convenience
impl<T: FastFloat> Neg for FFloat<T> {
- type Output = FFloat<T>;
+ type Output = Self;
fn neg(self) -> Self::Output {
unsafe { Self::new(-self.0) }
}
}
-impl<T: FastFloat> Eq for FFloat<T> {}
-impl<T: FastFloat> Ord for FFloat<T> {
- fn cmp(&self, other: &Self) -> std::cmp::Ordering {
- self.check();
- unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() }
- }
-}
-
impl<T: FastFloat> PartialEq<T> for FFloat<T> {
fn eq(&self, other: &T) -> bool {
self.0.eq(other)
}
}
-
+impl<T: FastFloat> Eq for FFloat<T> {}
+impl<T: FastFloat> PartialOrd for FFloat<T> {
+ fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+ self.check();
+ other.check();
+ Some(unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() })
+ }
+}
impl<T: FastFloat> PartialOrd<T> for FFloat<T> {
fn partial_cmp(&self, other: &T) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(other)
}
}
+impl<T: FastFloat> Ord for FFloat<T> {
+ fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+ self.check();
+ unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() }
+ }
+}
#[cfg(test)]
mod tests {
diff --git a/src/trait.rs b/src/trait.rs
index 3e5a75e..96e19c9 100644
--- a/src/trait.rs
+++ b/src/trait.rs
@@ -1,11 +1,9 @@
-use std::cmp::{PartialEq, PartialOrd};
use std::intrinsics::{
fadd_fast as add, fdiv_fast as div, fmul_fast as mul, frem_fast as rem, fsub_fast as sub,
};
-use std::ops::Neg;
macro_rules! meth {
($($name:ident)|+) => {
- pub trait FastFloat: Copy + std::fmt::Display + std::fmt::Debug + Neg<Output = Self> + PartialEq + PartialOrd {
+ pub trait FastFloat: Copy + std::fmt::Display + std::fmt::Debug + std::ops::Neg<Output = Self> + std::cmp::PartialEq + std::cmp::PartialOrd {
$(#[doc(hidden)] unsafe fn $name(a: Self, b: Self) -> Self;)+
#[doc(hidden)]
fn bad(self) -> bool;