From: Paul A. Bristow (boost_at_[hidden])
Date: 2001-11-06 15:27:55
Here are some suggested constants, in three groups:
1 Basic math constants. The absolute minimum?
2 More, and some derived math constants.
3 More obscure (but essential for some people) math constants.
I have indicated some rationale for including each one,
drawing on the 'authority' of 3 texts:
1 Knuth, Art of Computer Programming,
2 John Hart, Computer Approximations, and
3 Stephen Moshier, Math Functions, mathlib
4 Morris, ACM 715 & Brown CDFlib collection of math functions used in
as a guide to what has been used in typical math work.
Although there was some discussion and many disagreements,
in the end I have generally stuck to the naming scheme I proposed earlier.
I still prefer ln to log, but C99 seems to use log for ln and log10,
so I am persauded to reluctantly follow this.
I have yet to find a nicer way of describing reciprocal than one_div_...
Any ideas? Is reciprocal_sqrt_2 better than one_div_sqrt_2 ?
All the sqrt, log, trig and pow functions are liable to be inaccurate,
(seriously inaccurate at times)
and all lead to run-time code which is most unlikely to be optimised.
I indicate this by saying for example 'avoid log(pi)'.
Please object (Boosters are really, really expert at this!)
and suggest others (your pet constant!) that are missing.
Is the .hpp naming scheme sensible, if boring?
1 Basic math_constants.hpp
log_pi - avoid log(pi)
sqrt_2 - avoid sqrt(2.)
cbrt_2 - avoid pow (but follow cbrt C99 naming convention, even if ugly!)
cbrt_3 - avoid pow
fourth_root_2 - avoid pow
log_2 - avoid log(2.)
log_4 - avoid log(4.)
log_10 - avoid log(10.)
log_e - avoid log(e)
log_pi - avoid log(pi)
log_two_pi - avoid log(2.*pi)
one_div_pi - accuracy.
sqrt(1_div_pi) - avoid sqrt
sqrt_10 - avoid sqrt(10.)
sqrt_pi - avoid sqrt == gamma_half
log_sqrt_two_pi - avoid log and sqrt
log10_2 - avoid possible log and *
2 Additional in math_constants2.hpp
Some of these may be calculated accurately by the compiler,
but are good for clear programs,
and avoid any run-time code for debug and/or less-optimised code.
half_pi - convenient and commonly used (even if compiler should get it
quarter_pi - convenient and commonly used (even if compiler should get it
two_pi - convenient and commonly used(even if compiler should get it exact).
half_sqrt_2 - convenient and commonly used(even if compiler should get it
two_pow_two_thirds - avoid pow
two_div_pi - commonly used(even if compiler should get it exactly from
three_quarters_pi - for accuracy (or three_pi_div_4?)
pi_squared - accuracy
log_2_div_2 - avoid log(2)
e_squared - accuracy
two_pow_2_div_3 - avoid pow
log_log_2 - avoid log, twice!
phi - golden ratio
a handful of real constants (1. NOT 1 - useful)
third - accuracy?
two_thirds - accuracy?
3 Obscure in math_constants3.hpp
gamma_min_at -- 1.46...
gamma_min -- 0.88560...
e_pow_euler - avoid pow
Dr Paul A Bristow, hetp Chromatography
LA8 8AB UK
+44 1539 561830
Mobile +44 7714 33 02 04
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk