use_physical_constants/
lib.rs1#![forbid(unsafe_code)]
2
3pub const SPEED_OF_LIGHT: f64 = 299_792_458.0;
7
8pub const PLANCK_CONSTANT: f64 = 6.626_070_15e-34;
10
11pub const REDUCED_PLANCK_CONSTANT: f64 = 1.054_571_817e-34;
13
14pub const ELEMENTARY_CHARGE: f64 = 1.602_176_634e-19;
16
17pub const BOLTZMANN_CONSTANT: f64 = 1.380_649e-23;
19
20pub const AVOGADRO_CONSTANT: f64 = 6.022_140_76e23;
22
23pub const FINE_STRUCTURE_CONSTANT: f64 = 7.297_352_564_3e-3;
25
26pub const GRAVITATIONAL_CONSTANT: f64 = 6.674_30e-11;
28
29pub const VACUUM_PERMITTIVITY: f64 = 8.854_187_812_8e-12;
31
32pub const VACUUM_PERMEABILITY: f64 = 1.256_637_062_12e-6;
34
35pub const STEFAN_BOLTZMANN_CONSTANT: f64 = 5.670_374_419e-8;
37
38#[cfg(test)]
39mod tests {
40 use core::f64::consts::TAU;
41
42 use super::{
43 PLANCK_CONSTANT, REDUCED_PLANCK_CONSTANT, SPEED_OF_LIGHT, STEFAN_BOLTZMANN_CONSTANT,
44 };
45
46 fn runtime(value: f64) -> f64 {
47 value
48 }
49
50 fn approx_eq(left: f64, right: f64, relative_tolerance: f64) {
51 let scale = left.abs().max(right.abs()).max(1.0);
52 let delta = (left - right).abs();
53
54 assert!(
55 delta <= relative_tolerance * scale,
56 "left={left:e} right={right:e} delta={delta:e} rel_tol={relative_tolerance:e}"
57 );
58 }
59
60 #[test]
61 fn reduced_planck_matches_h_over_tau() {
62 approx_eq(REDUCED_PLANCK_CONSTANT, PLANCK_CONSTANT / TAU, 1.0e-9);
63 }
64
65 #[test]
66 fn representative_constants_are_positive() {
67 assert!(runtime(SPEED_OF_LIGHT) > 0.0);
68 assert!(runtime(PLANCK_CONSTANT) > 0.0);
69 assert!(runtime(STEFAN_BOLTZMANN_CONSTANT) > 0.0);
70 }
71}