Mathematical Functions for Real Floating Types

The mathematical functions declared in math.h were originally defined only for double values, with return values and parameters of type double. These functions are shown in Table 1-30.

Table 1-30. The traditional mathematical functions for double values

Mathematical function

C function

Trigonometric functions:

  • Sine, cosine, tangent

  • Arcsine, arccosine

  • Arctangent

sin(), cos(), tan()
asin(), acos()
atan(), atan2()

Hyperbolic functions

sinh(), cosh(), tanh()

Powers, square root

pow(), sqrt(),

Exponential functions

exp(), frexp(), ldexp()

Logarithms

log(), log10()

Next integer

ceil(), floor()

Absolute value

fabs()

Remainder (modular division)

fmod()

Separation of integer and fractional parts

modf()

ANSI C99 introduces new versions of the functions listed in Table 1-30 for the types float and long double. The names of these functions end with f or l; for example:

double cos( double x );
float cosf( float x );
long double cosl( long double x );

New standard mathematical functions for real numbers have also been added in math.h , as listed in Table 1-31. These functions also have versions for float and long double, with names ending in f and l.

Table 1-31. New mathematical functions for double values in ANSI C99

Mathematical function

C function

Trigonometric functions

asinh(), acosh(), atanh()

Exponential functions

exp2(), expm1()

Logarithms

ilogb(), logb(), log1p(), log2()

Roots ...

Get C Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.