Simbody  3.6
Numerical Constants with Types

This is a set of predefined constants in the form of Real (SimTK default precision) symbols that are important for writing precision-independent numerical algorithms. More...

Variables

const Real SimTK::NaN
 This is the IEEE "not a number" constant for this implementation of the default-precision Real type; be very careful using this because it has many strange properties such as not comparing equal to itself. More...
 
const Real SimTK::Infinity
 This is the IEEE positive infinity constant for this implementation of the default-precision Real type; -Infinity will produce the negative infinity constant. More...
 
const Real SimTK::Eps
 Epsilon is the size of roundoff noise; it is the smallest positive number of default-precision type Real such that 1+Eps != 1. More...
 
const Real SimTK::SqrtEps
 This is the square root of Eps, ~1e-8 if Real is double, ~3e-4 if Real is float. More...
 
const Real SimTK::TinyReal
 TinyReal is a floating point value smaller than the floating point precision; it is defined as Eps^(5/4) which is ~1e-20 for Real==double and ~1e-9 for float. More...
 
const Real SimTK::SignificantReal
 SignificantReal is the smallest value that we consider to be clearly distinct from roundoff error when it is the result of a computation; it is defined as Eps^(7/8) which is ~1e-14 when Real==double, ~1e-6 when Real==float. More...
 
const Real SimTK::LeastPositiveReal
 This is the smallest positive real number that can be expressed in the type Real; it is ~1e-308 when Real==double, ~1e-38 when Real==float. More...
 
const Real SimTK::MostPositiveReal
 This is the largest finite positive real number that can be expressed in the Real type; ~1e+308 when Real==double, ~1e+38 when Real==float. Note that there is also a value Infinity that will test larger than this one. More...
 
const Real SimTK::LeastNegativeReal
 This is the largest negative real number (that is, closest to zero) that can be expressed in values of type Real. More...
 
const Real SimTK::MostNegativeReal
 This is the smallest finite negative real number that can be expressed in values of type Real. Note that -Infinity is a value that will still test smaller than this one. More...
 
const int SimTK::NumDigitsReal
 This is the number of decimal digits that can be reliably stored and retrieved in the default Real precision (typically log10(1/eps)-1), that is, about 15 digits when Real==double and 6 digits when Real==float. More...
 
const int SimTK::LosslessNumDigitsReal
 This is the smallest number of decimal digits you should store in a text file if you want to be able to get exactly the same bit pattern back when you read it back in and convert the text to a Real value. More...
 
const Real SimTK::Zero
 Real(0) More...
 
const Real SimTK::One
 Real(1) More...
 
const Real SimTK::MinusOne
 Real(-1) More...
 
const Real SimTK::Two
 Real(2) More...
 
const Real SimTK::Three
 Real(3) More...
 
const Real SimTK::OneHalf
 Real(1)/2. More...
 
const Real SimTK::OneThird
 Real(1)/3. More...
 
const Real SimTK::OneFourth
 Real(1)/4. More...
 
const Real SimTK::OneFifth
 Real(1)/5. More...
 
const Real SimTK::OneSixth
 Real(1)/6. More...
 
const Real SimTK::OneSeventh
 Real(1)/7. More...
 
const Real SimTK::OneEighth
 Real(1)/8. More...
 
const Real SimTK::OneNinth
 Real(1)/9. More...
 
const Real SimTK::Pi
 Real(pi) More...
 
const Real SimTK::OneOverPi
 1/Real(pi) More...
 
const Real SimTK::E
 e = Real(exp(1)) More...
 
const Real SimTK::Log2E
 Real(log2(e)) (log base 2) More...
 
const Real SimTK::Log10E
 Real(log10(e)) (log base 10) More...
 
const Real SimTK::Sqrt2
 Real(sqrt(2)) More...
 
const Real SimTK::OneOverSqrt2
 1/sqrt(2)==sqrt(2)/2 as Real More...
 
const Real SimTK::Sqrt3
 Real(sqrt(3)) More...
 
const Real SimTK::OneOverSqrt3
 Real(1/sqrt(3)) More...
 
const Real SimTK::CubeRoot2
 Real(2^(1/3)) (cube root of 2) More...
 
const Real SimTK::CubeRoot3
 Real(3^(1/3)) (cube root of 3) More...
 
const Real SimTK::Ln2
 Real(ln(2)) (natural log of 2) More...
 
const Real SimTK::Ln10
 Real(ln(10)) (natural log of 10) More...
 
const Complex SimTK::I
 We only need one complex constant, i = sqrt(-1). For the rest just multiply the real constant by i, or convert with Complex(the Real constant), or if you need an address you can use NTraits<Complex>::getPi(), etc. More...
 

Detailed Description

This is a set of predefined constants in the form of Real (SimTK default precision) symbols that are important for writing precision-independent numerical algorithms.

These constants have memory addresses (that is, they are not macros), so you can return references to them. These are global external symbols rather than static members to avoid problems with static initialization order.

Constants defined here include common mathematical values like pi, e, and sqrt(2) and also numerical constants related to the floating point implementation of the Real type, such as NaN, Infinity, and the machine precision Epsilon. For convenience we also provide several common numerical values for which it is useful to have a precision-independent representation (mostly to avoid warnings or casts to avoid them), and also where it is useful to have a referenceable memory location that contains those values. These include small integers and common small fractions like 1/2 and 1/3.

Note that the Simbody convention for typed constants is to name them like ordinary variables except with an initial capital letter (like a class name). Typed constants are processed by the compiler rather than the preprocessor and do not require any special treatment when used; they behave just like variables of the same type and value would behave. So we don't feel the need to draw attention to them with ALL_CAPS like we do with preprocessor symbols.

