math.h
math.h is a header file in the Standard C Library of the C programming language . It was developed for mathematical functions. The programming language C ++ also uses the functions to ensure the compatibility of C to C ++, and declares them in the header file cmath (used there without the file extension “.h”).
All functions that read in or output an angle work with radians . Most functions work with floating point numbers . Mathematical functions with integer values ( Integer work) as abv, labs, div or ldiv, are instead in the header file stdlib.h represented.
Functions up to C95
The following functions were declared in the standards up to and including C95 .
Surname | description | Mathematical formulation |
---|---|---|
acos |
Arccosine | |
asin |
Arcsine | |
atan |
Arctangent | |
atan2 |
"Arctangent" with two arguments | |
ceil |
Rounding function | |
cos |
cosine | |
cosh |
Hyperbolic cosine | |
exp |
Exponential function | |
fabs |
Amount function | |
floor |
Full part function | |
fmod |
Executes the modulo function for floating point numbers | |
frexp |
Divides a floating point number into a factor and a power with base 2 | |
ldexp |
Multiplies the first parameter by 2 raised to the power of the second parameter | |
log |
Natural logarithm | |
log10 |
Logarithm to base 10 | |
modf |
Splits a floating point number into two numbers, before and after the decimal point | |
pow |
Exponentiates the first with the second parameter | |
sin |
Sine | |
sinh |
Hyperbolic sine | |
sqrt |
square root | |
tan |
tangent | |
tanh |
Hyperbolic tangent |
C99 functions
With the C99 standard , math.h was expanded to include the following functions.
Surname | description | Mathematical formulation |
---|---|---|
acosh |
Hyperbolic areakosine | |
asinh |
Hyperbolic area | |
atanh |
Hyperbolic areatangens | |
cbrt |
Cube root | |
copysign(x,y) |
returns the value of x with the sign of y back | |
erf |
Error function | |
erfc |
Returns the complementary error of x back | |
exp2(x) |
Power 2 with the transferred parameter | |
expm1(x) |
Returns the value of exp () - 1 return | |
fdim(x,y) |
Positive difference | |
fma(x,y,z) |
Multiplied and added | |
fmax(x,y) |
maximum | |
fmin(x,y) |
minimum | |
hypot(x,y) |
hypotenuse | |
ilogb |
how logb , however, gives int back |
(int)logb(x)
|
lgamma |
Logarithm of the gamma function | |
llrint |
Rounding function | |
lrint |
Rounding function | |
llround |
Rounding function | |
lround |
Rounding function | |
log1p(x) |
Natural logarithm of 1 + x | |
log2 |
Logarithm to base 2 | |
logb |
Returns the integer exponent of a floating point number as a floating point number | |
nan(s) |
A NaN produce | |
nearbyint |
Rounds floating point numbers to the nearest integer | |
nextafter(x,y) |
Returns the next representable number after x (direction y ) | |
nexttoward(x,y) |
Just like nextafter , except for y , is always long double returned as |
|
remainder(x,y) |
Remainder of a division | |
remquo(x,y,p) |
Same as remainder , but stores the quotient (as int ) as the destination of the pointer p
|
|
rint |
Rounds to the nearest integer, depending on the rounding mode, returns a floating point number | |
round |
commercial rounding function | |
scalbln(x,y) |
x * FLT_RADIX y ( y is long ) |
|
scalbn(x,y) |
x * FLT_RADIX y ( y is int ) |
|
tgamma |
Gamma function | |
trunc |
Trims a floating point number, i.e. H. rounds "towards zero" |
example
1 #include <stdio.h>
2 #include <math.h>
3
4 int main() {
5 double a = 5, b = 4;
6 double c = pow(a, b);
7 printf("%f hoch %f ist %f\n", a, b, c);
8 }
Web links
- Rationale for International Standard - Programming Languages - C. (PDF, 898 kB) Retrieved September 4, 2011 (C99).
- Description on cplusplus.com (English)
- Documentation from math.h on dinkumware.com ( Memento from February 21, 2010 in the Internet Archive )