1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
//! Provides access to the [CODATA recommended values for physical constants][codata]. //! //! # Examples //! //! ``` //! use physical_constants; //! //! let epsilon_0 = physical_constants::ELECTRIC_CONSTANT; //! let mu_0 = physical_constants::MAG_CONSTANT; //! println!("speed of massless particles: {} m/s", 1f64/(epsilon_0*mu_0).sqrt()); //! println!("impedance of free space: {} Ω", (mu_0/epsilon_0).sqrt()); //! ``` //! //! [codata]: http://physics.nist.gov/cuu/Constants/ //! [codata 2014]: http://physics.nist.gov/cuu/Constants/Table/allascii.txt // Include the physical constants, which are generated by the build script. include!(concat!(env!("OUT_DIR"), "/table.rs")); #[cfg(test)] mod tests { use super::*; // Testing for exact equality of floating-point numbers is actually appropriate for once. #[test] fn test_exact_quantity() { // An exact quantity whose decimal expansion ends with "..." in the table assert_eq!(SPEED_OF_LIGHT_IN_VACUUM, 299792458f64); } #[test] fn test_no_exponent() { // A value that has no exponent in the listing assert_eq!(ATOMIC_MASS_CONSTANT_ENERGY_EQUIVALENT_IN_MEV, 931.4940954); } #[test] fn test_positive_exponent() { assert_eq!(BOLTZMANN_CONSTANT_IN_HZ_PER_K, 2.0836612e10); } #[test] fn test_negative_exponent() { assert_eq!(CLASSICAL_ELECTRON_RADIUS, 2.8179403227e-15); } #[test] fn test_negative_value() { assert_eq!(ELECTRON_CHARGE_TO_MASS_QUOTIENT, -1.758820024e11); } #[test] fn test_dimensionless_value() { assert_eq!(PROTON_ELECTRON_MASS_RATIO, 1836.15267389); } #[test] fn test_first_quantity() { // The first quantity listed in the table assert_eq!(LATTICE_SPACING_220_OF_SILICON, 192.0155714e-12); } #[test] fn test_last_quantity() { // The last quantity listed in the table assert_eq!(WIEN_WAVELENGTH_DISPLACEMENT_LAW_CONSTANT, 2.8977729e-3); } #[test] fn test_changed_name() { // This quantity is called "{220} lattice spacing of silicon" in the original listing. To get a valid identifier, which must not contain curly brackets and must not begin with a digit, its name has to be changed entirely, not just by a simple character replacement. This test checks that the new name came through as it should. assert_eq!(LATTICE_SPACING_220_OF_SILICON, 192.0155714e-12); } }