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 approx_eq(left: f64, right: f64, relative_tolerance: f64) {
47 let scale = left.abs().max(right.abs()).max(1.0);
48 let delta = (left - right).abs();
49
50 assert!(
51 delta <= relative_tolerance * scale,
52 "left={left:e} right={right:e} delta={delta:e} rel_tol={relative_tolerance:e}"
53 );
54 }
55
56 #[test]
57 fn reduced_planck_matches_h_over_tau() {
58 approx_eq(REDUCED_PLANCK_CONSTANT, PLANCK_CONSTANT / TAU, 1.0e-9);
59 }
60
61 #[test]
62 fn representative_constants_are_positive() {
63 assert!(SPEED_OF_LIGHT > 0.0);
64 assert!(PLANCK_CONSTANT > 0.0);
65 assert!(STEFAN_BOLTZMANN_CONSTANT > 0.0);
66 }
67}