API Reference

Types

PhysicalConstants.PhysicalConstantType
PhysicalConstant{name,T,D,U} <: AbstractQuantity{T,D,U}

A type representing a physical constant, with units and – optionally – with error as standard deviation.

Each type is a singleton and is parametrised by

  • name: a Symbol representing its name
  • T: the numerical type of the constant, e.g. Float64
  • D: the physical dimension, from Unitful.jl
  • U: the physical unit, from Unitful.jl

See @constant and @derived_constant for how to define a new physical constant.

source

Functions

Base.floatMethod
float(::PhysicalConstant{name,T,D,U}) where {T,D,U}
float(FloatType, ::PhysicalConstant{name,T,D,U}) where {T,D,U}

Return the physical constant as a Quantity with the floating type optionally specified by FloatType, Float64 by default.

julia> using PhysicalConstants.CODATA2018: G

julia> G
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 2018

julia> float(G)
6.6743e-11 m^3 kg^-1 s^-2

julia> float(Float32, G)
6.6743f-11 m^3 kg^-1 s^-2
source
Measurements.measurementMethod
measurement(::PhysicalConstant{name,T,D,U}) where {T,D,U}
measurement(FloatType, ::PhysicalConstant{name,T,D,U}) where {T,D,U}

Return the physical constant as a Quantity with standard uncertainty. The floating-point precision can be optionally specified with the FloatType, Float64 by default.

julia> using PhysicalConstants.CODATA2018, Measurements

julia> import PhysicalConstants.CODATA2018: μ_0

julia> μ_0
Vacuum magnetic permeability (μ_0)
Value                         = 1.25663706212e-6 N A^-2
Standard uncertainty          = 1.9e-16 N A^-2
Relative standard uncertainty = 1.5e-10
Reference                     = CODATA 2018

julia> measurement(μ_0)
1.25663706212e-6 ± 1.9e-16 N A^-2

julia> measurement(Float32, μ_0)
1.256637e-6 ± 1.9e-16 N A^-2
source

Macros

PhysicalConstants.@constantMacro
@constant(name, sym, descr, val, def, unit, unc, bigunc, reference) -> PhysicalConstant

Macro to define a new PhysicalConstant.

The arguments are:

  • name: a symbol with the long name of the constant. This symbol is automatically eported
  • sym: a non-exported alias for the constant
  • descr: a description of the constant
  • val: the numerical Float64 value of the constant, in the reference units
  • def: the expression to use to compute the constant in any precision, in the reference units
  • unit: the reference units
  • unc: the numerical Float64 value of the uncertainty, in the reference units
  • bigunc: the expression to use to compute the uncertainty in any precision, in the reference units
  • reference: the name of the reference
julia> using PhysicalConstants, Unitful

julia> 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")

julia> MyConstant
A custom constant (mc)
Value                         = 12.34 m s^-1
Standard uncertainty          = 0.56 m s^-1
Relative standard uncertainty = 0.045
Reference                     = My lab notebook
source
PhysicalConstants.@derived_constantMacro
@derived_constant(name, sym, descr, val, def, unit, unc, bigunc, reference) -> PhysicalConstant

Macro to define a new PhysicalConstant derived from another existing PhysicalConstant.

The arguments are:

  • name: a symbol with the long name of the constant. This symbol is automatically eported
  • sym: a non-exported alias for the constant
  • descr: a description of the constant
  • val: the numerical Float64 value of the constant, in the reference units
  • def: the expression to use to compute the constant in any precision, in the reference units
  • unit: the reference units
  • measure64: the numerical Measurement{Float64} value of the constant, in the reference units
  • measurebig: the expression to use to compute the comstamt as a Measurement{BigFloat}, in the reference units
  • reference: the name of the reference
julia> using PhysicalConstants, Unitful, Measurements

julia> 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")

julia> MyConstant
A custom constant (mc)
Value                         = 12.34 m s^-1
Standard uncertainty          = 0.56 m s^-1
Relative standard uncertainty = 0.045
Reference                     = My lab notebook

julia> PhysicalConstants.@derived_constant(MyDerivedConstant, mdc, "A custom derived constant",
           96.252, ustrip(big(mc)) * BigFloat(78) / BigFloat(10), u"m/s",
           measurement(mc) * 7.8, measurement(BigFloat, mc)  * BigFloat(78) / BigFloat(10),
           "My lab notebook")

julia> MyDerivedConstant
A custom derived constant (mdc)
Value                         = 96.252 m s^-1
Standard uncertainty          = 4.368 m s^-1
Relative standard uncertainty = 0.045
Reference                     = My lab notebook
source