Move Float to separate crate

This commit is contained in:
Magnus Ulimoen 2021-03-22 16:17:27 +01:00
parent be984fbdac
commit 502679c9a1
7 changed files with 43 additions and 21 deletions

View File

@ -8,6 +8,7 @@ members = [
"shallow_water", "shallow_water",
"gridgeneration", "gridgeneration",
"heat-equation", "heat-equation",
"utils/float",
] ]
default-members = ["sbp", "euler", "maxwell", "shallow_water"] default-members = ["sbp", "euler", "maxwell", "shallow_water"]

View File

@ -12,11 +12,12 @@ rayon = { version = "1.3.0", optional = true }
sprs = { version = "0.10.0", optional = true, default-features = false } sprs = { version = "0.10.0", optional = true, default-features = false }
serde = { version = "1.0.115", optional = true, default-features = false, features = ["derive"] } serde = { version = "1.0.115", optional = true, default-features = false, features = ["derive"] }
num-traits = "0.2.14" num-traits = "0.2.14"
float = { path = "../utils/float" }
[features] [features]
# Use f32 as precision, default is f64 # Use f32 as precision, default is f64
f32 = [] f32 = ["float/f32"]
fast-float = [] fast-float = ["float/fast-float"]
sparse = ["sprs"] sparse = ["sprs"]
serde1 = ["serde", "ndarray/serde"] serde1 = ["serde", "ndarray/serde"]

View File

@ -3,20 +3,7 @@
#![feature(array_chunks)] #![feature(array_chunks)]
#![feature(const_fn_floating_point_arithmetic)] #![feature(const_fn_floating_point_arithmetic)]
/// Type used for floats, configure with the `f32` feature pub use float::{consts, Float};
#[cfg(feature = "f32")]
pub type Float = f32;
#[cfg(not(feature = "f32"))]
/// Type used for floats, configure with the `f32` feature
pub type Float = f64;
/// Associated constants for [`Float`]
pub mod consts {
#[cfg(feature = "f32")]
pub use std::f32::consts::*;
#[cfg(not(feature = "f32"))]
pub use std::f64::consts::*;
}
/// Grid and grid metrics /// Grid and grid metrics
pub mod grid; pub mod grid;

View File

@ -6,9 +6,7 @@ pub(crate) mod constmatrix;
pub(crate) use constmatrix::{ColVector, Matrix, RowVector}; pub(crate) use constmatrix::{ColVector, Matrix, RowVector};
#[cfg(feature = "fast-float")] #[cfg(feature = "fast-float")]
mod fastfloat; use float::FastFloat;
#[cfg(feature = "fast-float")]
use fastfloat::FastFloat;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub(crate) struct DiagonalMatrix<const B: usize> { pub(crate) struct DiagonalMatrix<const B: usize> {

12
utils/float/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "float"
version = "0.1.0"
authors = ["Magnus Ulimoen <magnus@ulimoen.dev>"]
edition = "2018"
[features]
f32 = []
fast-float = []
[dependencies]
num-traits = "0.2.14"

View File

@ -1,8 +1,8 @@
use super::*; use super::Float;
#[repr(transparent)] #[repr(transparent)]
#[derive(Copy, Clone, Debug, PartialEq, Default)] #[derive(Copy, Clone, Debug, PartialEq, Default)]
pub(crate) struct FastFloat(Float); pub struct FastFloat(Float);
use core::intrinsics::{fadd_fast, fdiv_fast, fmul_fast, fsub_fast}; use core::intrinsics::{fadd_fast, fdiv_fast, fmul_fast, fsub_fast};

23
utils/float/src/lib.rs Normal file
View File

@ -0,0 +1,23 @@
//! The Float type used throughout the ecosystem
#![cfg_attr(feature = "fast-float", feature(core_intrinsics))]
/// Type used for floats, configure with the `f32` feature
#[cfg(feature = "f32")]
pub type Float = f32;
#[cfg(not(feature = "f32"))]
/// Type used for floats, configure with the `f32` feature
pub type Float = f64;
/// Associated constants for [`Float`]
pub mod consts {
#[cfg(feature = "f32")]
pub use std::f32::consts::*;
#[cfg(not(feature = "f32"))]
pub use std::f64::consts::*;
}
#[cfg(feature = "fast-float")]
mod fastfloat;
#[cfg(feature = "fast-float")]
pub use fastfloat::FastFloat;