| The GNU C Library | www.imodulo.com · 2003-04-05 | ||
| [ Software | Documentation | Contact ] |
The header math.h defines several useful mathematical constants. All values are defined as preprocessor macros starting with M_. The values provided are:
M_EThe base of natural logarithms.
M_LOG2EThe logarithm to base 2 of M_E.
M_LOG10EThe logarithm to base 10 of M_E.
M_LN2The natural logarithm of 2.
M_LN10The natural logarithm of 10.
M_PIPi, the ratio of a circle's circumference to its diameter.
M_PI_2Pi divided by two.
M_PI_4Pi divided by four.
M_1_PIThe reciprocal of pi (1/pi)
M_2_PITwo times the reciprocal of pi.
M_2_SQRTPITwo times the reciprocal of the square root of pi.
M_SQRT2The square root of two.
M_SQRT1_2The reciprocal of the square root of two (also the square root of 1/2).
These constants come from the Unix98 standard and were also available in 4.4BSD; therefore they are only defined if _BSD_SOURCE or _XOPEN_SOURCE=500, or a more general feature select macro, is defined. The default set of features includes these constants. Feature Test Macros.
All values are of type double. As an extension, the GNU C library also defines these constants with type long double. The long double macros have a lowercase l appended to their names: M_El, M_PIl, and so forth. These are only available if _GNU_SOURCE is defined.
Note: Some programs use a constant named PI which has the same value as M_PI. This constant is not standard; it may have appeared in some old AT&T headers, and is mentioned in Stroustrup's book on C++. It infringes on the user's name space, so the GNU C library does not define it. Fixing programs written to expect it is simple: replace PI with M_PI throughout, or put -DPI=M_PI on the compiler command line.
| © Free Software Foundation, Inc. |