All Topics  
Math.h

 

   Email Print
   Bookmark   Link






 

Math.h



 
 
math.h is a header file in the standard library
C standard library

The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and character string handling, in the C ....
 of C programming language designed for basic mathematical operations. Most of the functions involve the use of floating point
Floating point

In computing, floating point describes a system for numerical representation in which a String of digits represents a rational number.The term floating point refers to the fact that the radix point can "float": that is, it can be placed anywhere relative to the Significant figures of the number....
 numbers. C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
 also implements these functions for compatibility reasons and declares them in the header cmath.

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

All these functions take doubles for floating-point arguments, unless otherwise specified.






Discussion
Ask a question about 'Math.h'
Start a new discussion about 'Math.h'
Answer questions from other users
Full Discussion Forum



Encyclopedia


math.h is a header file in the standard library
C standard library

The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and character string handling, in the C ....
 of C programming language designed for basic mathematical operations. Most of the functions involve the use of floating point
Floating point

In computing, floating point describes a system for numerical representation in which a String of digits represents a rational number.The term floating point refers to the fact that the radix point can "float": that is, it can be placed anywhere relative to the Significant figures of the number....
 numbers. C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
 also implements these functions for compatibility reasons and declares them in the header cmath.

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

All these functions take doubles for floating-point arguments, unless otherwise specified. To work with floats or long doubles, append an f or an l to the name, respectively.

Pre-C99 functions


Name Description
acos inverse cosine
asin inverse sine
atan one-parameter inverse tangent
atan2 two-parameter inverse tangent
Atan2

In trigonometry, the two-argument function atan2 is a variation of the arctangent function. For any real number arguments x and y not both equal to zero, atan2 is the angle in radians between the positive x-axis of a plane and the point given by the Cartesian coordinate system on it....
ceil ceiling, the smallest integer
Integer

The integers are natural numbers including 0 and their negative and non-negative numberss . They are numbers that can be written without a fractional or decimal component, and fall within the set ....
 not less than parameter
cos cosine
cosh hyperbolic cosine
exp exponential
Exponential

Exponential may refer to any of several mathematical topics related to exponentiation, including:*Exponential function, also:**Matrix exponential, the matrix analogue to the above...
 function
fabs absolute value
Absolute value

In mathematics, the absolute value of a real number is its numerical value without regard to its Negative and non-negative numbers. So, for example, 3 is the absolute value of both 3 and -3....
 (of a floating-point number)
floor floor, the largest integer not greater than parameter
fmod floating-point remainder
FMOD

FMOD is a commercial audio Library made by Firelight Technologies that plays music files of diverse Audio file format on many different Platform ....
frexp break floating-point number down into mantissa
Significand

The significand is the part of a floating point that contains its significant digits. Depending on the interpretation of the exponent, the significand may be considered to be an integer or a fraction ....
 and exponent
ldexp scale floating-point number by exponent (see article
Ldexp

In computing, ldexp is a function that multiplies a double precision floating point value by a specified integral power of two, returning the result if it is a valid floating point value for the representation used for double precision floating point values in the execution environment....
)
log natural logarithm
Natural logarithm

The natural logarithm, formerly known as the hyperbolic logarithm, is the logarithm to the base e , where e is an irrational number constant approximately equal to 2.718281828....
log10 base-10 logarithm
Common logarithm

The common logarithm is the logarithm with base 10. It is also known as the decadic logarithm, named after its base. It is indicated by log10, or sometimes Log with a capital L ....
modf(x,p) returns fractional part of x and stores integral part where pointer p points to
pow(x,y) raise x to the power of y, xy
sin sine
Siné

Maurice Sinet, known as Sin? is a France cartoonist.As a young man he studied drawing and graphic arts, earning his life as a cabaret singer....
sinh hyperbolic sine
sqrt square root
Square root

In mathematics, a square root of a number x is a number r such that r2 = x, or, in other words, a number r whose square is x....
tan tangent
tanh hyperbolic tangent


C99 functions


Name Description
acosh inverse hyperbolic cosine
Inverse hyperbolic function

The inverse functions of the hyperbolic functions are the area hyperbolic functions. The names hint at the fact that they compute the area of a hyperbolic sector in the same way that the inverse trigonometric functions compute the arclength of a sector on the unit circle ...
asinh inverse hyperbolic sine
Inverse hyperbolic function

The inverse functions of the hyperbolic functions are the area hyperbolic functions. The names hint at the fact that they compute the area of a hyperbolic sector in the same way that the inverse trigonometric functions compute the arclength of a sector on the unit circle ...
atanh inverse hyperbolic tangent
Inverse hyperbolic function

