constant

Returns the value of various mathematical and physical constants.

Synopsis

constant (name, unit)

Required Arguments

char name (Input)
Character string containing the name of the desired constant. The case of the character string name does not matter. The names “PI”, “Pi”, “pI”, and “pi” are equivalent. Spaces and underscores are allowed and ignored.
char unit (Input)
Character string containing the units of the desired constant. If None, then Système International d’Unités (SI) units are assumed. The case of the character string unit does not matter. The names “METER”, “Meter” and “meter” are equivalent. unit has the form U1*U2*...*Um/V1/.../Vn, where Ui and Vi are the names of basic units or are the names of basic units raised to a power. Basic units must be separated by * or /. Powers are indicated by ^, as in “m^2” for \(\text{m}^2\). Examples are, “METER*KILOGRAM/SECOND”, “M*KG/S”, “METER”, or “M/KG^2”.

Return Value

By default, constant returns the desired constant. If no value can be computed, NaN is returned.

Description

The names allowed are listed in the following table. Values marked with a ‡ are exact (to machine precision). The references in the right-hand column are indicated by the code numbers: [1] for Cohen and Taylor (1986), [2] for Liepman (1964), and [3] for precomputed mathematical constants.

Name Description Value Reference
Amu Atomic mass unit 1.6605655 × \(10^{-27}\) kg 1
ATM Standard atm pressure 1.01325 × \(10^5\) \(N/m^2\) 2
AU Astronomical unit 1.496 × \(10^{11}\) m  
Avogadro Avogadro’s number, N 6.022045 × \(10^{23}\) 1/mole 1
Boltzman Boltzman’s constant, k 1.380662 × \(10^{-23}\) J/K 1
C Speed of light, c 2.997924580 × \(10^8\) m/s 1
Catalan Catalan’s constant 0.915965…‡ 3
E Base of natural logs, e 2.718…‡ 3
ElectronCharge Electron charge, e 1.6021892 × \(10^{-19}\) C 1
ElectronMass Electron mass, \(m_e\) 9.109534 × \(10^{-31}\) kg 1

ElectronVolt

Euler

ElectronVolt, ev

Euler’s constant, γ

1.6021892 \(x10 ^{-19}\) J

0.577…‡

1

3

Faraday Faraday constant, F 9.648456 × \(10^4\) C/mole 1
FineStructure Fine structure, α 7.2973506 × \(10^{-3}\) 1
Gamma Euler’s constant, γ 0.577…‡ 3
Gas Gas constant, \(R_0\) 8.31441 J/mole/K 1
Gravity Gravitational constant, G 6.6720 × \(10^{-11}\) N \(m^2/kg^2\) 1
Hbar Planck’s constant/2π 1.0545887 × \(10^{-34}\) J s 1
PerfectGasVolume Std vol ideal gas 2.241383 × \(10^{-2}\) \(m^3\)/mole 1
Pi Pi, π 3.141…‡ 3
Planck Planck’s constant, h 6.626176 × \(10^{-34}\) J s 1
ProtonMass Proton mass, \(M_p\) 1.6726485 × \(10^{-27}\) kg 1
Rydberg Rydberg’s constant, \(R_\mu\) 1.097373177 × \(10^7\)/m 1
Speedlight Speed of light, c 2.997924580 × \(10^8\) m/s 1
StandardGravity Standard g 9.80665 \(m/s^2\) 2
StandardPressure Standard atm pressure 1.01325 × \(10^5\) \(N/m^2\) 2
StefanBoltzman Stefan-Boltzman, σ 5.67032 × \(10^{-8}W/K^4/m^2\) 1
WaterTriple Triple point of water 2.7316× \(10^2\) K 2

The units allowed are as follows:

Unit Description
Time day, hour = hr, min, minute, s = sec = second, year
Frequency Hertz = Hz
Mass AMU, g = gram, lb = pound, ounce = oz, slug
Distance Angstrom, AU, feet = foot, in = inch, m = meter = metre, micron, mile, mill, parsec, yard
Area Acre
Volume 1 = liter=litre
Force dyne, N = Newton
Energy BTU, Erg, J = Joule
Work W = watt
Pressure ATM = atmosphere, bar
Temperature degC = Celsius, degF = Fahrenheit, degK = Kelvin
Viscosity poise, stoke
Charge Abcoulomb, C = Coulomb, statcoulomb
Current A = ampere, abampere, statampere
Voltage Abvolt, V = volt
Magnetic induction T = Telsa, Wb = Weber
Other units I, farad, mole, Gauss, Henry, Maxwell, Ohm

The following metric prefixes may be used with the above units. The one or two letter prefixes may only be used with one letter unit abbreviations.

A d        
F femto \(10^{-15}\) dk deca \(10^2\)
P pico \(10^{-12}\) k kilo \(10^3\)
N nano \(10^{-9}\)   myria \(10^4\)
U micro \(10^{-6}\)   mega \(10^6\)
M milli \(10^{-3}\) g giga \(10^9\)
C centi \(10^{-2}\) t tera \(10^{12}\)

There is no one letter unit abbreviation for myria or mega since m means milli.

Examples

Example 1

In this example, Euler’s constant γ is obtained and printed. Euler’s constant is defined to be

\[\gamma = \lim_{n \to \infty} \left[ \sum_{k=1}^{n-1} \tfrac{1}{k} - \ln n \right]\]
from __future__ import print_function
from pyimsl.math.constant import constant

gamma = constant("gamma", "")
print("gamma = ", gamma)

Output

gamma =  0.5772156649015329

Example 2

In this example, the speed of light is obtained using several different units.

from __future__ import print_function
from pyimsl.math.constant import constant

# Get speed of light in meters/second
speed_light = constant("speed_light", "meter/second")
print("Speed of light = ", speed_light, " meters/sec")

# Get speed of light in miles/second
speed_light = constant("speed_light", "mile/second")
print("Speed of light = ", speed_light, " mile/sec")

# Get speed of light in centimeters/nanosecond
speed_light = constant("speed_light", "cm/ns")
print("Speed of light = ", speed_light, " cm/ns")

Output

Speed of light =  299792458.0  meters/sec
Speed of light =  186282.39705122088  mile/sec
Speed of light =  29.979245800000015  cm/ns

Warning Errors

IMSL_MASS_TO_FORCE A conversion of units of mass to units of force was required for consistency.