### Singleton Type Behavior Example Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Demonstrates that different names for the same physical constant refer to the same singleton object. ```julia SpeedOfLightInVacuum === c_0 # true ``` -------------------------------- ### Hubble Constant Unit Conversion Example Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Demonstrates a unit conversion for the Hubble constant, using the speed of light (`c_0`) as an example. This converts `c_0` to km/s/Mpc. ```julia # Hubble constant unit conversion (if H0 were c_0) uconvert(u"km/s/Mpc", float(c_0)) ``` -------------------------------- ### Ideal Gas Law Calculation Example Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Demonstrates how to use the molar gas constant (R) in an ideal gas law calculation (PV = nRT). Requires importing the CODATA2022 module. ```julia using PhysicalConstants.CODATA2022 # Ideal gas law: PV = nRT # For 1 mole of gas at STP (T=273.15K, P=1 atm) # V = nRT/P = 1 * R * 273.15 / 101325 ``` -------------------------------- ### Get Vacuum Electric Permittivity (ε_0) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the vacuum electric permittivity. Used in Coulomb's law and Maxwell's equations. ```julia using PhysicalConstants.CODATA2022 float(ε_0) # Returns: 8.8541878188e-12 F m^-1 # Coulomb's law: F = 1/(4π*ε_0) * q1*q2/r² import PhysicalConstants.CODATA2022: ε_0 coulomb_k = 1 / (4 * π * ε_0) ``` -------------------------------- ### Get Wien Wavelength Displacement Law Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Wien wavelength displacement law constant (b) using the CODATA2022 module. An example of calculating peak wavelength is shown. ```julia using PhysicalConstants.CODATA2022 float(b) # Returns: 2.897771955e-3 m K # Wien's displacement law: λ_peak = b / T # Peak wavelength for blackbody at 5000 K peak_wavelength = float(b) / 5000u"K" ``` -------------------------------- ### Get Characteristic Impedance of Vacuum (Z_0) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the characteristic impedance of vacuum. Useful for calculations involving electromagnetic waves in free space. ```julia using PhysicalConstants.CODATA2022 float(Z_0) # Returns: 376.730313412 Ω # Related to μ_0, ε_0, and c_0 import PhysicalConstants.CODATA2022: Z_0, µ_0, ε_0 # Z_0 ≈ √(μ_0 / ε_0) ``` -------------------------------- ### Scoped Access to Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Access constants with scoped module names. This example shows how to get the float value of the speed of light. ```julia import PhysicalConstants.CODATA2022 value = float(PhysicalConstants.CODATA2022.c_0) ``` -------------------------------- ### Get Measurement with Uncertainty Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Retrieve constants as a measurement type, which includes their uncertainty. You can specify the precision for the measurement. ```julia measurement(G) ``` ```julia measurement(Float32, G) ``` ```julia measurement(BigFloat, G) ``` -------------------------------- ### Add PhysicalConstants Package Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/docs/src/index.md Install the latest version of the PhysicalConstants.jl package using the Julia package manager. ```julia pkg> add PhysicalConstants ``` -------------------------------- ### Get Float32 Representation of a Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Demonstrates how to get the Float32 representation of a physical constant. This can be used when memory or performance is critical and reduced precision is acceptable. ```julia using PhysicalConstants.CODATA2014 # Float32 float(Float32, ElectronMass) ``` -------------------------------- ### Get Standard Atmosphere Pressure Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the standard atmosphere pressure (atm) using the CODATA2022 module. Includes an example of converting to other pressure units. ```julia using PhysicalConstants.CODATA2022 float(atm) # Returns: 101325.0 Pa # Convert to other pressure units import PhysicalConstants.CODATA2022: atm pressure_bar = uconvert(u"bar", float(atm)) ``` -------------------------------- ### Get Constants with Uncertainty Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/docs/src/usage.md Retrieve physical constants along with their standard uncertainties using the `measurement()` function. Requires the `Measurements` package. ```jldoctest julia> using Measurements julia> import PhysicalConstants.CODATA2022: h, ħ julia> measurement(ħ) 1.0545718176461565e-34 ± 0.0 J s julia> measurement(Float32, ħ) 1.0545718e-34 ± 0.0 J s julia> measurement(BigFloat, ħ) 1.054571817646156391262428003302280744722826330020413122421923470598435912734741e-34 ± 0.0 J s julia> measurement(BigFloat, ħ) / (measurement(BigFloat, h) / (2 * big(pi))) 1.0 ± 0.0 ``` -------------------------------- ### Get BigFloat Representation of a Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Illustrates how to obtain a BigFloat representation of a physical constant, allowing for arbitrary precision arithmetic. ```julia using PhysicalConstants.CODATA2014 # BigFloat float(BigFloat, ElectronMass) ``` -------------------------------- ### Get Vacuum Magnetic Permeability (µ_0) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the vacuum magnetic permeability. Used in electromagnetic calculations and Maxwell's equations. ```julia using PhysicalConstants.CODATA2022 float(µ_0) # Returns: 1.25663706127e-6 N A^-2 # Relationship with speed of light and permittivity import PhysicalConstants.CODATA2022: µ_0, ε_0, c_0 # c_0 ≈ 1/√(ε_0 * µ_0) ``` -------------------------------- ### Get Standard Acceleration of Gravitation (g_n) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the standard acceleration due to gravity. Useful for calculating weight force. ```julia using PhysicalConstants.CODATA2022 float(g_n) # Returns: 9.80665 m s^-2 # Weight force mass = 10u"kg" weight = mass * float(g_n) ``` -------------------------------- ### Get Electron Rest Mass (m_e) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the rest mass of an electron. Fundamental for atomic and quantum electrodynamics calculations. ```julia using PhysicalConstants.CODATA2022 float(m_e) # Returns: 9.1093837139e-31 kg # Compton wavelength: λ_c = h / (m_e * c) import PhysicalConstants.CODATA2022: m_e, h, c_0 compton_wavelength = float(h) / (float(m_e) * float(c_0)) ``` -------------------------------- ### Get Proton Rest Mass (m_p) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the rest mass of a proton. Fundamental for nuclear and particle physics calculations. ```julia using PhysicalConstants.CODATA2022 float(m_p) # Returns: 1.67262192595e-27 kg # Proton to electron mass ratio import PhysicalConstants.CODATA2022: m_p, m_e ratio = ustrip(float(m_p)) / ustrip(float(m_e)) # Returns: ≈ 1836.15 ``` -------------------------------- ### Get Float64 Representation of a Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Shows how to obtain the Float64 representation of a physical constant. This is useful for calculations where precision is not a primary concern. ```julia using PhysicalConstants.CODATA2014 # Float64 float(ElectronMass) # Returns: 9.10938356e-31 kg ``` -------------------------------- ### Get Boltzmann Constant (k_B) and Calculate Thermal Energy Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieve the nominal value of the Boltzmann constant and use it to calculate thermal energy at a given temperature. ```julia using PhysicalConstants.CODATA2022 float(k_B) # Returns: 1.380649e-23 J K^-1 # Thermal energy at room temperature (T = 300 K) thermal_energy = float(k_B) * 300u"K" ``` -------------------------------- ### Get Molar Gas Constant (R) in J/(mol·K) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the molar gas constant. Requires importing the CODATA2022 module. ```julia using PhysicalConstants.CODATA2022 float(R) # Returns: 8.31446261815324 J mol^-1 K^-1 ``` -------------------------------- ### Get Speed of Light in Vacuum (c_0) as Float Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieve the nominal value of the speed of light in vacuum as a floating-point number. Supports different precision levels. ```julia using PhysicalConstants.CODATA2022 # Use as a quantity float(c_0) # Returns: 2.99792458e8 m s^-1 # Different precisions float(Float32, c_0) float(BigFloat, c_0) # Use in calculations energy = 2 * c_0^2 # Einstein's E = mc^2 ``` -------------------------------- ### Get Neutron Mass (m_n) in kg Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the neutron rest mass in kilograms. Requires importing the CODATA2022 module. ```julia using PhysicalConstants.CODATA2022 float(m_n) # Returns: 1.67492750056e-27 kg ``` -------------------------------- ### Get Atomic Mass Constant (m_u) in kg Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the atomic mass constant (unified atomic mass unit) in kilograms. Requires importing the CODATA2022 module. ```julia using PhysicalConstants.CODATA2022 float(m_u) # Returns: 1.66053906892e-27 kg ``` -------------------------------- ### Get Wien Frequency Displacement Law Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Wien frequency displacement law constant (b′) using the CODATA2022 module. Wien's law in the frequency domain is shown as a comment. ```julia using PhysicalConstants.CODATA2022 float(b′) # Returns: 5.878925757e10 Hz K^-1 # Wien's law in frequency: ν_peak = b' * T ``` -------------------------------- ### Displaying and Using a Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2018-module.md Demonstrates how to display a constant's details and use it in a calculation. Requires importing specific constants or the entire module. ```julia using PhysicalConstants.CODATA2018 # Display a constant PlanckConstant # Output: # Planck constant (h) # Value = 6.62607015e-34 J s # Standard uncertainty = (exact) # Relative standard uncertainty = (exact) # Reference = CODATA 2018 # Use in calculations import PhysicalConstants.CODATA2018: c_0, h frequency = 1e15u"Hz" energy = h * frequency ``` -------------------------------- ### Performing Physical Calculations Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Demonstrates how to use physical constants in calculations, such as computing the Compton wavelength or the reciprocal of the fine-structure constant. This highlights the package's integration with Unitful for dimensional analysis. ```julia using PhysicalConstants.CODATA2022 # Compton wavelength import PhysicalConstants.CODATA2022: h, c_0, m_e λ_c = float(h) / (float(m_e) * float(c_0)) # → 2.426310235e-12 m # Fine structure constant reciprocal import PhysicalConstants.CODATA2022: α α_inv = 1 / ustrip(float(α)) # → 137.035999084 ``` -------------------------------- ### Import All Datasets Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Import all available CODATA datasets. This allows access to constants from multiple versions simultaneously. ```julia using PhysicalConstants ``` -------------------------------- ### Physics Calculations with CODATA2018 Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2018-module.md Demonstrates physics calculations using CODATA2018 constants, including Planck length and hydrogen atom fine structure splitting. Requires importing specific constants. ```julia using PhysicalConstants.CODATA2018 # Planck length: l_p = √(ℏc/G) import PhysicalConstants.CODATA2018: ħ, c_0, G planck_length = sqrt(float(ħ) * float(c_0) / float(G)) # Fine structure splitting of hydrogen atom import PhysicalConstants.CODATA2018: α, R_∞, h delta_E = 2 * float(α)^2 * float(R_∞) * float(h) * float(c_0) ``` -------------------------------- ### Automatic Type Promotion with Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Shows how PhysicalConstants integrate with Julia's promotion system, automatically promoting types during arithmetic operations involving constants and other quantities. ```julia using PhysicalConstants.CODATA2022, Unitful c = float(SpeedOfLightInVacuum) # Quantity{Float64,...} v = 100.5f6u"m/s" # Quantity{Float32,...} result = c + v # Automatically promotes to Quantity{Float64,...} ``` -------------------------------- ### Explicit Conversion of Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Demonstrates explicit conversion of constants, both to different numerical types (e.g., Float64, Float32) and to different units using `uconvert`. ```julia using PhysicalConstants.CODATA2022 # Convert dimensionless constant to numeric type α_f64 = convert(Float64, FineStructureConstant) α_f32 = convert(Float32, FineStructureConstant) # Unit conversion using Unitful c_km_s = uconvert(u"km/s", float(SpeedOfLightInVacuum)) ``` -------------------------------- ### Using Constants with Measurement Uncertainty Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2018-module.md Demonstrates how to use constants that have measured uncertainties, such as the Newtonian Constant of Gravitation. Requires the Measurements package. ```julia using PhysicalConstants.CODATA2018, Measurements # Constants with measured uncertainties measurement(NewtonianConstantOfGravitation) # Returns: 6.6743e-11 ± 1.5e-15 m^3 kg^-1 s^-2 # Comparison: this constant is much less precisely known than # electromagnetic constants which are exact in CODATA 2018 ``` -------------------------------- ### Import CODATA2014 Module Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Import the entire CODATA2014 module or specific constants. This is the first step to access the defined physical constants. ```julia using PhysicalConstants.CODATA2014 # or using PhysicalConstants.CODATA2014: c_0, h, N_A # import specific constants ``` -------------------------------- ### Comparing Constants Across Datasets Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Shows how to import and compare the same physical constant from different CODATA versions (e.g., 2014, 2018, 2022). This is useful for tracking historical changes and understanding data evolution. ```julia import PhysicalConstants.CODATA2022: h as h_2022 import PhysicalConstants.CODATA2018: h as h_2018 import PhysicalConstants.CODATA2014: h as h_2014 # Compare historical values println("Planck constant over time:") println("2014: ", float(h_2014)) println("2018: ", float(h_2018)) println("2022: ", float(h_2022)) ``` -------------------------------- ### Get Fine Structure Constant (α) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the fine structure constant. Requires importing the CODATA2022 module. ```julia using PhysicalConstants.CODATA2022 float(α) # Returns: 7.2973525643e-3 (≈ 1/137) ``` -------------------------------- ### Import CODATA Datasets Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Import specific CODATA datasets as submodules. CODATA2022 is recommended for new work, while CODATA2018 and CODATA2014 are available for reproducibility and historical comparison. ```julia using PhysicalConstants.CODATA2022 # Recommended using PhysicalConstants.CODATA2018 # For 2018 data using PhysicalConstants.CODATA2014 # For 2014 data ``` -------------------------------- ### Converting Units of Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Illustrates how to convert a physical constant's value to different units using `uconvert` from the Unitful package. This is essential for ensuring compatibility in calculations involving different unit systems. ```julia using PhysicalConstants.CODATA2022, Unitful # Convert constant to different units c = float(SpeedOfLightInVacuum) c_per_ns = uconvert(u"km/ns", c) # → 299.792458 km ns^-1 E_J = float(PlanckConstant) * 1e15u"Hz" E_eV = uconvert(u"eV", E_J) # Convert photon energy to eV ``` -------------------------------- ### Get Bohr Radius (a_0) in meters Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Bohr radius in meters. Requires importing the CODATA2022 module. ```julia using PhysicalConstants.CODATA2022 float(a_0) # Returns: 5.29177210544e-11 m ``` -------------------------------- ### Display a CODATA 2014 Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Demonstrates how to display a physical constant from the CODATA 2014 dataset, including its value, standard uncertainty, and relative standard uncertainty. Note that some constants have non-zero uncertainties in this dataset. ```julia using PhysicalConstants.CODATA2014 # Display a constant PlanckConstant # Output: # Planck constant (h) # Value = 6.62607040e-34 J s # Standard uncertainty = 8.1e-42 J s # Relative standard uncertainty = 1.2e-8 # Reference = CODATA 2014 # Note the non-zero uncertainty, unlike later datasets ``` -------------------------------- ### Get Elementary Charge (e) as Float Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieve the nominal value of the elementary charge as a floating-point number. Useful for electrostatics calculations. ```julia using PhysicalConstants.CODATA2022 float(e) # Returns: 1.602176634e-19 C # Use in electrostatics calculations import PhysicalConstants.CODATA2022: e, ε_0 coulomb_constant = 1 / (4π * ε_0) ``` -------------------------------- ### Importing Physical Constants for Shorter Typing Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Import specific physical constants like `c_0`, `h`, `m_e`, and `k_B` from `PhysicalConstants.CODATA2022` for faster and more convenient typing in interactive sessions (REPL). ```julia import PhysicalConstants.CODATA2022: c_0, h, m_e, k_B # Faster typing in REPL ``` -------------------------------- ### Comparing Constants Across CODATA Datasets Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2018-module.md Illustrates how to compare the values of constants between different CODATA datasets (e.g., CODATA2022 and CODATA2018). Requires importing both modules and aliasing constants to avoid name conflicts. ```julia using PhysicalConstants.CODATA2022, PhysicalConstants.CODATA2018 import PhysicalConstants.CODATA2022: ε_0 as ε_0_22, m_e as m_e_22 import PhysicalConstants.CODATA2018: ε_0 as ε_0_18, m_e as m_e_18 # Compare values difference = float(m_e_22) - float(m_e_18) # Returns: 1.24e-42 kg (very small difference) # Both datasets have same electron mass values in last significant figures ``` -------------------------------- ### Import CODATA2022 Module Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Import the entire CODATA2022 module or specific constants. ```julia using PhysicalConstants.CODATA2022 # or using PhysicalConstants.CODATA2022: c_0, h, N_A # import specific constants ``` -------------------------------- ### Select CODATA 2018 Dataset Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Import the CODATA 2018 dataset for reproducibility with publications from that year. ```julia using PhysicalConstants.CODATA2018 # For reproducibility with 2018 publications ``` -------------------------------- ### Accessing Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Demonstrates how to access physical constants as quantities with units using the `float()` function. This is the most common way to retrieve constant values. ```julia using PhysicalConstants.CODATA2022 # Access as Quantity with units c = float(SpeedOfLightInVacuum) # → 2.99792458e8 m s^-1 h = float(PlanckConstant) # → 6.62607015e-34 J s ``` -------------------------------- ### Get Stefan-Boltzmann Constant Value Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Stefan-Boltzmann constant (σ) using the CODATA2022 module. The Stefan-Boltzmann law is provided as a comment. ```julia using PhysicalConstants.CODATA2022 float(σ) # Returns: 5.670374419e-8 W m^-2 K^-4 # Stefan-Boltzmann law: j = σ * T⁴ # Power radiated by blackbody at temperature T (in K) ``` -------------------------------- ### Get Bohr Magneton Value Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Bohr magneton (µ_B) using the CODATA2022 module. Ensure the module is imported before use. ```julia using PhysicalConstants.CODATA2022 float(µ_B) # Returns: 9.2740100657e-24 J T^-1 ``` -------------------------------- ### Import CODATA 2022 Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Import the recommended CODATA 2022 dataset for accessing physical constants. This is the standard way to include the latest recommended values. ```julia using PhysicalConstants.CODATA2022 ``` -------------------------------- ### Perform Arithmetic with Physical Constants and Quantities Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Illustrates seamless arithmetic operations between physical constants (treated as quantities) and other `Unitful.jl` quantities, such as calculating energy using E=mc². ```julia using PhysicalConstants.CODATA2022, Unitful mass = 1000u"kg" energy = mass * float(SpeedOfLightInVacuum)^2 ``` -------------------------------- ### Get Planck Constant (h) as Float and Measurement Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieve the nominal value of Planck's constant as a floating-point number or as a measurement including its uncertainty. ```julia using PhysicalConstants.CODATA2022, Measurements float(h) # Returns: 6.62607015e-34 J s # Measurement with uncertainty (zero in this case) measurement(h) # Returns: 6.62607015e-34 ± 0.0 J s ``` -------------------------------- ### Checking Available Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Use `using PhysicalConstants.CODATA2022` to import all exported constants and then use the `names()` function to list all available constants within the module. ```julia using PhysicalConstants.CODATA2022 # See what's exported names(PhysicalConstants.CODATA2022) ``` -------------------------------- ### Import Historical CODATA Datasets Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Import constants from specific historical CODATA datasets. ```julia using PhysicalConstants.CODATA2018 using PhysicalConstants.CODATA2014 ``` -------------------------------- ### Get Rydberg Constant Value Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Rydberg constant (R_∞) using the CODATA2022 module. The Rydberg formula is also shown as a comment. ```julia using PhysicalConstants.CODATA2022 float(R_∞) # Returns: 1.0973731568157e7 m^-1 # Rydberg formula: 1/λ = R_∞ * Z² * (1/n₁² - 1/n₂²) ``` -------------------------------- ### Importing CODATA2018 Module Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2018-module.md Import the entire CODATA2018 module or specific constants. This is the first step before using any constants from this dataset. ```julia using PhysicalConstants.CODATA2018 # or using PhysicalConstants.CODATA2018: c_0, h, N_A # import specific constants ``` -------------------------------- ### Speed of Light Conversion to km/s Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md A concise snippet to convert the speed of light constant (`c_0`) to kilometers per second using `uconvert`. ```julia # Speed of light in km/s uconvert(u"km/s", float(c_0)) ``` -------------------------------- ### Get Thomson Cross Section Value Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Thomson cross section (σ_e) using the CODATA2022 module. This constant is used in scattering calculations. ```julia using PhysicalConstants.CODATA2022 float(σ_e) # Returns: 6.6524587051e-29 m^2 ``` -------------------------------- ### Track Uncertainty with Measurements.jl Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Shows how to use the Measurements.jl package to work with physical constants that have significant uncertainties. This allows for proper propagation of uncertainty in calculations. ```julia using PhysicalConstants.CODATA2014, Measurements # Constants with significant uncertainties measurement(PlanckConstant) # Returns: 6.62607040e-34 ± 8.1e-42 J s measurement(BoltzmannConstant) # Returns: 1.38064852e-23 ± 7.9e-30 J K^-1 measurement(AvogadroConstant) # Returns: 6.022140857e23 ± 7.4e15 mol^-1 ``` -------------------------------- ### Get Avogadro Constant (N_A) in mol⁻¹ Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieves the nominal value of the Avogadro constant, representing the number of particles per mole. Requires importing the CODATA2022 module. ```julia using PhysicalConstants.CODATA2022 float(N_A) # Returns: 6.02214076e23 mol^-1 ``` -------------------------------- ### Select CODATA 2014 Dataset Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Import the CODATA 2014 dataset for historical data before the 2019 SI redefinition. Constants in this dataset have measured uncertainties. ```julia using PhysicalConstants.CODATA2014 # Historical data before 2019 SI redefinition # Constants have measured uncertainties ``` -------------------------------- ### Convert Constants to Quantity Types Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Convert physical constants to different numeric types like Float64, Float32, or BigFloat to perform calculations or get exact values. ```julia float(c_0) ``` ```julia float(Float32, h) ``` ```julia float(BigFloat, c_0) ``` ```julia big(h) ``` -------------------------------- ### Access Molar Gas Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Access the molar gas constant (`R`). This demonstrates retrieving a constant used in gas law calculations. ```julia R ``` -------------------------------- ### Use Constants with Uncertainty (Measurements.jl) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Use the Measurements.jl package to work with constants that have uncertainties. Exact constants will have zero uncertainty. ```julia using PhysicalConstants.CODATA2022, Measurements # Measured with significant uncertainty G_meas = measurement(NewtonianConstantOfGravitation) # 6.6743e-11 ± 1.5e-15 m^3 kg^-1 s^-2 # Exact constants h_meas = measurement(PlanckConstant) # 6.62607015e-34 ± 0.0 J s ``` -------------------------------- ### Macros Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Information on the macros used for defining physical constants, both fundamental and derived. ```APIDOC ## Macros ### `@constant` This macro is used to define a fundamental physical constant. **Arguments:** - `name`: The symbolic name of the constant. - `sym`: The symbol representing the constant. - `descr`: A description of the constant. - `val`: The numerical value of the constant. - `def`: The definition or formula for the constant. - `unit`: The unit of the constant. - `unc`: The uncertainty of the constant. - `bigunc`: The uncertainty of the constant for `BigFloat`. - `reference`: The source reference for the constant. ### `@derived_constant` This macro is used to define a derived physical constant. **Arguments:** - `name`: The symbolic name of the constant. - `sym`: The symbol representing the constant. - `descr`: A description of the constant. - `val`: The numerical value of the constant. - `def`: The definition or formula for the constant. - `unit`: The unit of the constant. - `m64`: The measurement with uncertainty for `Float64`. - `mbig`: The measurement with uncertainty for `BigFloat`. - `reference`: The source reference for the constant. ``` -------------------------------- ### Get Newtonian Constant of Gravitation (G) as Float and Measurement Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2022-module.md Retrieve the nominal value of the Newtonian constant of gravitation as a floating-point number or as a measurement including its uncertainty. Useful for gravitational force calculations. ```julia using PhysicalConstants.CODATA2022, Measurements float(G) # Returns: 6.6743e-11 m^3 kg^-1 s^-2 # With uncertainty measurement(G) # Returns: 6.6743e-11 ± 1.5e-15 m^3 kg^-1 s^-2 # Gravitational force between two masses import PhysicalConstants.CODATA2022: G # F = G * m1 * m2 / r^2 ``` -------------------------------- ### Import Specific or All Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Import specific constants or all constants from a dataset. You can use short symbols or long names for access. ```julia # Import specific constants using PhysicalConstants.CODATA2022: c_0, h, k_B, G # Or import all using PhysicalConstants.CODATA2022 # Use short symbols or long names import PhysicalConstants.CODATA2022 c_value = float(PhysicalConstants.CODATA2022.c_0) ``` -------------------------------- ### Access Fine Structure Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Access the fine structure constant (`α`). This demonstrates retrieving a dimensionless fundamental constant. ```julia α ``` -------------------------------- ### Get Quantity with Specified Float Type Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Shows how to use `float(ConstantType, constant)` to obtain a `Quantity` with a specific floating-point type (e.g., `Float32`, `BigFloat`). This is the preferred method for dimensioned constants. ```julia using PhysicalConstants.CODATA2022 float(SpeedOfLightInVacuum) float(Float32, BohrRadius) float(BigFloat, PlanckConstant) ``` -------------------------------- ### Load CODATA2022 Dataset Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/docs/src/usage.md Load the CODATA2022 dataset to access physical constants. This is the recommended way to use the package for end-users. ```jldoctest julia> using PhysicalConstants.CODATA2022 julia> SpeedOfLightInVacuum Speed of light in vacuum (c_0) Value = 2.99792458e8 m s^-1 Standard uncertainty = (exact) Relative standard uncertainty = (exact) Reference = CODATA 2022 julia> NewtonianConstantOfGravitation Newtonian constant of gravitation (G) Value = 6.6743e-11 m^3 kg^-1 s^-2 Standard uncertainty = 1.5e-15 m^3 kg^-1 s^-2 Relative standard uncertainty = 2.2e-5 Reference = CODATA 2022 ``` -------------------------------- ### Convert Dimensionless Constant to Numeric Type Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Demonstrates using `convert(Type, constant)` for dimensionless constants to get a raw numeric value of a specified type (e.g., `Float64`, `Float32`). This method raises an error for dimensioned constants. ```julia # Only works for constants with NoDims convert(Float64, FineStructureConstant) convert(Float32, FineStructureConstant) ``` -------------------------------- ### Create Custom CODATA Module Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Users can create custom modules to define their own constants, leveraging the `@constant` macro within a module definition. ```julia module MyConstants using PhysicalConstants, Measurements, Unitful import PhysicalConstants: @constant # Define custom constants here @constant(...) end ``` -------------------------------- ### Combine Measurements with Physical Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Shows how physical constants, when converted to `Measurement` objects using `Measurements.jl`, correctly propagate uncertainties when combined with other measurements in calculations. ```julia using PhysicalConstants.CODATA2022, Measurements c = measurement(SpeedOfLightInVacuum) dist = 1500.0 ± 0.5u"m" time = dist / c ``` -------------------------------- ### Import Entire CODATA2018 Module Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2018-module.md Imports all 30 constants from the CODATA2018 module, making them directly accessible in the current namespace. ```julia using PhysicalConstants.CODATA2018 ``` -------------------------------- ### reference Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/core-api.md Retrieves the reference document for a physical constant. ```APIDOC ## reference ### Description Retrieves the reference document for a physical constant. ### Method Signature ```julia reference(::PhysicalConstant{name,T,D,U}) where {T,D,U} -> String ``` ### Parameters #### Path Parameters * **constant** (PhysicalConstant) - Required - The physical constant. ### Response A string indicating the reference source (e.g., "CODATA 2022"). ### Description Returns metadata indicating which CODATA dataset or reference document defines the constant's value. All constants in PhysicalConstants.jl are defined from official CODATA (Committee on Data for Science and Technology) recommendations. ### Request Example ```julia using PhysicalConstants.CODATA2022 reference(SpeedOfLightInVacuum) # Returns: "CODATA 2022" reference(PlanckConstant) # Returns: "CODATA 2022" ``` ``` -------------------------------- ### Type Signatures Quick Reference Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md This section provides a quick reference for the type signatures of the core components of the PhysicalConstants.jl package, including the main struct and core operations. ```APIDOC ## Type Signatures Quick Reference ### Type Definition ```julia struct PhysicalConstant{name,T,D,U} <: AbstractQuantity{T,D,U} ``` ### Core Operations ```julia # Convert to Float64 quantity float(::PhysicalConstant) -> Quantity{Float64,...} # Convert to a specified FloatType quantity float(FloatType, ::PhysicalConstant) -> Quantity{FloatType,...} # Convert to BigFloat quantity big(::PhysicalConstant) -> Quantity{BigFloat,...} # Get measurement with uncertainty measurement(::PhysicalConstant) -> Measurement × Unit # Get measurement with uncertainty for a specified FloatType measurement(FloatType, ::PhysicalConstant) -> Measurement × Unit # Get the reference string for the constant reference(::PhysicalConstant) -> String ``` ### Macros ```julia # Macro to define a physical constant @constant(name, sym, descr, val, def, unit, unc, bigunc, reference) # Macro to define a derived physical constant @derived_constant(name, sym, descr, val, def, unit, m64, mbig, reference) ``` ``` -------------------------------- ### Mathematical Operations on Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Illustrates the support for standard mathematical operations (arithmetic, powers, functions) on physical constants, often in conjunction with Unitful for unit handling. ```julia using PhysicalConstants.CODATA2022, Unitful h = float(PlanckConstant) c = float(SpeedOfLightInVacuum) ν = 1e15u"Hz" # Arithmetic E = h * ν # E = 6.62607015e-19 J # Powers c2 = c^2 # c2 = 8.98755179e16 (m/s)^2 # Functions inv_c = inv(c) sqrt_h = sqrt(h) # Trigonometric (if applicable) cos(float(α)) # cos of fine-structure constant ``` -------------------------------- ### PhysicalConstant + Quantity Promotion Rule Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Defines how a PhysicalConstant and a Unitful Quantity are promoted to a common Quantity type during arithmetic operations. Ensures symmetric promotion for both orders of operation. ```julia Base.promote_rule(::Type{PhysicalConstant{name,S,D,SU}}, ::Type{Quantity{T,D,TU}}) where {name,S,T,D,SU,TU} = promote_type(Quantity{S,D,SU}, Quantity{T,D,TU}) Base.promote_rule(::Type{Quantity{T,D,TU}}, ::Type{PhysicalConstant{name,S,D,SU}}) where {name,S,T,D,SU,TU} = promote_type(Quantity{S,D,SU}, Quantity{T,D,TU}) ``` -------------------------------- ### Access Unit and Dimension of Physical Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Demonstrates how to extract the unit and dimension from a physical constant using `Unitful.jl` functions `unit()` and `dimension()`. ```julia using PhysicalConstants.CODATA2022, Unitful unit(SpeedOfLightInVacuum) dimension(PlanckConstant) ``` -------------------------------- ### Convert Planck Constant to eV·s Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Illustrates converting the Planck constant to electronvolt-seconds (eV·s) using `uconvert`. This is common in quantum mechanics and particle physics. ```julia using PhysicalConstants.CODATA2022, Unitful h = float(PlanckConstant) h_ev_s = uconvert(u"eV*s", h) ``` -------------------------------- ### Access Electron Mass Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Access the electron mass constant (`m_e`). This demonstrates retrieving constants related to atomic and subatomic particles. ```julia m_e ``` -------------------------------- ### Import and Access CODATA 2022 Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Import the recommended CODATA 2022 dataset and access constants by their full name or short alias. ```julia # Use CODATA 2022 (recommended) using PhysicalConstants.CODATA2022 # Access a constant SpeedOfLightInVacuum # or use short alias c_0 ``` -------------------------------- ### Dimensionality Checking with uconvert Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Demonstrates that `uconvert` enforces dimensional consistency by raising an error when attempting to convert to incompatible units, such as converting speed (m/s) to mass (kg). ```julia import Unitful uconvert(u"kg", float(SpeedOfLightInVacuum)) ``` -------------------------------- ### Convert Temperature from Energy Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Calculates temperature in Kelvin from a given energy (in Hz) using Planck's constant (`h`) and Boltzmann's constant (`k_B`). It imports constants from `PhysicalConstants.CODATA2022`. ```julia # Temperature from energy (thermal) import PhysicalConstants.CODATA2022: h, k_B, c_0 temp = float(h) * 5e14u"Hz" / float(k_B) uconvert(u"K", temp) ``` -------------------------------- ### Cross-Module Constant Comparison Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/README.md Import constants with aliases from different CODATA datasets for comparison. ```julia import PhysicalConstants.CODATA2022: h as h_22 import PhysicalConstants.CODATA2014: h as h_14 ``` -------------------------------- ### Retrieve Reference Document for Physical Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/core-api.md Retrieves a string indicating the reference document (e.g., CODATA version) for a given PhysicalConstant. This helps in understanding the origin and traceability of the constant's value. ```julia using PhysicalConstants.CODATA2022 reference(SpeedOfLightInVacuum) # Returns: "CODATA 2022" reference(PlanckConstant) # Returns: "CODATA 2022" ``` -------------------------------- ### Define a New Physical Constant Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/core-api.md Use the `@constant` macro to define a new physical constant with its value, uncertainty, and metadata. Ensure `PhysicalConstants` and `Unitful` are imported. ```julia using PhysicalConstants, Unitful PhysicalConstants.@constant(MyConstant, mc, "A custom constant", 12.34, BigFloat(1234) / BigFloat(100), u"m/s", 0.56, BigFloat(56) / BigFloat(100), "My lab notebook") MyConstant ``` -------------------------------- ### Convert Bohr Radius to Nanometers Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/promotion-and-conversion.md Demonstrates converting the Bohr radius to nanometers using `uconvert`. This is useful for working with atomic-scale lengths in different units. ```julia using PhysicalConstants.CODATA2022, Unitful a_0_m = float(BohrRadius) a_0_nm = uconvert(u"nm", a_0_m) ``` -------------------------------- ### Controlling Precision of Constants Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2018-module.md Shows how to retrieve constants with different floating-point precisions (Float64, Float32, BigFloat). Useful for calculations requiring specific precision levels. ```julia using PhysicalConstants.CODATA2018 # Float64 (default) float(PlanckConstant) # Float32 precision float(Float32, PlanckConstant) # BigFloat for arbitrary precision float(BigFloat, PlanckConstant) ``` -------------------------------- ### Compare Planck Constant Across Datasets Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Compares the value of the Planck constant across different CODATA datasets (2014, 2018, 2022) to show its evolution and how it became an exact value in later datasets. ```julia import PhysicalConstants.CODATA2014: h as h_14 import PhysicalConstants.CODATA2018: h as h_18 import PhysicalConstants.CODATA2022: h as h_22 # Planck constant evolution println("CODATA2014: ", float(h_14)) # 6.62607040e-34 J s (measured, uncertain) println("CODATA2018: ", float(h_18)) # 6.62607015e-34 J s (exact) println("CODATA2022: ", float(h_22)) # 6.62607015e-34 J s (exact, same as 2018) ``` -------------------------------- ### Displaying Physical Constant Information Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/package-overview.md Shows the default formatted text display for a physical constant, which includes its name, symbol, value, uncertainty, and reference. ```julia using PhysicalConstants.CODATA2022 PlanckConstant # Output: # Planck constant (h) # Value = 6.62607015e-34 J s # Standard uncertainty = (exact) # Relative standard uncertainty = (exact) # Reference = CODATA 2022 ``` -------------------------------- ### big Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/core-api.md Alias for converting a constant to BigFloat precision. ```APIDOC ## big ### Description Alias for converting a constant to `BigFloat` precision. ### Method Signature ```julia big(::PhysicalConstant{name,T,D,U}) where {T,D,U} -> Quantity{BigFloat,D,U} ``` ### Parameters #### Path Parameters * **constant** (PhysicalConstant) - Required - The physical constant to convert. ### Response A `Quantity` with `BigFloat` precision. ### Description Convenience alias for `float(BigFloat, constant)`. Provides high-precision representation suitable for arbitrary-precision arithmetic and numerical methods requiring extended precision. ### Request Example ```julia using PhysicalConstants.CODATA2022 big(PlanckConstant) # Returns Planck constant as BigFloat with ~50 decimal places # BigFloat constants can be used in exact mathematical expressions big(ħ) == big(h) / (2 * big(pi)) # Returns: true ``` ``` -------------------------------- ### Calculate Fine Structure Splitting (Hydrogen) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Calculate the fine structure splitting energy for hydrogen using fundamental constants. ```julia import PhysicalConstants.CODATA2022: α, R_∞, h, c_0 ΔE = 2 * float(α)^2 * float(R_∞) * float(h) * float(c_0) ``` -------------------------------- ### Unit Conversion with Unitful.jl Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/quick-reference.md Convert constants to different units using the Unitful.jl package. This is useful for calculations involving different scales or units. ```julia using Unitful # Convert to different units uconvert(u"km/s", float(c_0)) # Returns: 299792.458 km s^-1 uconvert(u"eV", float(h) * 1e15u"Hz") # Convert photon energy to eV ``` -------------------------------- ### Access Speed of Light in Vacuum (c_0) Source: https://github.com/juliaphysics/physicalconstants.jl/blob/master/_autodocs/codata2014-module.md Retrieve the exact value for the speed of light in a vacuum (c_0) as defined in the CODATA2014 dataset. This constant has been exact by definition since 1983. ```julia c_0 ```