constants 0.3.1

A convenience library of constants
Documentation
#![no_std]

//! `constants` is a big (and growing) library of mathematical and physical constants. While in no
//! way revolutionary, I hope that I can save you a few keystrokes with this.
//!
//! # Sources
//!
//! The source for this data is mainly Wikipedia right now, so expect these to change a little bit.
//! What I mean by this is that I will try to find a more reputable source for each constant,
//! hopefully one that yields higher precision.

// re-exports of the corelib constants for easy access
pub use core::f64::consts::{E, PI, TAU};

/// The precision of the float can be changed using this type. This will be relevant once 128-bit
/// floats come to stable.
type Float = f64;

/// Convenience function to convert metres to feet.
pub fn metres_to_feet(metres: Float) -> Float {
    metres * crate::length::metric::METRES_TO_FEET
}

/// See [`metres_to_feet()`].
pub fn feet_to_metres(feet: Float) -> Float {
    feet / crate::length::metric::METRES_TO_FEET
}

/// In `m/s^2`.
pub mod gravitational_pull {
    use crate::Float;

    pub mod earth {
        use crate::Float;

        pub const STANDARD: Float = 9.80665;
        pub const EQUATORIAL: Float = 9.7803267715;
    }

    pub const MOON: Float = 1.622;

    pub const MERCURY: Float = 3.7;
    pub const VENUS: Float = 8.87;
    pub const MARS: Float = 3.72076;
    pub const JUPITER: Float = 24.79;
    pub const SATURN: Float = 10.44;
    pub const URANUS: Float = 8.69;
    pub const NEPTUNE: Float = 11.15;
}

pub mod length {
    pub mod metric {
        use crate::Float;

        pub const METRES_TO_FEET: Float = 3.28084;
    }
}

/// In `m/s`.
pub const SPEED_OF_LIGHT: Float = 299792458.0;

#[cfg(test)]
mod tests {
    #[test]
    fn metres_to_feet() {
        assert_eq!(super::metres_to_feet(1.0), 3.28084)
    }

    #[test]
    fn feet_to_metres() {
        assert_eq!(super::feet_to_metres(3.28084), 1.0)
    }
}