The inverse functions of the hyperbolic functions are the area hyperbolic functions. The names hint at the fact that they compute the area of a hyperbolic sector in the same way that the inverse trigonometric functions compute the arclength of a sector on the unit circle ...
cbrt cube root
Cube root

In mathematics, a cube root of a number, denoted or x1/3, is a number a such that a3 = x. All real numbers have exactly one real number cube root and a pair of complex conjugate roots, and all nonzero complex numbers have three distinct complex cube roots....
copysign(x,y) returns the value of x with the sign of y
erf error function
Error function

In mathematics, the error function is a special function which occurs in probability, statistics, materials science, and partial differential equations....
erfc complementary error function
exp2(x) raise 2 to the power of x, 2x
expm1(x) one less than the exponential of x, ex − 1
fdim(x,y) positive difference between x and y, fmax(xy, 0)
fma(x,y,z) multiply and add, (x * y) + z
fmax(x,y) largest value of x and y
fmin(x,y) smallest value of x and y
hypot(x,y) hypotenuse
Hypotenuse

File:Triangle Sides.svgA hypotenuse is the longest side of a right triangle, the side opposite the right angle. The length of the hypotenuse of a right triangle can be found using the Pythagorean theorem, which states that the Square of the length of the hypotenuse equals the sum of the squares of the lengths of the other two sides....
, sqrt(x2 + y2)
ilogb the exponent of a floating-point value, converted to an int
lgamma natural log of the absolute value
Absolute value

In mathematics, the absolute value of a real number is its numerical value without regard to its Negative and non-negative numbers. So, for example, 3 is the absolute value of both 3 and -3....
 of the gamma function
Gamma function

In mathematics, the Gamma function is an extension of the factorial function to real number and complex number numbers. For a complex number z with positive real part the Gamma function is defined by...
llrint round to integer (returns long long) using current rounding mode
lrint round to integer (returns long) using current rounding mode
llround round to integer (returns long long)
lround round to integer (returns long)
log1p(x) natural logarithm
Natural logarithm

The natural logarithm, formerly known as the hyperbolic logarithm, is the logarithm to the base e , where e is an irrational number constant approximately equal to 2.718281828....
 of 1 + x
log2 base-2 logarithm
Binary logarithm

In mathematics, the binary logarithm is the logarithm for base 2. It is the inverse function of ....
logb extract exponent from floating-point number
nan(s) returns NaN
NaN

In computing, NaN, which stands for Not a Number, is a value or symbol that is usually produced as the result of an operation on invalid input operands, especially in floating point calculations....
, possibly using string argument
nearbyint round floating-point number to nearest integer
nextafter(x,y) returns next representable value after x (towards y)
nexttoward(x,y) same as nextafter, except y is always a long double
remainder(x,y) calculates remainder, as required by IEC 60559
remquo(x,y,p) same as remainder, but store quotient (as int) at target of pointer p
rint round to integer (returns int) using current rounding mode
round round to integer (returns int)
scalbln(x,n) x * FLT_RADIXn (n is long)
scalbn(x,n) x * FLT_RADIXn (n is int)
tgamma gamma function
Gamma function

In mathematics, the Gamma function is an extension of the factorial function to real number and complex number numbers. For a complex number z with positive real part the Gamma function is defined by...
trunc truncate floating-point number


XSI Extensions

Extra functions may be available as X/Open
X/Open

X/Open Company, Ltd. was a consortium founded by several European UNIX systems manufacturers in 1984 to identify and promote open standards in the field of information technology....
 System Interfaces Extensions. These are not present in any ANSI or ISO C standard.

Name Description
j0(x) Bessel function
Bessel function

In mathematics, Bessel functions, first defined by the mathematician Daniel Bernoulli and generalized by Friedrich Bessel, are Canonical#Mathematics solutions y of Bessel's differential equation:...
 of x of the first kind of order 0
j1(x) Bessel function of x of the first kind of order 1
jn(n,x) Bessel function of x of the first kind of order n
scalb(x,y) x * FLT_RADIXy (x and y are doubles)
y0(x) Bessel function of x of the second kind of order 0
y1(x) Bessel function of x of the second kind of order 1
yn(n,x) Bessel function of x of the second kind of order n


The double-to-string conversion functions ecvt, fcvt and gcvt have been deprecated in favour of sprintf.

Extra links

  • , a reference of all math.h functions