Move Float to separate crate
This commit is contained in:
parent
be984fbdac
commit
502679c9a1
|
@ -8,6 +8,7 @@ members = [
|
|||
"shallow_water",
|
||||
"gridgeneration",
|
||||
"heat-equation",
|
||||
"utils/float",
|
||||
]
|
||||
|
||||
default-members = ["sbp", "euler", "maxwell", "shallow_water"]
|
||||
|
|
|
@ -12,11 +12,12 @@ rayon = { version = "1.3.0", optional = true }
|
|||
sprs = { version = "0.10.0", optional = true, default-features = false }
|
||||
serde = { version = "1.0.115", optional = true, default-features = false, features = ["derive"] }
|
||||
num-traits = "0.2.14"
|
||||
float = { path = "../utils/float" }
|
||||
|
||||
[features]
|
||||
# Use f32 as precision, default is f64
|
||||
f32 = []
|
||||
fast-float = []
|
||||
f32 = ["float/f32"]
|
||||
fast-float = ["float/fast-float"]
|
||||
sparse = ["sprs"]
|
||||
serde1 = ["serde", "ndarray/serde"]
|
||||
|
||||
|
|
|
@ -3,20 +3,7 @@
|
|||
#![feature(array_chunks)]
|
||||
#![feature(const_fn_floating_point_arithmetic)]
|
||||
|
||||
/// 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::*;
|
||||
}
|
||||
pub use float::{consts, Float};
|
||||
|
||||
/// Grid and grid metrics
|
||||
pub mod grid;
|
||||
|
|
|
@ -6,9 +6,7 @@ pub(crate) mod constmatrix;
|
|||
pub(crate) use constmatrix::{ColVector, Matrix, RowVector};
|
||||
|
||||
#[cfg(feature = "fast-float")]
|
||||
mod fastfloat;
|
||||
#[cfg(feature = "fast-float")]
|
||||
use fastfloat::FastFloat;
|
||||
use float::FastFloat;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct DiagonalMatrix<const B: usize> {
|
||||
|
|
|
@ -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"
|
|
@ -1,8 +1,8 @@
|
|||
use super::*;
|
||||
use super::Float;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[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};
|
||||
|
|
@ -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;
|
Loading…
Reference in New Issue