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    #[test]
22    fn larger_astronomical_distances_exceed_smaller_ones() {
23        assert!(LIGHT_YEAR > ASTRONOMICAL_UNIT);
24        assert!(PARSEC > LIGHT_YEAR);
25    }
26
27    #[test]
28    fn representative_stellar_mass_is_positive() {
29        assert!(SOLAR_MASS > 0.0);
30    }
31
32    #[test]
33    fn parsec_exceeds_astronomical_unit() {
34        assert!(PARSEC > ASTRONOMICAL_UNIT);
35    }
36}