API Reference
Types
PhysicalConstants.PhysicalConstant — TypePhysicalConstant{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: aSymbolrepresenting its nameT: the numerical type of the constant, e.g.Float64D: the physical dimension, fromUnitful.jlU: the physical unit, fromUnitful.jl
See @constant and @derived_constant for how to define a new physical constant.
Functions
Base.float — Methodfloat(::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^-2Measurements.measurement — Methodmeasurement(::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^-2Macros
PhysicalConstants.@constant — Macro@constant(name, sym, descr, val, def, unit, unc, bigunc, reference) -> PhysicalConstantMacro to define a new PhysicalConstant.
The arguments are:
name: a symbol with the long name of the constant. This symbol is automatically eportedsym: a non-exported alias for the constantdescr: a description of the constantval: the numericalFloat64value of the constant, in the reference unitsdef: the expression to use to compute the constant in any precision, in the reference unitsunit: the reference unitsunc: the numericalFloat64value of the uncertainty, in the reference unitsbigunc: the expression to use to compute the uncertainty in any precision, in the reference unitsreference: 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 notebookPhysicalConstants.@derived_constant — Macro@derived_constant(name, sym, descr, val, def, unit, unc, bigunc, reference) -> PhysicalConstantMacro 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 eportedsym: a non-exported alias for the constantdescr: a description of the constantval: the numericalFloat64value of the constant, in the reference unitsdef: the expression to use to compute the constant in any precision, in the reference unitsunit: the reference unitsmeasure64: the numericalMeasurement{Float64}value of the constant, in the reference unitsmeasurebig: the expression to use to compute the comstamt as aMeasurement{BigFloat}, in the reference unitsreference: 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