Cosmonstants.jl

Cosmonstants.jl builds on top of PhysicalConstants.jl to deliver extra constants (astrophysics, high-energy physics, and Corpuscles-derived particle masses) together with simple utilities for working with multiple unit systems.

Highlights

  • Cosmonstants.Constants exports CODATA2022 data as well as the extended sets defined in constants/extended.jl, constants/hep.jl, and constants/astro.jl so everything stays in sync with the registrar helpers used by the package.
  • The @createConstantsForMasses macro turns Corpuscles.jl particle masses into the same @constant entries used by PhysicalConstants; this is why MassMuon, MassTau, and the quark masses live in the same table as SolarMass and PlanckConstant.
  • Cosmonstants.Unitfull re-exports those constants under short aliases such as c_0, ħ, or M☉, while Cosmonstants.Unitless strips the units so you can work with raw SI numbers.
  • getUnitSystem + getUnitSystemModule dispatch on Real versus AbstractQuantity so multi-method APIs can react to the caller's preferred system without manual branching.

Quick start

julia> using Cosmonstants

julia> Cosmonstants.SolarMass
mass of the Sun (M☉)
Value                         = 1.98847e30 kg
Standard uncertainty          = 7.0e25 kg
Relative standard uncertainty = 3.5e-5
Reference                     = IAU1976
julia> uf = getUnitSystem(Unitful.Quantity)
UnitfullSystem()

julia> uf.c_0
SpeedOfLightInVacuum (c_0)
Value                         = 2.99792458e8 m s^-1
Standard uncertainty          = 0.0 m s^-1
Reference                     = CODATA2022

julia> ul = getUnitSystem(Float64)
UnitlessSystem()

julia> ul.c_0
2.99792458e8

Helpers & references

  • getListOfConstants() lists the canonical constants that feed the modules above; use it to build tables, documentation, or introspection tools.
  • correspondingSymbol(constant) returns the short alias for Unitfull (useful for generating tables or matching to external datasets).
  • fullReference(shortRef) looks up the stored bibliography entries plus sensible fallbacks (CODATA2022, PDG2022, IAU resolutions, etc.).

Whenever you add new constants, keep constants/extended.jl, constants/hep.jl, or constants/astro.jl in sync with the relevant references and correspondingSymbol aliases.

Building the docs

This repository ships with a Documenter.jl build under docs/. To rebuild locally, run:

julia --project=docs docs/make.jl

The generated output lands in docs/build and mirrors what is hosted at https://rafaelab.github.io/Cosmonstants.jl/index.html.

Cosmonstants.getCorpusclesParticleMassUncertaintyMethod

Helper function (unexported) to get the mass uncertainty value of a particle in kg. If lower and upper uncertainties are different, return the largest one of the two. This is done to be fully consistent with PhysicalConstants.jl, which uses the package Measurements.jl, which does not accept asymmetric uncertainties.

Input

. p:: ParticleType object for Corpuscles.jl

Output

. Particle mass uncertainty (without explicit units) in kg.

source
Cosmonstants.getUnitSystemMethod
getUnitSystem(::Type{T}) where {T}
getUnitSystem(::T) where {T}

Returns the unit system module (Unitfull or Unitless) corresponding to the type T. It acts as a dispatcher for functions that depend on the unit system.

source
Cosmonstants.getUnitSystemModuleMethod
getUnitSystemModule(::Type{<: AbstractUnitSystem})
getUnitSystemModule(::<: AbstractUnitSystem)

Returns the unit system module (Unitfull or Unitless) corresponding to the given AbstractUnitSystem type or instance.

source
Cosmonstants.@captureShowOutputMacro
@captureShowOutput(ex)

A macro that captures the output of evaluating an expression ex and returns a tuple containing the result of the evaluation and a string representation of the output.

Input

. ex: the expression to be evaluated (e.g., a constant or a mathematical expression).

Output

A tuple (val, output_string) where:
. val is the result of evaluating the expression ex
. output_string is a string containing the expression, its result, and its textual representation

source
Cosmonstants.@createConstantsForMassesMacro

Macro to conveniently create objects like in PhysicalConstants.jl from particle masses contained in Corpuscles.jl.

Input

. particle: a Corpuscles's Particle-type object . name: explicit name of the variable of the corresponding constant . symbol: short alias for the corresponding quantity (must be explicitly imported) . info: string containing the details of the quantity.

To do

. automatically retrieve PDG year (Corpuscles._default_year).

source
Cosmonstants.UnitfullModule
module Unitfull

This module defines a set of physical constants and derived quantities. It imports fundamental constants from external modules and provides shorthand notations for convenience. By using the module, the corresponding constants/units are scope-protected.

source
Cosmonstants.UnitlessModule
module Unitless

This module defines a set of physical constants and derived quantities stripping its units. The default is S.I. units.

source