Boost logo

Boost :

From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2000-07-06 05:05:32


Is there any interest in some high accuracy constants for the boost libraries?

For example the draft values below.

Use of these should increase program portability
(no annoying and hard to trace discrepancies when moving
to a different floating-point type, compiler, processor or platform).

No cost or performance penalty in using the right value,
but improving quality by getting it right 1st time.

Saving some time and hassle in finding them from a wide variety of sources.

Single or sub-sets of constants may be useful too. Cut'n'paste?
Some constants like pi are very widely used, but others are
rather obscure. Open to suggestions on packaging.

The ones listed cover most statistics and numerical analysis requirements.

Other constants could be added easily (calculated if necessary using
Victor Shoup's, NTL, www.shoup.net/ntl/ Numeric Template Library).

There is some html documentation available, as well as some comments
shown below (which might well NOT be part of .hpp files).
Paul

Dr Paul A. Bristow, hetp Chromatography
4 Victoria Road, Wilmslow, Cheshire SK9 5HN UK
Phone +44 1625 520193 FAX & Voicemail +44 1625 252495
email mailto:pbristow_at_[hidden]

constants.hpp

// Written by G:\Cpp\WinNTL-4_0a\src\NTL\makeConstants\makeConstants.cpp Thu
Apr 27 21:00:44 2000
// Using Victor Shoup's Numeric Template Library version 4.0a
// Real type is double accurate to 15 decimal digits.

#include <limits> // for max
// See Word version constants.doc (also saved and viewable as constants.html)

// This file is a collection of the most basic mathematical constants
// which are like to be widely used
// - even by programs just computing areas of circles!

// The objective is to achieve the full accuracy possible
// with IEEE Floating point hardware and C++ language.
// This has no extra cost to the user, but reduces irritating effects
// caused by the inevitable limitations of floating point calculations.
// At least these manifest as spurious least significant digits,
// at worst algorithms that fail because comparisons fail.
// Aim for at least 40 decimal places to ensure no loss of accuracy even for
long double.
// 40 decimal places 1234567890123456789012345678901234567890
// 50 decimal places 12345678901234567890123456789012345678901234567890

// Sources: see constants.doc.

typedef double real_type; // float or double or long double.
// Changing this typedef automatically converts the constant to the
appropriate
// type, for example float 1.234F, double 1234. or long double 1.234L.
// Note MSVC++ 6 SP3 implements long double as double, IEEE 64 bit format.

const real_type realMax = std::numeric_limits<real_type>::max();
const real_type eps = std::numeric_limits<real_type>::epsilon(); // For
example:
// const double eps = DBL_EPSILON; // std::numeric_limits<double>::epsilon()
// Constants related to:
// Integers
const real_type zero = (real_type)0.;
const real_type one = (real_type)1.;
const real_type unity = (real_type)1.;
// Two
const real_type two = (real_type)2.; // An exact IEEE 754 floating point
value.
const real_type half = (real_type) 0.5;

const real_type sqrtTwo = (real_type)
1.41421356237309504880168872420969807857; // sqrt(2)
const real_type rootTwo = (real_type)
1.41421356237309504880168872420969807857; // sqrt(2) alias.
const real_type root2 = (real_type) 1.41421356237309504880168872420969807857;
// sqrt(2) alias.
const real_type oneDivSqrtTwo = (real_type)
0.7071067811865475244008443621048490392848; // 1/sqrt(2)
const real_type halfSqrtTwo = (real_type)
0.7071067811865475244008443621048490392848; // sqrt(2)/2
const real_type cubeRootTwo = (real_type)
1.25992104989487316476721060727822835057025; // 2^1/3
const real_type fourthRootTwo = (real_type)
1.1892071150027210667174999705604759152929; // 2^1/4
const real_type logTwo = (real_type)
0.6931471805599453094172321214581765680755;
const real_type lnTwo = (real_type)
0.6931471805599453094172321214581765680755; // Alias logTwo.
const real_type oneDivLnTwo = (real_type)
1.44269504088896340735992468100189213742;
const real_type log10Two = (real_type)
0.3010299956639811952137388947244930267682; // log10(2)

// Three and up

const real_type Three = (real_type) 3.;
const real_type oneThird = (real_type)
0.3333333333333333333333333333333333333333; // 1/3
const real_type twoThirds = (real_type)
0.6666666666666666666666666666666666666667; // 2/3
const real_type sqrtThree = (real_type)
1.732050807568877293527446341505872366943; // 3^1/2
const real_type cubeRootThree = (real_type)
1.442249570307408382321638310780109588392; // 3^1/2
const real_type logThree = (real_type)
1.098612288668109691395245236922525704647; // ln(3)
const real_type sqrtFive = (real_type)
2.236067977499789696409173668731276235441; // sqrt(5)
const real_type sqrtTen = (real_type)
3.16227766016837933199889354443271853372; // sqrt(10)
const real_type lnTen = (real_type) 2.302585092994045684017991454684364207601;
// ln(10)
const real_type oneDivLnTen = (real_type)
0.4342944819032518276511289189166050822944; // 1/ln(10)
const real_type ten = (real_type) 10.;

// Archimedes constant pi
const real_type quarterPi = (real_type)
0.7853981633974483096156608458198757210493; // pi/4
const real_type thirdPi = (real_type)
1.047197551196597746154214461093167628066; // pi/3
const real_type halfPi = (real_type)
1.570796326794896619231321691639751442099; // pi/2
const real_type pi = (real_type) 3.141592653589793238462643383279502884197; //
pi
const real_type oneDivPi = (real_type)
0.3183098861837906715377675267450287240689; // 1/pi
const real_type twoDivPi = (real_type)
0.6366197723675813430755350534900574481378; // 2/pi
const real_type twoPi = (real_type) 6.283185307179586476925286766559005768394;
// 2 * pi
const real_type oneDivTwoPi = (real_type)
0.1591549430918953357688837633725143620345; // 1/2*pi
const real_type threePi = (real_type)
9.424777960769379715387930149838508652592; // 3 * pi
const real_type sqrtPi = (real_type)
1.772453850905516027298167483341145182798; // sqrt(pi)
const real_type sqrtHalfPi = (real_type)
1.253314137315500251207882642405522626503; // sqrt(pi/2)
const real_type sqrtTwoPi = (real_type)
2.506628274631000502415765284811045253007; // sqrt(2*pi)
const real_type oneDivSqrtPi = (real_type)
0.5641895835477562869480794515607725858441; // 1/sqrt(pi)
const real_type oneDivSqrtTwoPi = (real_type)
0.3989422804014326779399460599343818684759; // 1/sqrt(2*pi)
const real_type piSqr = (real_type) 9.869604401089358618834490999876151135314;
// pi^2
const real_type piCubed = (real_type)
31.00627668029982017547631506710139520223; // pi^3
const real_type lnSqrtPi = (real_type)
0.5723649429247000870717136756765293558236; // ln(sqrt(pi))
const real_type lnSqrtTwoPi = (real_type)
0.9189385332046727417803297364056176398614; // ln(sqrt(2*pi))
const real_type lnSqrtHalfPi = (real_type)
0.2257913526447274323630976149474410717859; // ln(sqrt(pi/2))
const real_type lnPi = (real_type) 1.144729885849400174143427351353058711647;
// ln(pi)
const real_type lnTwoPi = (real_type)
1.837877066409345483560659472811235279723; // ln(2*pi)
const real_type piPowPi = (real_type)
36.46215960720791177099082602269212366637; // pi^pi
const real_type piPowE = (real_type)
22.45915771836104547342715220454373502759; // pi^e

        // degree and radian.
const real_type degree = (real_type)
0.01745329251994329576923690768488612713443; // radians = pi/180.
const real_type radian = (real_type)
57.29577951308232087679815481410517033241; // degrees = 180/pi.

// Trigonometric.
const real_type sinhOne = (real_type)
1.17520119364380145688238185059560081515571798;
const real_type sinOne = (real_type)
0.84147098480789650665250232163029899962256306;
const real_type cosOne = (real_type) 0.54030230586813971740093660744297660;

// Euclid's "extreme and mean ratio" - D E Knuth, Vol 1 page 80 - 81.
// Greek artist Phidias is said to have used it in his sculpture.
const real_type goldenRatio = (real_type)
1.61803398874989484820458683436563811772;
// = (1 + sqrt(5)) /2;
const real_type lnPhi = (real_type)
0.4812118250596034474977589134243684231352; // ln(phi)

const real_type oneDivLnPhi = (real_type)
2.078086921235027537601322606117795767742; // 1/ln(phi)

// Exponential e
const real_type e = (real_type) 2.718281828459045235360287471352662497757; //
exp(1)
const real_type oneDivE = (real_type)
0.3678794411714423215955237701614608674458; // 1/e
const real_type ePowE = (real_type) 15.15426224147926418976043027262991190553;
// e^e
const real_type sqrtE = (real_type) 1.648721270700128146848650787814163571654;
// sqrt(e)
const real_type eSqr = (real_type) 7.38905609893065022723042746057500781318;
// e^2
const real_type eCubed = (real_type)
20.08553692318766774092852965458171789699; // e^3
const real_type log10e = (real_type)
0.4342944819032518276511289189166050822944; // log10(e)
const real_type oneDivLog10 = (real_type)
0.4342944819032518276511289189166050822944; // 1/ln(10)
const real_type logTen = (real_type)
2.302585092994045684017991454684364207601; // ln(10)
const real_type lnE = (real_type) 1.; // log(e) == (real_type)unity.
const real_type ePowPi = (real_type)
23.14069263277926900572908636794854738027; // e^pi
const real_type ePowHalfPi = (real_type)
4.81047738096535165547303566670383312639; // e^(pi/2)
const real_type ePowQuarterPi = (real_type)
2.193280050738015456559769659278738223462; // e^(pi/4)
const real_type ePowMinusHalfPi = (real_type)
0.2078795763507619085469556198349787700339; // e^(-pi/2)
const real_type ePowMinusQuarterPi = (real_type)
0.4559381277659962367659212947280294194166; // e^(-pi/4)
const real_type ePowMinusE = (real_type)
0.06598803584531253707679018759684642493858; // e^-e
const real_type ePowEuler = (real_type)
1.78107241799019798523650410310717954917; // e^euler
const real_type ePowMinusEuler = (real_type)
0.5614594835668851698241432147908807867657; // e^-euler

// gamma function or Euler constant.
const real_type euler = (real_type)
0.5772156649015328606065120900824024310422; // Euler alias gamma
const real_type gamma = (real_type)
0.5772156649015328606065120900824024310422; // gamma
const real_type lnEuler =
(real_type) -0.5495393129816448223376617688029077883307; // ln(Euler)
const real_type gammaQuarter = (real_type)
3.625609908221908311930685155867672002995; // gamma(1/4)
const real_type gammaThird = (real_type)
2.678938534707747633655692940974677644129; // gamma(1/3)
const real_type gammaHalf = (real_type)
1.772453850905516027298167483341145182798; // gamma(1/2)
const real_type gammaTwoThirds = (real_type)
1.354117939426400416945288028154513785519; // gamma(2/3)
const real_type gammaThreeQuarter = (real_type)
1.225416702465177645129098303362890526851; // gamma(3/4)
const real_type gammaFiveSixths = (real_type)
1.128787029908125961260901090258842013327; // gamma(5/6)
const real_type gammaSqr = (real_type)
0.3331779238077186743183761363552442266594; // gamma^2
const real_type gammaCubed = (real_type)
0.1923155168211845896631923744196359071217; // gamma^3
const real_type gammaMin = (real_type)
1.46163214496836234126265954232572132846819;
 // gamma(1.46) has the minimum value of 0.88...
const real_type gammaMinValue = (real_type)
0.88560319441088870027881590058258873320795153367;
const real_type gammaZero = realMax; // DBL_MAX; or LDBL_MAX == infinity.
const real_type gammaOne = (real_type) 1.; // by definition.
const real_type gammaTwo = (real_type) 1.; // by definition.
const real_type gammaThree = (real_type) 2.; // factorial(2) == 2!
const real_type gammaFour = (real_type) 6.; // factorial(3) == 3!
const real_type gammaFive = (real_type) 24.; // factorial(3) == 4!
const real_type gammaSix = (real_type) 120.; // factorial(3) == 5!

const real_type lnGammaZero = realMax; // == DBL_MAX or LDBL_MAX, or infinity?
const real_type lnGamma =
(real_type) -0.5495393129816448223376617688029077883307; // ln(gamma)
const real_type lnGammaSixth = (real_type)
1.716733435078240460527846309587930757279; // ln(gamma(1/6))
const real_type lnGammaQuarter = (real_type)
1.288022524698077457370610440219717295925; // ln(gamma(1/4))
const real_type lnGammaThird = (real_type)
0.9854206469277670691871740369779613917356; // ln(gamma(1/3))
const real_type lnGammaHalf = (real_type)
0.5723649429247000870717136756765293558236; // ln(gamma(1/2))
const real_type lnGammaTwoThirds = (real_type)
0.3031502751475235686758628173720110356635; // ln(gamma(2/3))
const real_type lnGammaThreeQuarters = (real_type)
0.2032809514312953714814329718624296997597; // ln(gamma(3/4))
const real_type lnGammaFiveSixths = (real_type)
0.1211436313311050230328131632233045224434; // ln(gamma(5/6))
const real_type lnGammaOne = (real_type) 0.; // ln(1) by definition.
const real_type lnGammaMin = (real_type)
0.3795537188395179971250638364384648368782; // ln(gamma(min))
const real_type lnGammaTwo = (real_type) 0.; // ln(1) by definition.
const real_type lnGammaThree = (real_type)
0.693147180559945309417232121458176; // gamma(3) = ln(2!)
const real_type lnGammaFour = (real_type) 1.79175946922805500081247735838071;
// gamma(4) = ln(3!)
const real_type lnGammaFive = (real_type) 3.17805383034794561964694160129705;
// gamma(5) = ln(4!)
const real_type lnGammaSix = (real_type) 4.78749174278204599424770093452327;
// gamma(6) = ln(5!)

// Continued fraction (base 10)
const double cf = 1.030640834100712935881776094116936840925;
const real_type zetaTwo =
(real_type)1.644934066848226436472415166646025189218942; // zeta(2)
const real_type zetaThree = (real_type)
1.202056903159594285399738161511449990765; // zeta(3)
// End of constants.h


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk