C mathematical functions: Difference between revisions
Christian75 (talk | contribs) Removing iw |
m Reverted edits by Christian75 (talk) to last version by 1exec1 |
||
Line 179: | Line 179: | ||
[[Category:C Standard Library]] |
[[Category:C Standard Library]] |
||
[[cs:Math.h]] |
|||
[[de:Math.h]] |
|||
[[es:Math.h]] |
|||
[[ko:Math.h]] |
|||
[[it:Math.h]] |
|||
[[pt:Math.h]] |
|||
[[ru:Math.h]] |
|||
[[sk:Math.h]] |
|||
[[tr:Math.h]] |
|||
[[uk:Math.h]] |
Revision as of 22:40, 31 October 2011
C standard library (libc) |
---|
General topics |
Miscellaneous headers |
C mathematical operations are a group of functions in the standard library of the C programming language[citation needed] implementing basic mathematical functions. Most of the functions involve the use of floating point numbers. [1] Most of the functions involve the use of floating point numbers. Different C standards provide different albeit backwards-compatible, sets of functions. C mathematical functions are inherited in C++.
Overview of functions
Most of the mathematical functions are placed in math.h header (cmath header in C++). The functions that operate on integers, such as abs, labs, div, and ldiv, are instead specified in the stdlib.h header (cstdlib header in C++).
Any functions that operate on angles use radians as the unit of angle.[1]
In C89, all functions accept only the type double for the floating-point arguments. In C99, this limitation was fixed by introducing new sets of functions with f and l suffixes that work on float and long double arguments respectively.
- absolute value of an integral value , , - computes
- - computes absolute value of a floating point value
- , , - computes the quotient and remainder of integer division
- - remainder of the floating point division operation
- - signed remainder of the division operation
- - signed remainder as well as the three last bits of the division operation
- - fused multiply-add operation
- - larger of two floating point values
- - smaller of two floating point values
- - positive difference of two floating point values
- not-a-number (NaN) , , - returns a
- Exponential functions
- e raised to the given power - returns
- - returns 2 raised to the given power
- - returns e raised to the given power, minus one
- - computes natural (base e) logarithm (to base e)
- - computes common (base 10) logarithm
- - computes natural logarithm (to base e) of 1 plus the given number
- - extracts exponent of the number
- - extracts exponent of the number
- Power functions
- square root - computes
- cubic root - computes
- - computes square root of the sum of the squares of two given numbers
- - raises a number to the given power
- Trigonometric functions
- sine - computes
- cosine - computes
- tangent - computes
- arc sine - computes
- arc cosine - computes
- arc tangent - computes
- - computes arc tangent, using signs to determine quadrants
- Hyperbolic functions
- - computes hyperbolic sine
- - computes hyperbolic cosine
- - computes hyperbolic tangent
- - computes hyperbolic arc sine
- - computes hyperbolic arc cosine
- - computes hyperbolic arc tangent
- Error and gamma functions
- error function - computes
- complementary error function - computes
- gamma function - computes natural logarithm of the
- - computes gamma function
- Nearest integer floating point operations
- - returns the nearest integer not less than the given value
- - returns the nearest integer not greater than the given value
- - returns the nearest integer not greater in magnitude than the given value
- , , - returns the nearest integer, rounding away from zero in halfway cases
- - returns the nearest integer using current rounding mode
- , , - returns the nearest integer using current rounding mode with exception if the result differs
- Floating point manipulation functions
- - decomposes a number into significand and a power of 2
- - multiplies a number by 2 raised to a power
- - decomposes a number into integer and fractional parts
- , - multiplies a number by FLT_RADIX raised to a power
- , - returns next representable floating point value towards the given value
- - copies the sign of a floating point value
- Classification
- - categorizes the given floating point value
- - checks if the given number has finite value
- - checks if the given number is infinite
- - checks if the given number is NaN
- - checks if the given number is normal
- - checks if the given number is negative
Floating point environment
![]() | This section needs expansion. You can help by adding to it. (October 2011) |
Declaration | Description |
---|---|
int (int excepts); |
clear exceptions specified by excepts |
int (fenv_t *penv); |
store current floating-point environment in penv |
int (fexcept_t *pflag, int excepts); |
store current status flags in pflags |
int (void); |
retrieve current rounding direction |
int (fenv_t *penv); |
save current floating-point environment to penv and clear all exceptions |
int (int excepts); |
raise floating-point exceptions |
int (const fenv_t *penv); |
set current floating-point environment to penv |
int (const fexcept_t *pflags, int excepts); |
set current status flags to those stored in pflags |
int (int round); |
set current rounding direction to round |
int (int excepts); |
test whether certain exceptions have been raised |
int (const fenv_t *penv); |
restore floating-point environment penv, but keep current exceptions |
int fesetprec(int prec) |
Sets the precision mode to the value specified by prec. |
Complex numbers
C99 adds a new _Complex keyword that provides support for complex numbers. Any floating point type can be modified with _Complex. In that case, a variable of such type contains a pair of floating point numbers and in such a way defines a complex number. C++ does not provide complex numbers in backwards compatible way. As an alternative, std::complex
can be used.
All operations on complex numbers are defined in complex.h header.
- Basic operations
- absolute value - computes
- argument of a complex number - computes
- imaginary part of a complex number - computes
- real part of a complex number - computes
- complex conjugate - computes
- Riemann sphere - computes complex projection into the
- Exponentiation operations
- exponential - computes complex
- logarithm - computes complex
- square root - computes complex
- power - computes complex
- Trigonometric operations
- complex sine - computes
- complex cosine - computes
- complex tangent - computes
- complex arc sine - computes
- complex arc cosine - computes
- complex arc tangent - computes
- Hyperbolic operations
- complex hyperbolic sine - computes
- complex hyperbolic cosine - computes
- complex hyperbolic tangent - computes
- complex hyperbolic arc sine - computes
- complex hyperbolic arc cosine - computes
- complex hyperbolic arc tangent - computes
Type-generic functions
![]() | This section needs expansion. You can help by adding to it. (October 2011) |
The header tgmath.h defines a type-generic macro for each mathematical function, so that the same function name can be used to call functions accepting different types of the arguments.
References
- ^ a b ISO/IEC 9899:1999 specification (PDF). p. 212, § 7.12.
External links
![](http://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.png)
- The Single UNIX Specification, Version 4 from The Open Group : mathematical declarations – Base Definitions Reference,
- Dinkumware math.h reference, a reference of all
math.h
functions - C++ reference for math functions inherited from C