Variable Documentation

◆ NaN

const Real SimTK::NaN

This is the IEEE "not a number" constant for this implementation of the default-precision Real type; be very careful using this because it has many strange properties such as not comparing equal to itself.

You must use the SimTK::isNaN() function instead to determine whether something contains a NaN value.

◆ Infinity

const Real SimTK::Infinity

This is the IEEE positive infinity constant for this implementation of the default-precision Real type; -Infinity will produce the negative infinity constant.

Infinity tests larger than any other Real value.

◆ Eps

const Real SimTK::Eps

Epsilon is the size of roundoff noise; it is the smallest positive number of default-precision type Real such that 1+Eps != 1.

If Real is double (the normal case) then Eps ~= 1e-16; if Real is float then Eps ~= 1e-7.

◆ SqrtEps

const Real SimTK::SqrtEps

This is the square root of Eps, ~1e-8 if Real is double, ~3e-4 if Real is float.

Many numerical algorithms are limited to accuracy of sqrt(Eps) so this constant is useful in checking for termination of them.

◆ TinyReal

const Real SimTK::TinyReal

TinyReal is a floating point value smaller than the floating point precision; it is defined as Eps^(5/4) which is ~1e-20 for Real==double and ~1e-9 for float.

This is commonly used as a number to add to a computation in a denominator (such as a vector length) that might come out zero, just for the purpose of avoiding a divide by zero.

◆ SignificantReal

const Real SimTK::SignificantReal

SignificantReal is the smallest value that we consider to be clearly distinct from roundoff error when it is the result of a computation; it is defined as Eps^(7/8) which is ~1e-14 when Real==double, ~1e-6 when Real==float.

◆ LeastPositiveReal

const Real SimTK::LeastPositiveReal

This is the smallest positive real number that can be expressed in the type Real; it is ~1e-308 when Real==double, ~1e-38 when Real==float.

◆ MostPositiveReal

const Real SimTK::MostPositiveReal

This is the largest finite positive real number that can be expressed in the Real type; ~1e+308 when Real==double, ~1e+38 when Real==float. Note that there is also a value Infinity that will test larger than this one.

◆ LeastNegativeReal

const Real SimTK::LeastNegativeReal

This is the largest negative real number (that is, closest to zero) that can be expressed in values of type Real.

◆ MostNegativeReal

const Real SimTK::MostNegativeReal

This is the smallest finite negative real number that can be expressed in values of type Real. Note that -Infinity is a value that will still test smaller than this one.

◆ NumDigitsReal

const int SimTK::NumDigitsReal

This is the number of decimal digits that can be reliably stored and retrieved in the default Real precision (typically log10(1/eps)-1), that is, about 15 digits when Real==double and 6 digits when Real==float.

◆ LosslessNumDigitsReal

const int SimTK::LosslessNumDigitsReal

This is the smallest number of decimal digits you should store in a text file if you want to be able to get exactly the same bit pattern back when you read it back in and convert the text to a Real value.

Typically, this is about log10(1/tiny), which is about 20 digits when Real==double and 9 digits when Real==float.

◆ Zero

const Real SimTK::Zero

Real(0)

◆ One

const Real SimTK::One

Real(1)

◆ MinusOne

const Real SimTK::MinusOne

Real(-1)

◆ Two

const Real SimTK::Two

Real(2)

◆ Three

const Real SimTK::Three

Real(3)

◆ OneHalf

const Real SimTK::OneHalf

Real(1)/2.

◆ OneThird

const Real SimTK::OneThird

Real(1)/3.

◆ OneFourth

const Real SimTK::OneFourth

Real(1)/4.

◆ OneFifth

const Real SimTK::OneFifth

Real(1)/5.

◆ OneSixth

const Real SimTK::OneSixth

Real(1)/6.

◆ OneSeventh

const Real SimTK::OneSeventh

Real(1)/7.

◆ OneEighth

const Real SimTK::OneEighth

Real(1)/8.

◆ OneNinth

const Real SimTK::OneNinth

Real(1)/9.

◆ Pi

const Real SimTK::Pi

Real(pi)

◆ OneOverPi

const Real SimTK::OneOverPi

1/Real(pi)

◆ E

const Real SimTK::E

e = Real(exp(1))

◆ Log2E

const Real SimTK::Log2E

Real(log2(e)) (log base 2)

◆ Log10E

const Real SimTK::Log10E

Real(log10(e)) (log base 10)

◆ Sqrt2

const Real SimTK::Sqrt2

Real(sqrt(2))

◆ OneOverSqrt2

const Real SimTK::OneOverSqrt2

1/sqrt(2)==sqrt(2)/2 as Real

◆ Sqrt3

const Real SimTK::Sqrt3

Real(sqrt(3))

◆ OneOverSqrt3

const Real SimTK::OneOverSqrt3

Real(1/sqrt(3))

◆ CubeRoot2

const Real SimTK::CubeRoot2

Real(2^(1/3)) (cube root of 2)

◆ CubeRoot3

const Real SimTK::CubeRoot3

Real(3^(1/3)) (cube root of 3)

◆ Ln2

const Real SimTK::Ln2

Real(ln(2)) (natural log of 2)

◆ Ln10

const Real SimTK::Ln10

Real(ln(10)) (natural log of 10)

◆ I

const Complex SimTK::I

We only need one complex constant, i = sqrt(-1). For the rest just multiply the real constant by i, or convert with Complex(the Real constant), or if you need an address you can use NTraits<Complex>::getPi(), etc.

See also
NTraits