Move FastFloat to separate crate (archival)
This commit is contained in:
		
							
								
								
									
										11
									
								
								utils/fast-float/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								utils/fast-float/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "fast-float"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
authors = ["Magnus Ulimoen <magnus@ulimoen.dev>"]
 | 
			
		||||
edition = "2018"
 | 
			
		||||
 | 
			
		||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
float = { path = "../float" }
 | 
			
		||||
num-traits = "0.2.14"
 | 
			
		||||
							
								
								
									
										123
									
								
								utils/fast-float/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								utils/fast-float/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,123 @@
 | 
			
		||||
#![no_std]
 | 
			
		||||
#![feature(core_intrinsics)]
 | 
			
		||||
 | 
			
		||||
use float::Float;
 | 
			
		||||
 | 
			
		||||
#[repr(transparent)]
 | 
			
		||||
#[derive(Copy, Clone, Debug, PartialEq, Default)]
 | 
			
		||||
pub struct FastFloat(Float);
 | 
			
		||||
 | 
			
		||||
use core::intrinsics::{fadd_fast, fdiv_fast, fmul_fast, fsub_fast};
 | 
			
		||||
 | 
			
		||||
impl core::ops::Mul for FastFloat {
 | 
			
		||||
    type Output = Self;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn mul(self, o: Self) -> Self::Output {
 | 
			
		||||
        unsafe { Self(fmul_fast(self.0, o.0)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Mul<Float> for FastFloat {
 | 
			
		||||
    type Output = FastFloat;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn mul(self, o: Float) -> Self::Output {
 | 
			
		||||
        unsafe { Self(fmul_fast(self.0, o)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Mul<FastFloat> for Float {
 | 
			
		||||
    type Output = FastFloat;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn mul(self, o: FastFloat) -> Self::Output {
 | 
			
		||||
        unsafe { FastFloat(fmul_fast(self, o.0)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Add<FastFloat> for FastFloat {
 | 
			
		||||
    type Output = FastFloat;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn add(self, o: FastFloat) -> Self::Output {
 | 
			
		||||
        unsafe { Self(fadd_fast(self.0, o.0)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Add<Float> for FastFloat {
 | 
			
		||||
    type Output = FastFloat;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn add(self, o: Float) -> Self::Output {
 | 
			
		||||
        unsafe { Self(fadd_fast(self.0, o)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Add<FastFloat> for Float {
 | 
			
		||||
    type Output = FastFloat;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn add(self, o: FastFloat) -> Self::Output {
 | 
			
		||||
        unsafe { FastFloat(fadd_fast(self, o.0)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Sub for FastFloat {
 | 
			
		||||
    type Output = Self;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn sub(self, o: FastFloat) -> Self::Output {
 | 
			
		||||
        unsafe { Self(fsub_fast(self.0, o.0)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Div for FastFloat {
 | 
			
		||||
    type Output = Self;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn div(self, o: FastFloat) -> Self::Output {
 | 
			
		||||
        unsafe { Self(fdiv_fast(self.0, o.0)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::MulAssign<FastFloat> for FastFloat {
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn mul_assign(&mut self, o: FastFloat) {
 | 
			
		||||
        unsafe {
 | 
			
		||||
            self.0 = fmul_fast(self.0, o.0);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl core::ops::Mul for &FastFloat {
 | 
			
		||||
    type Output = FastFloat;
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn mul(self, o: Self) -> Self::Output {
 | 
			
		||||
        unsafe { FastFloat(fmul_fast(self.0, o.0)) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<Float> for FastFloat {
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn from(f: Float) -> Self {
 | 
			
		||||
        Self(f)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
impl From<FastFloat> for Float {
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn from(f: FastFloat) -> Self {
 | 
			
		||||
        f.0
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mod numt {
 | 
			
		||||
    use super::{FastFloat, Float};
 | 
			
		||||
    use num_traits::identities::{One, Zero};
 | 
			
		||||
 | 
			
		||||
    impl One for FastFloat {
 | 
			
		||||
        fn one() -> Self {
 | 
			
		||||
            Self(Float::one())
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    impl Zero for FastFloat {
 | 
			
		||||
        fn zero() -> Self {
 | 
			
		||||
            Self(Float::zero())
 | 
			
		||||
        }
 | 
			
		||||
        fn is_zero(&self) -> bool {
 | 
			
		||||
            self.0.is_zero()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -6,7 +6,5 @@ edition = "2018"
 | 
			
		||||
 | 
			
		||||
[features]
 | 
			
		||||
f32 = []
 | 
			
		||||
fast-float = []
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
num-traits = "0.2.14"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
//! The Float type used throughout the ecosystem
 | 
			
		||||
#![no_std]
 | 
			
		||||
#![cfg_attr(feature = "fast-float", feature(core_intrinsics))]
 | 
			
		||||
#![forbid(unsafe_code)]
 | 
			
		||||
 | 
			
		||||
/// Type used for floats, configure with the `f32` feature
 | 
			
		||||
#[cfg(feature = "f32")]
 | 
			
		||||
@@ -16,8 +16,3 @@ pub mod consts {
 | 
			
		||||
    #[cfg(not(feature = "f32"))]
 | 
			
		||||
    pub use core::f64::consts::*;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "fast-float")]
 | 
			
		||||
mod fastfloat;
 | 
			
		||||
#[cfg(feature = "fast-float")]
 | 
			
		||||
pub use fastfloat::FastFloat;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user