C Programming/math.h

math.h is a header file in the standard library of the C programming language designed for basic mathematical operations. Most of the functions involve the use of floating point numbers. C++ also implements these functions for compatibility reasons and declares them in the header  (the C99 functions are not available in the current C++ standard, C++ 98).

All functions that take or return an angle work in radians.

All functions take s for floating-point arguments, unless otherwise specified. In C99, to work with s or  s, append an   or an   to the name, respectively.

Mathematical library functions that operate on integers, such as,  ,  , and  , are instead specified in the stdlib.h header.

Pre-C99 functions
(For functions to convert strings to floating point numbers (atof, strtod, etc.), see C Programming/C Reference/stdlib.h.)

(For functions to convert floating point numbers to strings (snprintf, itoa, etc.), see C Programming/C Reference/stdio.h and C_Programming/C_Reference/stdlib.h#itoa.)

XSI Extensions
Extra functions may be available as X/Open System Interfaces Extensions. These are not present in any ANSI or ISO C standard.

The -to-string conversion functions ,   and   have been deprecated in favour of.

Mathematical constants (not standard)
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.

While these constants are common, they are not part of the C standard, so most modern compilers require an explicit definition (such as _USE_MATH_DEFINES in Microsoft Visual C++ ) for them to be defined when including math.h.