rust ffast-math (defunct, use lower)
no_std
| -rw-r--r-- | Cargo.toml | 3 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | src/lib.rs | 19 | ||||
| -rw-r--r-- | src/trait.rs | 4 |
4 files changed, 16 insertions, 13 deletions
@@ -7,4 +7,5 @@ repository = "https://github.com/bend-n/umath" authors = ["bend-n <[email protected]>"] edition = "2021" exclude = [".gitignore"] -categories = ["hardware-support", "mathematics",]
\ No newline at end of file +categories = ["hardware-support", "mathematics", "no-std", "no-std::no-alloc"] +keywords = ["fast", "math", "unsafe", "ffast-math", "float"]
\ No newline at end of file @@ -1,6 +1,7 @@ # umath: ffast-math, for rust. - +[](#nightlyness) +[](https://docs.rs/umath) Want to make your math *faster*? [<sup>*t&c apply</sup>](https://simonbyrne.github.io/notes/fastmath) @@ -9,8 +9,9 @@ //! ``` #![feature(core_intrinsics)] #![warn(clippy::pedantic, clippy::dbg_macro, clippy::use_self, missing_docs)] -use std::cmp::{PartialEq, PartialOrd}; -use std::ops::{ +#![no_std] +use core::cmp::{Ordering, PartialEq, PartialOrd}; +use core::ops::{ Add as add, AddAssign as add_assign, Deref, DerefMut, Div as div, DivAssign as div_assign, Mul as mul, MulAssign as mul_assign, Neg, Rem as rem, RemAssign as rem_assign, Sub as sub, SubAssign as sub_assign, @@ -33,14 +34,14 @@ use r#trait::FastFloat; #[derive(Copy, Clone, PartialEq)] pub struct FFloat<T>(T); -impl<T: FastFloat> std::fmt::Debug for FFloat<T> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl<T: FastFloat> core::fmt::Debug for FFloat<T> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:?}", self.0) } } -impl<T: FastFloat> std::fmt::Display for FFloat<T> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl<T: FastFloat> core::fmt::Display for FFloat<T> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.0) } } @@ -184,17 +185,17 @@ impl<T: FastFloat> PartialEq<T> for FFloat<T> { } impl<T: FastFloat> Eq for FFloat<T> {} impl<T: FastFloat> PartialOrd for FFloat<T> { - fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) } } impl<T: FastFloat> PartialOrd<T> for FFloat<T> { - fn partial_cmp(&self, other: &T) -> Option<std::cmp::Ordering> { + fn partial_cmp(&self, other: &T) -> Option<Ordering> { self.0.partial_cmp(other) } } impl<T: FastFloat> Ord for FFloat<T> { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> Ordering { self.check(); unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() } } diff --git a/src/trait.rs b/src/trait.rs index 7717cd6..7401848 100644 --- a/src/trait.rs +++ b/src/trait.rs @@ -1,9 +1,9 @@ -use std::intrinsics::{ +use core::intrinsics::{ fadd_fast as add, fdiv_fast as div, fmul_fast as mul, frem_fast as rem, fsub_fast as sub, }; macro_rules! meth { ($($name:ident)|+) => { - pub trait FastFloat: Copy + std::fmt::Display + std::fmt::Debug + std::ops::Neg<Output = Self> + std::cmp::PartialEq + std::cmp::PartialOrd { + pub trait FastFloat: Copy + core::fmt::Display + core::fmt::Debug + core::ops::Neg<Output = Self> + core::cmp::PartialEq + core::cmp::PartialOrd { $(#[doc(hidden)] unsafe fn $name(a: Self, b: Self) -> Self;)+ #[doc(hidden)] fn bad(self) -> bool; |