Skip to main content

use_astronomical_constants/
lib.rs

1#![forbid(unsafe_code)]
2
3//! Reusable astronomical constants expressed as plain `f64` values.
4
5/// Exact astronomical unit by IAU definition, in meters.
6pub const ASTRONOMICAL_UNIT: f64 = 149_597_870_700.0;
7
8/// Conventional light-year distance for one Julian year of light travel, in meters.
9pub const LIGHT_YEAR: f64 = 9.460_730_472_580_8e15;
10
11/// Approximate parsec distance, in meters.
12pub const PARSEC: f64 = 3.085_677_581_491_367e16;
13
14/// Measured solar mass, in kilograms.
15pub const SOLAR_MASS: f64 = 1.988_47e30;
16
17#[cfg(test)]
18mod tests {
19    use super::{ASTRONOMICAL_UNIT, LIGHT_YEAR, PARSEC, SOLAR_MASS};
20
21    fn runtime(value: f64) -> f64 {
22        value
23    }
24
25    #[test]
26    fn larger_astronomical_distances_exceed_smaller_ones() {
27        assert!(runtime(LIGHT_YEAR) > runtime(ASTRONOMICAL_UNIT));
28        assert!(runtime(PARSEC) > runtime(LIGHT_YEAR));
29    }
30
31    #[test]
32    fn representative_stellar_mass_is_positive() {
33        assert!(runtime(SOLAR_MASS) > 0.0);
34    }
35
36    #[test]
37    fn parsec_exceeds_astronomical_unit() {
38        assert!(runtime(PARSEC) > runtime(ASTRONOMICAL_UNIT));
39    }
40}