stormath/
lib.rs

1
2// Copyright (C) 2024, NTNU
3// Author: Jarle Vinje Kramer <jarlekramer@gmail.com; jarle.a.kramer@ntnu.no>
4// License: GPL v3.0 (see separate file LICENSE or https://www.gnu.org/licenses/gpl-3.0.html)
5
6//! Collection of common mathematical utility functions.
7//!
8//! The library is developed in parallel to, and for, the
9//! [Stormbird library](https://github.com/NTNU-IMT/stormbird). The functions available is closely
10//! connected to what is needed here. However, the implementation of the functionality in this crate
11//! is such that it may also be useful in other contexts. It is therefore kept as a separate crate.
12
13pub mod interpolation;
14pub mod integration;
15pub mod smoothing;
16pub mod statistics;
17pub mod array_generation;
18pub mod finite_difference;
19pub mod spatial_vector;
20pub mod special_functions;
21pub mod solvers;
22pub mod matrix;
23pub mod optimize;
24pub mod rigid_body_motion;
25pub mod error;
26
27pub mod type_aliases {
28    //! Type aliase to easy switch between different floating point number represntations
29
30    #[cfg(feature = "single_precision")]
31    pub type Float = f32;
32
33    #[cfg(not(feature = "single_precision"))]
34    pub type Float = f64;
35}
36
37pub mod consts {
38    //! Different constant. Defined so that it should be easy load these with the Float type alias
39    use super::type_aliases::Float;
40
41    #[cfg(feature = "single_precision")]
42    pub const PI: Float = std::f32::consts::PI;
43    #[cfg(feature = "single_precision")]
44    pub const TAU: Float = std::f32::consts::TAU;
45    #[cfg(feature = "single_precision")]
46    pub const INFINITY: Float = std::f32::INFINITY;
47    #[cfg(feature = "single_precision")]
48    pub const MIN_POSITIVE: Float = std::f32::MIN_POSITIVE;
49    #[cfg(feature = "single_precision")]
50    pub const MIN: Float = std::f32::MIN;
51
52    #[cfg(not(feature = "single_precision"))]
53    pub const PI: Float = std::f64::consts::PI;
54    #[cfg(not(feature = "single_precision"))]
55    pub const TAU: Float = std::f64::consts::TAU;
56    #[cfg(not(feature = "single_precision"))]
57    pub const INFINITY: Float = std::f64::INFINITY;
58    #[cfg(not(feature = "single_precision"))]
59    pub const MIN_POSITIVE: Float = std::f64::MIN_POSITIVE;
60    #[cfg(not(feature = "single_precision"))]
61    pub const MIN: Float = std::f64::MIN;
62
63}