C mathematical functions

C mathematical functions

C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions.[1][2] 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++.

Contents

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 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.[3]

  • abs, labs, llabs - computes absolute value of an integral value
  • fabs - computes absolute value of a floating point value
  • div, ldiv, lldiv - computes the quotient and remainder of integer division
  • fmod- remainder of the floating point division operation
  • remainder - signed remainder of the division operation
  • remquo - signed remainder as well as the three last bits of the division operation
  • fma - fused multiply-add operation
  • fmax - larger of two floating point values
  • fmin - smaller of two floating point values
  • fdim - positive difference of two floating point values
  • nan, nanf, nanl - returns a not-a-number (NaN)
Exponential functions
  • exp - returns e raised to the given power
  • exp2 - returns 2 raised to the given power
  • expm1 - returns e raised to the given power, minus one
  • log - computes natural (base e) logarithm (to base e)
  • log10 - computes common (base 10) logarithm
  • log1p - computes natural logarithm (to base e) of 1 plus the given number
  • ilogb - extracts exponent of the number
  • logb - extracts exponent of the number
Power functions
  • sqrt - computes square root
  • cbrt - computes cubic root
  • hypot - computes square root of the sum of the squares of two given numbers
  • pow - raises a number to the given power
Trigonometric functions
Hyperbolic functions
  • sinh - computes hyperbolic sine
  • cosh - computes hyperbolic cosine
  • tanh - computes hyperbolic tangent
  • asinh - computes hyperbolic arc sine
  • acosh - computes hyperbolic arc cosine
  • atanh - computes hyperbolic arc tangent
Error and gamma functions
Nearest integer floating point operations
  • ceil - returns the nearest integer not less than the given value
  • floor - returns the nearest integer not greater than the given value
  • trunc - returns the nearest integer not greater in magnitude than the given value
  • round, lround, llround - returns the nearest integer, rounding away from zero in halfway cases
  • nearbyint - returns the nearest integer using current rounding mode
  • rint, lrint, llrint - returns the nearest integer using current rounding mode with exception if the result differs
Floating point manipulation functions
  • frexp - decomposes a number into significand and a power of 2
  • ldexp - multiplies a number by 2 raised to a power
  • modf - decomposes a number into integer and fractional parts
  • scalbn, scalbln - multiplies a number by FLT_RADIX raised to a power
  • nextafter, nexttoward - returns next representable floating point value towards the given value
  • copysign - copies the sign of a floating point value
Classification
  • fpclassify - categorizes the given floating point value
  • isfinite - checks if the given number has finite value
  • isinf - checks if the given number is infinite
  • isnan - checks if the given number is NaN
  • isnormal - checks if the given number is normal
  • signbit - checks if the given number is negative

Floating point environment

C99 adds several functions and types for fine-grained control of floating point computations.[3] The additional functions and types are defined in fenv.h header (cfenv in C++).

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
Exponentiation operations
Trigonometric operations
  • csin - computes complex sine
  • ccos - computes complex cosine
  • ctan - computes complex tangent
  • casin - computes complex arc sine
  • cacos - computes complex arc cosine
  • catan - computes complex arc tangent
Hyperbolic operations
  • csinh - computes complex hyperbolic sine
  • ccosh - computes complex hyperbolic cosine
  • ctanh - computes complex hyperbolic tangent
  • casinh - computes complex hyperbolic arc sine
  • cacosh - computes complex hyperbolic arc cosine
  • catanh - computes complex hyperbolic arc tangent

Type-generic functions

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.

Random number generation

The header stdlib.h (cstdlib in C++) defines several functions that can be used for statistically random number generation[4]

  • rand - generates a pseudo-random number
  • srand - initializes a pseudo-random number generator

References

  1. ^ a b ISO/IEC 9899:1999 specification. p. 212, § 7.12. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf. 
  2. ^ Prata, Stephen (2004). C primer plus. Sams Publishing. Appendix B, Section V: The Standard ANSI C Library with C99 Additions. ISBN 0-672-32696-5. 
  3. ^ a b Prata, Stephen (2004). C primer plus. Sams Publishing. Appendix B, Section VIII: C99 Numeric Computational Enhancements. ISBN 0-672-32696-5. 
  4. ^ "GNU C Library -- Mathematics". http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_17.html. Retrieved 2 November 2011. 

External links


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Digital Library of Mathematical Functions — The Digital Library of Mathematical Functions (DLMF) is an online project at the National Institute of Standards and Technology to develop a major resource of mathematical reference data for special functions and their applications. It is… …   Wikipedia

  • Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables — Titelseite der Ausgabe von 1965 Abramowitz Stegun oder Abramowitz und Stegun ist die häufig verwendete umgangssprachliche Bezeichnung für ein bekanntes mathematisches Nachschlagewerk mit dem (englischen) Originaltitel Handbook of Mathematical… …   Deutsch Wikipedia

  • Handbook of Mathematical Functions — Titelseite der Ausgabe von 1965 Abramowitz Stegun oder Abramowitz und Stegun ist die häufig verwendete umgangssprachliche Bezeichnung für ein bekanntes mathematisches Nachschlagewerk mit dem (englischen) Originaltitel Handbook of Mathematical… …   Deutsch Wikipedia

  • List of mathematical functions — In mathematics, several functions or groups of functions are important enough to deserve their own names. This is a listing of pointers to those articles which explain these functions in more detail. There is a large theory of special functions… …   Wikipedia

  • Mathematical model — Not to be confused with the same term that is used in model theory, a branch of mathematical logic. An artifact that is used to illustrate a mathematical idea may also be called a mathematical model, the usage of which is the reverse of the sense …   Wikipedia

  • Mathematical table — Before calculators were cheap and plentiful, people would use mathematical tables lists of numbers showing the results of calculation with varying arguments to simplify and drastically speed up computation. Tables of logarithms and trigonometric… …   Wikipedia

  • Mathematical Tables Project — The Mathematical Tables Project was one of the largest and most sophisticated computing organizations that operated prior to the invention of the digital electronic computer. Begun in 1938 as a project of the Works Progress Administration (WPA),… …   Wikipedia

  • Mathematical notation — For information on rendering mathematical formulas in Wikipedia, see Help:Formula. See also: Table of mathematical symbols Mathematical notation is a system of symbolic representations of mathematical objects and ideas. Mathematical notations are …   Wikipedia

  • mathematical function program — noun Any of a set of subroutines supplied with a language or system that can be called to perform standard mathematical functions efficiently …   Wiktionary

  • Mathematical logic — (also known as symbolic logic) is a subfield of mathematics with close connections to foundations of mathematics, theoretical computer science and philosophical logic.[1] The field includes both the mathematical study of logic and the… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”