C++ Boost

Mathematical Constants for C and C++


Contents

This document provides information about a series of C/C++ header files which present some widely used accurate mathematical constants like pi, sqrt(2),e ...
The files were reviewed for inclusion in the Boost library but were rejected because agreement on the form of presentation could not be reached.
 The main contention was on how to provide a way of using the constants with multiple precision and User Defined Types, including interval types and fixed point decimals.
 However the values presented here are still useful to provide C and C++ constant values, typically as statements like
#define M_SQRTTWO 1.41421356237309504880168872420969807857L  /* sqrt(2) */
static const double pi = 3.141592653589793238462643383279502884197; // Archimedes constant pi
To use these files, include one (and only one) of the header files to provide macro, float, double or long double, or function.
(Or even just copy and paste the line(s) required).
For the user, these values are convenient and accurate enough for all normal computations, using up to 128-bit floating point hardware.
Using accurate values not only ensures a more accurate result, but avoid makes the program as portable as is possible.
Using pre-calculated values for constants like fourthirds pi avoids slight inaccuracies which are inevitable if the compiler does the calculation at compile time,
and significant inaccuracies if functions like log, sin, cos, pow are calculated at run time.

The values are calculated using reference values and an arbitrary precision decimal arithmetic program NTL.  They have been checked against compiler generated values and a second reference source where possible.  But please tell the author of any errors you discover.

Overview
Rationale
Definitions
FAQ
Bibliography
Acknowledgements
Download constants files (zipped)
Download documentation(zipped)


hetp://www.hetp/u-net.com/public/math_constants.html  Revised 5 May 2005.

© Copyright Paul A. Bristow and hetp 2002-2005. All Rights Reserved.

Valid HTML 4.01!