7.4.7 <math.h>

Performs various mathematical operations.

The following constants (macros) are all implementation-defined.

Type

Definition Name

Description

Constant
(macro)

EDOM

Indicates the value to be set in errno if the value of a parameter input to a function is outside the range of values defined in the function.

ERANGE

Indicates the value to be set in errno if the result of a function cannot be represented as a double type value, or if an overflow or an underflow occurs.

HUGE_VAL

HUGE_VALF <-lang=c99>

HUGE_VALL <-lang=c99>

Indicates the value for the function return value if the result of a function overflows.

INFINITY <-lang=c99>

Expanded to a float-type constant expression that represents positive or unsigned infinity.

NAN <-lang=c99>

Defined when float-type qNaN is supported.

FP_INFINITE <-lang=c99>

FP_NAN <-lang=c99>

FP_NORMAL <-lang=c99>

FP_SUBNORMAL <-lang=c99>

FP_ZERO <-lang=c99>

These indicate exclusive types of floating-point values.

FP_FAST_FMA <-lang=c99>

FP_FAST_FMA <-lang=c99>

FFP_FAST_FMAFL <-lang=c99>

Defined when the Fma function is executed at the same or higher speed than a multiplication and an addition with double-type operands.

FP_ILOGB0 <-lang=c99>

FP_ILOGBNAN <-lang=c99>

These are expanded to an integer constant expression of the value returned by ilogb when they are 0 or not-a-number, respectively.

MATH_ERRNO <-lang=c99>

MATH_ERREXCEPT <-lang=c99>

These are expanded to integer constants 1 and 2, respectively.

math_errhandling <-lang=c99>

Expanded to an int-type expression whose value is a bitwise logical OR of MATH_ERRNO and MATH_ERREXCEPT.

Type

float_t <-lang=c99>

double_t <-lang=c99>

These are floating-point types having the same width as float and double, respectively.

Function (macro)

fpclassify <-lang=c99>

Classifies argument values into not-a-number, infinity, normalized number, denormalized number, and 0.

isfinite <-lang=c99>

Determines whether the argument is a finite value.

isinf <-lang=c99>

Determines whether the argument is infinity.

isnan <-lang=c99>

Determines whether the argument is a not-a-number.

isnormal <-lang=c99>

Determines whether the argument is a normalized number.

signbit <-lang=c99>

Determines whether the sign of the argument is negative.

isgreater <-lang=c99>

Determines whether the first argument is greater than the second argument.

isgreaterequal <-lang=c99>

Determines whether the first argument is equal to or greater than the second argument.

isless <-lang=c99>

Determines whether the first argument is smaller than the second argument.

islessequal <-lang=c99>

Determines whether the first argument is equal to or smaller than the second argument.

islessgreater <-lang=c99>

Determines whether the first argument is smaller or greater than the second argument.

isunordered <-lang=c99>

Determines whether the arguments are not ordered.

Function

acos

acosf

acosl

Calculates the arc cosine of a floating-point number.

asin

asinf

asinl

Calculates the arc sine of a floating-point number.

atan

atanf

atanl

Calculates the arc tangent of a floating-point number.

atan2

atan2f

atan2l

Calculates the arc tangent of the result of a division of two floating-point numbers.

cos

cosf

cosl

Calculates the cosine of a floating-point radian value.

sin

sinf

sinl

Calculates the sine of a floating-point radian value.

tan

tanf

tanl

Calculates the tangent of a floating-point radian value.

cosh

coshf

coshl

Calculates the hyperbolic cosine of a floating-point number.

Function

sinh

sinhf

sinhl

Calculates the hyperbolic sine of a floating-point number.

tanh

tanhf

tanhl

Calculates the hyperbolic tangent of a floating-point number.

exp

expf

expl

Calculates the exponential function of a floating-point number.

frexp

frexpf

frexpl

Breaks a floating-point number into a [0.5, 1.0) value and a power of 2.

ldexp

ldexpf

ldexpl

Multiplies a floating-point number by a power of 2.

log

logf

logl

Calculates the natural logarithm of a floating-point number.

log10

log10f

log10l

Calculates the base-ten logarithm of a floating-point number.

modf

modff

modfl

Breaks a floating-point number into integral and fractional parts.

pow

powf

powl

Calculates a power of a floating-point number.

sqrt

sqrtf

sqrtl

Calculates the positive square root of a floating-point number.

ceil

ceilf

ceill

Calculates the smallest integral value not less than or equal to the given floating-point number.

fabs

fabsf

fabsl

Calculates the absolute value of a floating-point number.

floor

floorf

floorl

Calculates the largest integral value not greater than or equal to the given floating-point number.

fmod

fmodf

fmodl

Calculates the remainder of a division of two floating-point numbers.

acosh <-lang=c99>

acoshf <-lang=c99>

acoshl <-lang=c99>

Calculates the hyperbolic arc cosine of a floating-point number.

asinh <-lang=c99>

asinhf <-lang=c99>

asinhl <-lang=c99>

Calculates the hyperbolic arc sine of a floating-point number.

Function

atanh <-lang=c99>

atanhf <-lang=c99>

atanhl <-lang=c99>

Calculates the hyperbolic arc tangent of a floating-point number.

exp2 <-lang=c99>

exp2f <-lang=c99>

exp2l <-lang=c99>

Calculates the value of 2 raised to the power x.

expm1 <-lang=c99>

expm1f <-lang=c99>

expm1l <-lang=c99>

Calculates the natural logarithm raised to the power x and subtracts 1 from the result.

ilogb <-lang=c99>

ilogbf <-lang=c99>

ilogbl <-lang=c99>

Extracts the exponent of x as a signed int value.

log1p <-lang=c99>

log1pf <-lang=c99>

log1pl <-lang=c99>

Calculates the natural logarithm of the argument + 1.

log2 <-lang=c99>

log2f <-lang=c99>

log2l <-lang=c99>

Calculates the base-2 logarithm.

logb <-lang=c99>

logbf <-lang=c99>

logbl <-lang=c99>

Extracts the exponent of x as a signed integer.

scalbn <-lang=c99>

scalbnf <-lang=c99>

scalbnl <-lang=c99>

scalbln <-lang=c99>

scalblnf <-lang=c99>

scalblnl <-lang=c99>

Calculates x × FLT_RADIXn.

cbrt <-lang=c99>

cbrtf <-lang=c99>

cbrtl <-lang=c99>

Calculates the cube root of a floating-point number.

hypot <-lang=c99>

hypotf <-lang=c99>

hypotl <-lang=c99>

Calculates the square root of the sum of squares of two

 

parameters ( ).

erf <-lang=c99>

erff <-lang=c99>

erfl <-lang=c99>

Calculates the error function.

erfc <-lang=c99>

erfcf <-lang=c99>

erfcl <-lang=c99>

Calculates the complementary error function.

lgamma <-lang=c99>

lgammaf <-lang=c99>

lgammal <-lang=c99>

Calculates the natural logarithm of the absolute value of the gamma function.

tgamma <-lang=c99>

tgammaf <-lang=c99>

tgammal <-lang=c99>

Calculates the gamma function.

nearbyint <-lang=c99>

nearbyintf <-lang=c99>

nearbyintl <-lang=c99>

Rounds a floating-point number to an integer in the floating-point representation according to the current rounding direction.

Function

rint <-lang=c99>

rintf <-lang=c99>

rintl <-lang=c99>

Equivalent to nearbyint except that this function group may generate floating-point exception.

lrint <-lang=c99>

lrintf <-lang=c99>

lrintl <-lang=c99>

llrint <-lang=c99>

llrintf <-lang=c99>

llrintl <-lang=c99>

Rounds a floating-point number to the nearest integer according to the rounding direction.

round <-lang=c99>

roundf <-lang=c99>

roundl <-lang=c99>

Rounds a floating-point number to the nearest integer in the floating-point representation.

lround <-lang=c99>

lroundf <-lang=c99>

lroundl <-lang=c99>

llround <-lang=c99>

llroundf <-lang=c99>

llroundl <-lang=c99>

Rounds a floating-point number to the nearest integer.

trunc <-lang=c99>

truncf <-lang=c99>

truncl <-lang=c99>

Rounds a floating-point number to the nearest integer.

remainder <-lang=c99>

remainderf <-lang=c99>

remainderl <-lang=c99>

Calculates remainder x REM y specified in the IEEE60559 standard.

remquo <-lang=c99>

remquof <-lang=c99>

remquol <-lang=c99>

Calculates the value having the same sign as x/y and the absolute value congruent modulo-2n to the absolute value of the quotient.

copysign <-lang=c99>

copysignf <-lang=c99>

copysignl <-lang=c99>

Generates a value consisting of the given absolute value and sign.

nan <-lang=c99>

nanf <-lang=c99>

nanl <-lang=c99>

nan("n string") is equivalent to ("NAN(n string)", (char**) NULL).

nextafter <-lang=c99>

nextafterf <-lang=c99>

nextafterl <-lang=c99>

Converts a floating-point number to the type of the function and calculates the representable value following the converted number on the real axis.

nexttoward <-lang=c99>

nexttowardf <-lang=c99>

nexttowardl <-lang=c99>

Equivalent to the nextafter function group except that the second argument is of type long double and returns the second argument after conversion to the type of the function.

fdim <-lang=c99>

fdimf <-lang=c99>

fdiml <-lang=c99>

Calculates the positive difference.

fmax <-lang=c99>

fmaxf <-lang=c99>

fmaxl <-lang=c99>

Obtains the greater of two values.

fmin <-lang=c99>

fminf <-lang=c99>

fminl <-lang=c99>

Obtains the smaller of two values.

Function

fma <-lang=c99>

fmaf <-lang=c99>

fmal <-lang=c99>

Calculates (d1 * d2) + d3 as a single ternary operation.

 

Operation in the event of an error is described below.

(1)

Domain error

A domain error occurs if the value of a parameter input to a function is outside the domain over which the mathematical function is defined. In this case, the value of EDOM is set in errno. The function return value in implementation-defined.

(2)

Range error

A range error occurs if the result of a function cannot be represented as a value of the double type. In this case, the value of ERANGE is set in errno. If the result overflows, the function returns the value of HUGE_VAL, HUGE_VALF, or HUGE_VALL with the same sign as the correct value of the function. If the result underflows, 0 is returned as the return value.

Notes 1.

If there is a possibility of a domain error resulting from a <math.h> function call, it is dangerous to use the resultant value directly. The value of errno should always be checked before using the result in such cases.

[Format]

.

.

.

1 x=asin(a);

2 if (errno==EDOM)

3 printf ("error\n");

4 else

5 printf ("result is : %lf\n",x);

.

.

.

In line 1, the arc sine value is computed using the asin function. If the value of argument a is outside the asin function domain [–1.0, 1.0], the EDOM value is set in errno. Line 2 determines whether a domain error has occurred. If a domain error has occurred, error is output in line 3. If there is no domain error, the arc sine value is output in line 5.

Notes 2.

Whether or not a range error occurs depends on the internal representation format of floating-point types determined by the compiler. For example, if an internal representation format that allows an infinity to be represented as a value is used, <math.h> library functions can be implemented without causing range errors.

Implementation-Defined Specifications

Item

Compiler Specifications

Value returned by a mathematical function if an input argument is out of the range

A not-a-number is returned. For details on the format of not-a-numbers, refer to section "(5) Floating-Point Number Specifications" in "4.1.4 Internal Data Representation and Areas".

Whether errno is set to the value of macro ERANGE if an underflow error occurs in a mathematical function

For the functions that set errno to the value of ERANGE, see "10.5.6 Standard Library Error Messages". The other functions do not set errno to ERANGE.

Whether a range error occurs if the second argument in the fmod function is 0

A range error occurs.

For details of the return value from fmod, see "fmod/fmodf/fmodl" in "7.4.7 <math.h>".

 

acos/acosf/acosl

Calculates the arc cosine of a floating-point number.

[Format]

#include <math.h>
double acos (double d)
float acosf (float d)
long double acosl (long double d);


[Parameters]

d Floating-point number for which arc cosine is to be computed

[Return values]

Normal: Arc cosine of d
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs for a value of d not in the range [–1.0, +1.0].

The acos function returns the arc cosine in the range [0, π] by the radian.

 

asin/asinf/asinl

Calculates the arc sine of a floating-point number.

[Format]

#include <math.h>
double asin (double d)
float asinf (float d)
long double asinl (long double);


[Parameters]

d Floating-point number for which arc sine is to be computed

[Return values]

Normal: Arc sine of d
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs for a value of d not in the range [–1.0, +1.0].

The asin function returns the arc sine in the range [–π/2, +π/2] by the radian.

 

atan/atanf/atanl

Calculates the arc tangent of a floating-point number.

[Format]

#include <math.h>
double atan (double d)
float atanf (float d)
long double atanl (long double d);


[Parameters]

d Floating-point number for which arc tangent is to be computed

[Return values]

Arc tangent of d

[Remarks]

The atan function returns the arc tangent in the range (–π/2, +π/2) by the radian.

 

atan2/atan2f/atan2l

Calculates the arc tangent of the division of two floating-point numbers.

[Format]

#include <math.h>
double atan2 (double y, double x)
float atan2f (float y, float x)
long double atan2l (long double y, long double x);


[Parameters]

x Divisor
y Dividend

[Return values]

Normal: Arc tangent value when y is divided by x
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if the values of both x and y are 0.0.

The atan2 function returns the arc tangent in the range (–π, +π) by the radian. The meaning of the atan2 function is illustrated in Figure 7.1. As shown in the figure, the result of the atan2 function is the angle between the X-axis and a straight line passing through the origin and point (x, y).

If y = 0.0 and x is negative, the result is π. If x = 0.0, the result is ±π/2, depending on whether y is positive or negative.

Figure 7.1

Meaning of atan2 Function

 

cos/cosf/cosl

Calculates the cosine of a floating-point radian value.

[Format]

#include <math.h>
double cos (double d)
float cosf (float d)
long double cosl (long double d);


[Parameters]

d Radian value for which cosine is to be computed

[Return values]

Cosine of d

 

sin/sinf/sinl

Calculates the sine of a floating-point radian value.

[Format]

#include <math.h>
double sin (double d)
float sinf (float d)
long double sinl (long double d);


[Parameters]

d Radian value for which sine is to be computed

[Return values]

Sine of d

 

tan/tanf/tanl

Calculates the tangent of a floating-point radian value.

[Format]

#include <math.h>
double tan (double d)
float tanf (float d)
long double tanl (long double d);


[Parameters]

d Radian value for which tangent is to be computed

[Return values]

Tangent of d

 

cosh/coshf/coshl

Calculates the hyperbolic cosine of a floating-point number.

[Format]

#include <math.h>
double cosh (double d)
float coshf (float d)
long double coshl (long double d);


[Parameters]

d Floating-point number for which hyperbolic cosine is to be computed

[Return values]

Hyperbolic cosine of d

 

sinh/sinhf/sinhl

Calculates the hyperbolic sine of a floating-point number.

[Format]

#include <math.h>
double sinh (double d)
float sinhf (float d)
long double sinhl (long double d);


[Parameters]

d Floating-point number for which hyperbolic sine is to be computed

[Return values]

Hyperbolic sine of d

 

tanh/tanhf/tanhl

Calculates the hyperbolic tangent of a floating-point number.

[Format]

#include <math.h>
double tanh (double d)
float tanhf (float d)
long double tanhl (long double d);


[Parameters]

d Floating-point number for which hyperbolic tangent is to be computed

[Return values]

Hyperbolic tangent of d

 

exp/expf/expl

Calculates the exponential function of a floating-point number.

[Format]

#include <math.h>
double exp (double d)
float expf (float d)
long double expl (long double d);


[Parameters]

d Floating-point number for which exponential function is to be computed

[Return values]

Exponential function value of d

 

frexp/frexpf/frexpl

Breaks a floating-point number into a [0.5, 1.0) value and a power of 2.

[Format]

#include <math.h>
double frexp (double value, double long *exp);
float frexpf (float value, long * exp);
long double frexpl (long double value, long *exp);


[Parameters]

value Floating-point number to be broken into a [0.5, 1.0) value and a power of 2
exp Pointer to storage area that holds power-of-2 value

[Return values]

If value is 0.0: 0.0
If value is not 0.0: Value of ret defined by ret * 2value pointed to by exp = value

[Remarks]

The frexp function breaks value into a [0.5, 1.0) value and a power of 2. It stores the resultant power-of-2 value in the area pointed to by exp.

The frexp function returns the return value ret in the range [0.5, 1.0) or as 0.0.

If value is 0.0, the contents of the int storage area pointed to by exp and the value of ret are both 0.0.

 

ldexp/ldexpf/ldexpl

Multiplies a floating-point number by a power of 2.

[Format]

#include <math.h>
double ldexp (double e, long f);
float ldexpf (float e, long f);
long double ldexpl (long double e, long f);


[Parameters]

e Floating-point number to be multiplied by a power of 2
f Power-of-2 value

[Return values]

Result of e * 2f operation

 

log/logf/logl

Calculates the natural logarithm of a floating-point number.

[Format]

#include <math.h>
double log (double d);
float logf (float d);
long double logl (long double d);


[Parameters]

d Floating-point number for which natural logarithm is to be computed

[Return values]

Normal: Natural logarithm of d
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if d is negative.

A range error occurs if d is 0.0.

 

log10/log10f/log10l

Calculates the base-ten logarithm of a floating-point number.

[Format]

#include <math.h>
double log10 (double d);
float log10f(float d);
long double log10l(long double d);


[Parameters]

d Floating-point number for which base-ten logarithm is to be computed

[Return values]

Normal: Base-ten logarithm of d
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if d is negative.

A range error occurs if d is 0.0.

 

modf/modff/modfl

Breaks a floating-point number into integral and fractional parts.

[Format]

#include <math.h>
double modf (double a, double*b);
float modff (float a, float *b);
long double modfl (long double a, long double *b);


[Parameters]

a Floating-point number to be broken into integral and fractional parts
b Pointer indicating storage area that stores integral part

[Return values]

Fractional part of a

 

pow/powf/powl

Calculates a power of floating-point number.

[Format]

#include <math.h>
double pow (double x, double y);
float powf (float x, float y);
long double powl (long double x, long double y);


[Parameters]

x Value to be raised to a power
y Power value

[Return values]

Normal: Value of x raised to the power y
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if x is 0.0 and y is 0.0 or less, or if x is negative and y is not an integer.

 

sqrt/sqrtf/sqrtl

Calculates the positive square root of a floating-point number.

[Format]

#include <math.h>
double sqrt (double d);
float sqrtf (float d);
long double sqrtl (long double d);


[Parameters]

d Floating-point number for which positive square root is to be computed

[Return values]

Normal: Positive square root of d
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if d is negative.

 

ceil/ceilf/ceill

Returns the smallest integral value not less than or equal to the given floating-point number.

[Format]

#include <math.h>
double ceil (double d);
float ceilf (float d);
long double ceill ( long double d);


[Parameters]

d Floating-point number for which smallest integral value not less than that number is to be computed

[Return values]

Smallest integral value not less than or equal to d

[Remarks]

The ceil function returns the smallest integral value not less than or equal to d, expressed as a double type value. Therefore, if d is negative, the value after truncation of the fractional part is returned.

 

fabs/fabsf/fabsl

Calculates the absolute value of a floating-point number.

[Format]

#include <math.h>
double fabs (double d);
float fabsf (float d);
long double fabsl (long double d);


[Parameters]

d Floating-point number for which absolute value is to be computed

[Return values]

Absolute value of d

 

floor/floorf/floorl

Returns the largest integral value not greater than or equal to the given floating-point number.

[Format]

#include <math.h>
double floor (double d);
float floorf (float d);
long double floorl (long double d);


[Parameters]

d Floating-point number for which largest integral value not greater than that number is to be computed

[Return values]

Largest integral value not greater than or equal to d

[Remarks]

The floor function returns the largest integral value not greater than or equal to d, expressed as a double type value. Therefore, if d is negative, the value after rounding-up of the fractional part is returned.

 

fmod/fmodf/fmodl

Calculates the remainder of a division of two floating-point numbers.

[Format]

#include <math.h>
double fmod (double x, double y);
float fmodf (float x, float y);
long double fmodl (long double x, long double y);


[Parameters]

x Dividend
y Divisor

[Return values]

When y is 0.0: x
When y is not 0.0: Remainder of division of x by y

When y is ±∞: Returns x.

When x is ±∞ or y is 0: Returns not-a-number and sets global variable errno to the value of macro EDOM.

[Remarks]

In the fmod function, the relationship between parameters x and y and return value ret is as follows:

x = y * i + ret (where i is an integer)

The sign of return value ret is the same as the sign of x.

If the quotient of x/y cannot be represented, the value of the result is not guaranteed.

 

acosh/acoshf/acoshl

Calculates the hyperbolic arc cosine of a floating-point number.

[Format]

#include <math.h>
double acosh(double d);
float acoshf(float d);
long double acoshl(long double d);


[Parameters]

d Floating-point number for which hyperbolic arc cosine is to be computed

[Return values]

Normal: Hyperbolic arc cosine of d
Abnormal: Domain error: Returns NaN.

Error conditions: A domain error occurs when d is smaller than 1.0.

[Remarks]

The acosh function returns the hyperbolic arc cosine in the range [0, +∞].

 

asinh/asinhf/asinhl

Calculates the hyperbolic arc sine of a floating-point number.

[Format]

#include <math.h>
double asinh(double d);
float asinhf(float d);
long double asinhl(long double d);


[Parameters]

d Floating-point number for which hyperbolic arc sine is to be computed

[Return values]

Hyperbolic arc sine of d

 

atanh/atanhf/atanhl

Calculates the hyperbolic arc tangent of a floating-point number.

[Format]

#include <math.h>
double atanh(double d);
float atanhf(float d);
long double atanhl(long double d);


[Parameters]

d Floating-point number for which hyperbolic arc tangent is to be computed

[Return values]

Normal: Hyperbolic arc tangent of d

Abnormal: Domain error: Returns HUGE_VAL, HUGE_VALF, or HUGE_VALL depending on the function.

Range error: Returns not-a-number.

[Remarks]

A domain error occurs for a value of d not in the range [–1, +1]. A range error may occur for a value of d equal to –1 or 1.

exp2/exp2f/exp2l

Calculates the value of 2 raised to the power d.

[Format]

#include <math.h>
double exp2(double d);
float exp2f(float d);
long double exp2l(long double d);


[Parameters]

d Floating-point number for which exponential function is to be computed

[Return values]

Normal: Exponential function value of 2

Abnormal: Range error: Returns 0, or returns +HUGE_VAL, +HUGE_VALF, or +HUGE_VALL depending on the function

[Remarks]

A range error occurs if the absolute value of d is too large.

 

expm1/expm1f/expm1l

Calculates the value of natural logarithm base e raised to the power d and subtracts 1 from the result.

[Format]

#include <math.h>
double expm1(double d);
float expm1f(float d);
long double expm1l(long double d) ;


[Parameters]

d Power value to which natural logarithm base e is to be raised

[Return values]

Normal: Value obtained by subtracting 1 from natural logarithm base e raised to the power d

Abnormal: Range error: Returns -HUGE_VAL, –HUGE_VALF, or –HUGE_VALL depending on the function.

[Remarks]

expm1(d) provides more accurate calculation than exp(x) – 1 even when d is near to 0.

 

ilogb/ilogbf/ilogbl

Extracts the exponent of d.

[Format]

#include <math.h>
long ilogb(double d);
long ilogbf(float d);
long ilogbl(long double d);


[Parameters]

d Value of which exponent is to be extracted

[Return values]

Normal: Exponential function value of d
d is ∞: INT_MAX
d is not-a-number: FP_ILOGBNAN
d is 0: FP_ILOGBNAN


Abnormal: d is 0 and a range error has occurred: FP_ILOGB0

[Remarks]

A range error may occur if d is 0.

 

log1p/log1pf/log1pl

Calculates the natural logarithm (base e) of d + 1.

[Format]

#include <math.h>
double log1p(double d);
float log1pf(float d);
long double log1pl(long double d);


[Parameters]

d Value for which the natural logarithm of this parameter + 1 is to be computed

[Return values]

Normal: Natural logarithm of d + 1

Abnormal: Domain error: Returns not-a-number.

Range error: Returns –HUGE_VAL, –HUGE_VALF, or –HUGE_VALL depending on the function.

[Remarks]

A domain error occurs if d is smaller than –1.

A range error occurs if d is –1.

log1p(d) provides more accurate calculation than log(1+d) even when d is near to 0.

 

log2/log2f/log2l

Calculates the base-2 logarithm of d.

[Format]

#include <math.h>
double log2(double d);
float log2f(float d);
long double log2l(long double d);


[Parameters]

d Value of which logarithm is to be calculated

[Return values]

Normal: Base-2 logarithm of d
Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if d is a negative value.

 

logb/logbf/logbl

Extracts the exponent of d in internal floating-point representation, as a floating-point value.

[Format]

#include <math.h>
double logb(double d);
float logbf(float d);
long double logbl(long double d);


[Parameters]

d Value of which exponent is to be extracted

[Return values]

Normal: Signed exponent of d

Abnormal: Range error: Returns –HUGE_VAL, –HUGE_VALF, or –HUGE_VALL depending on the function.

[Remarks]

A range error may occur if d is 0.

d is always assumed to be normalized.

 

scalbn/scalbnf/scalbnl/scalbln/scalblnf/scalblnl

Calculates a floating-point number multiplied by a power of radix, which is an integer.

[Format]

#include <math.h>
double scalbn(double d, long e);
float scalbnf(float d, long e);
long double scalbnl(long double d, long e);
double scalbln(double d, long e);
float scalblnf(float d, long int e);
long double scalblnl(long double d, long int e);





[Parameters]

d Value to be multiplied by FLT_RADIX raised to the power e
e Exponent used to compute a power of FLT_RADIX

[Return values]

Normal: Value equal to d multiplied by FLT_RADIX

Abnormal: Range error: Returns –HUGE_VAL, –HUGE_VALF, or –HUGE_VALL depending on the function.

[Remarks]

A range error may occur if d is 0.

FLT_RADIX raised to the power e is not actually calculated.

 

cbrt/cbrtf/cbrtl

Calculates the cube root of a floating-point number.

[Format]

#include <math.h>
double cbrt(double d);
float cbrtf(float d);
long double cbrtl(long double d);


[Parameters]

d Value for which a cube root is to be computed

[Return values]

Cube root of d

 

hypot/hypotf/hypotl

 

Calculates the square root of the sum of squares of floating-point values ( ).

[Format]

#include <math.h>
double hypot(double x, double y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y);


[Parameters]

x, y Values for which the square root of the sum of squares of two parameters ( ) is to be calculated

[Return values]

Normal: Square root of the sum of squares of two parameters ( )

Abnormal: Range error: Returns HUGE_VAL, HUGE_VALF, or HUGE_VALL depending on the function.

[Remarks]

A range error may occur if the result overflows.

 

erf/erff/erfl

Calculates the error function value of a floating-point number.

[Format]

#include <math.h>
double erf(double d);
float erff(float d);
long double erfl(long double d);


[Parameters]

d Value for which the error function value is to be computed

[Return values]

Error function value of d

 

erfc/erfcf/erfcl

Calculates the complementary error function value of a floating-point number.

[Format]

#include <math.h>
double erfc(double d);
float erfcf(float d);
long double erfcl(long double d);


[Parameters]

d Value for which the complementary error function value is to be computed

[Return values]

Complementary error function value of d

[Remarks]

A range error occurs if the absolute value of d is too large.

 

lgamma/lgammaf/lgammal

Calculates the logarithm of the gamma function of a floating-point number.

[Format]

#include <math.h>
double lgamma(double d);
float lgammaf(float d);
long double lgammal(long double d);


[Parameters]

d Value for which the logarithm of the gamma function is to be computed

[Return values]

Normal: Logarithm of gamma function of d

Abnormal: Domain error: Returns HUGE_VAL, HUGE_VALF, or HUGE_VALL with the mathematically correct sign.

Range error: Returns +HUGE_VAL, +HUGE_VALF, or +HUGE_VALL.

[Remarks]

A range error is set if the absolute value of d is too large or small.

A domain error occurs if d is a negative integer or 0 and the calculation result is not representable.

 

tgamma/tgammaf/tgammal

Calculates the gamma function of a floating-point number.

[Format]

#include <math.h>
double tgamma(double d);
float tgammaf(float d);
long double tgammal(long double d);


[Parameters]

d Value for which the gamma function value is to be computed

[Return values]

Normal: Gamma function value of d

Abnormal: Domain error: Returns HUGE_VAL, HUGE_VALF, or HUGE_VALL with the same sign as that of d.

Range error: Returns 0, or returns +HUGE_VAL, +HUGE_VALF, or +HUGE_VALL with the mathematically correct sign depending on the function.

[Remarks]

A range error is set if the absolute value of d is too large or small.

A domain error occurs if d is a negative integer or 0 and the calculation result is not representable.

 

nearbyint/nearbyintf/nearbyintl

Rounds a floating-point number to an integer in the floating-point representation according to the current rounding direction.

[Format]

#include <math.h>
double nearbyint(double d);
float nearbyintf(float d);
long double nearbyintl(long double d);


[Parameters]

d Value to be rounded to an integer in the floating-point format

[Return values]

d rounded to an integer in the floating-point format

[Remarks]

The nearbyint function group does not generate "inexact" floating-point exceptions.

 

rint/rintf/rintl

Rounds a floating-point number to an integer in the floating-point representation according to the current rounding direction.

[Format]

#include <math.h>
double rint(double d);
float rintf(float d);
long double rintl(long double d);


[Parameters]

d Value to be rounded to an integer in the floating-point format

[Return values]

d rounded to an integer in the floating-point format

[Remarks]

The rint function group differs from the nearbyint function group only in that the ring function group may generate "inexact" floating-point exceptions.

 

lrint/lrintf/lrintl/llrint/llrintf/llrintl

Rounds a floating-point number to the nearest integer according to the current rounding direction.

[Format]

#include <math.h>
long int lrint(double d);
long int lrintf(float d);
long int lrintl(long double d);
long long int llrint(double d);
long long int llrintf(float d);
long long int llrintl(long double d);





[Parameters]

d Value to be rounded to an integer

[Return values]

Normal: d rounded to an integer

Abnormal: Range error: Returns an undetermined value.

[Remarks]

A range error may occur if the absolute value of d is too large.

The return value is unspecified when the rounded value is not in the range of the return value type.

 

round/roundf/roundl/lround/lroundf/lroundl/llround/llroundf/llroundl

Rounds a floating-point number to the nearest integer.

[Format]

#include <math.h>
double round(double d);
float roundf(float d);
long double roundl(long double d);
long int lround(double d);
long int lroundf(float d);
long int lroundl(long double d);
long long int llround (double d);
long long int llroundf(float d);
long long int llroundl(long double d);








[Parameters]

d Value to be rounded to an integer

[Return values]

Normal: d rounded to an integer

Abnormal: Range error: Returns an undetermined value.

[Remarks]

A range error may occur if the absolute value of d is too large.

When d is at the midpoint between two integers, the lround function group selects the integer farther from 0 regardless of the current rounding direction. The return value is unspecified when the rounded value is not in the range of the return value type.

 

trunc/truncf/truncl

Rounds a floating-point number to the nearest integer in the floating-point representation.

[Format]

#include <math.h>
double trunc(double d);
float truncf(float d);
long double truncl(long double d);


[Parameters]

d Value to be rounded to an integer in the floating-point representation

[Return values]

d truncated to an integer in the floating-point format

[Remarks]

The trunc function group rounds d so that the absolute value after rounding is not greater than the absolute value of d.

remainder/remainderf/remainderl

Calculates the remainder of a division of two floating-point numbers.

[Format]

#include <math.h>
double remainder(double d1, double d2);
float remainderf(float d1, float d2);
long double remainderl(long double d1, long double d2);


[Parameters]

d1, d2 Values for which remainder of a division is to be computed (d1 / d2)

[Return values]

Remainder of division of d1 by d2

[Remarks]

The remainder calculation by the remainder function group conforms to the IEEE 60559 standard.

 

remquo/remquof/remquol

Calculates the remainder of a division of two floating-point numbers.

[Format]

#include <math.h>
double remquo(double d1, double d2, long *q);
float remquof(float d1, float d2, long *q);
long double remquol(long double d1, long double d2, long *q);


[Parameters]

d1, d2 Values for which remainder of a division is to be computed (d1 / d2)

q Value pointing to the location to store the quotient obtained by remainder calculation

[Return values]

Remainder of division of d1 by d2

[Remarks]

The value stored in the location indicated by q has the same sign as the result of x/y and the integral quotient of modulo-2n x/y (n is an implementation-defined integer equal to or greater than 3).

 

copysign/copysignf/copysignl

Generates a value consisting of the absolute value of d1 and the sign of d2.

[Format]

#include <math.h>
double copysign(double d1, double d2);
float copysignf(float d1, float d2);
long double copysignl(long double d1, long double d2);


[Parameters]

d1 Value of which absolute value is to be used in the generated value

d2 Value of which sign is to be used in the generated value

[Return values]

Normal: Value consisting of absolute value of d1 and sign of d2

Abnormal: Range error: Returns an undetermined value.

[Remarks]

When d1 is a not-a-number, the copysign function group generates a not-a-number with the sign bit of d2.

 

nan/nanf/nanl

Returns not-a-number.

[Format]

#include <math.h>
double nan(const char *c);
float nanf(const char *c);
long double nanl(const char *c);


[Parameters]

c Pointer to a string

[Return values]

qNaN with the contents of the location indicated by c or 0 (when qNaN is not supported)

[Remarks]

The nan("c string") call is equivalent to strtod("NAN(c string)", (char**) NULL). The nanf and nanl calls are equivalent to the corresponding strtof and strtold calls, respectively.

 

nextafter/nextafterf/nextafterl

Calculates the next floating-point representation following d1 in the direction to d2 on the real axis.

[Format]

#include <math.h>
double nextafter(double d1, double d2);
float nextafterf(float d1, float d2);
long double nextafterl(long double d1, long double d2);


[Parameters]

d1 Floating-point value on the real axis

d2 Value indicating the direction viewed from d1, in which a representable floating-point value is to be found

[Return values]

Normal: Representable floating-point value

Abnormal: Range error: Returns HUGE_VAL, HUGE_VALF, or HUGE_VALL with the mathematically correct sign depending on the function.

[Remarks]

A range error may occur if d1 is the maximum finite value that can be represented in its type and the return value is an infinity or cannot be represented in its type.

The nextafter function group returns d2 when d1 is equal to d2.

 

nexttoward/nexttowardf/nexttowardl

Calculates the next floating-point representation following d1 in the direction to d2 on the real axis.

[Format]

#include <math.h>
double nexttoward(double d1, long double d2);
float nexttowardf(float d1, long double d2);
long double nexttowardl(long double d1, long double d2);


[Parameters]

d1 Floating-point value on the real axis

d2 Value indicating the direction viewed from d1, in which a representable floating-point value is to be found

[Return values]

Normal: Representable floating-point value

Abnormal: Range error: Returns HUGE_VAL, HUGE_VALF, or HUGE_VALL with the mathematically correct sign depending on the function

[Remarks]

A range error may occur if d1 is the maximum finite value that can be represented in its value and the return value is an infinity or cannot be represented in its type.

The nexttoward function group is equivalent to the nextafter function group except that d2 is of type long double and returns d2 after conversion depending of the function when d1 is equal to d2.

 

fdim/fdimf/fdiml

Calculates the positive difference between two arguments.

[Format]

#include <math.h>
double fdim(double d1, double d2);
float fdimf(float d1, float d2);
long double fdiml(long double d1, long double d2);


[Parameters]

d1, d2 Values of which difference is to be computed (|d1 - d2|)

[Return values]

Normal: Positive difference between two arguments

Abnormal: Range error: HUGE_VAL, HUGE_VALF, or HUGE_VALL

[Remarks]

A range error may occur if the return value overflows.

 

fmax/fmaxf/fmaxl

Obtains the greater of two arguments.

[Format]

#include <math.h>
double fmax(double d1, double d2);
float fmaxf(float d1, float d2);
long double fmaxl(long double d1, long double d2);


[Parameters]

d1, d2 Values to be compared

[Return values]

Greater of two arguments

[Remarks]

The fmax function group recognizes a not-a-number as a lack of data. When one argument is a not-a-number and the other is a numeric value, the function returns the numeric value.

 

fmin/fminf/fminl

Obtains the smaller of two arguments.

[Format]

#include <math.h>
double fmin(double d1, double d2);
float fminf(float d1, float d2);
long double fminl(long double d1, long double d2);


[Parameters]

d1, d2 Values to be compared

[Return values]

Smaller of two arguments

[Remarks]

The fmin function group recognizes a not-a-number as a lack of data. When one argument is a not-a-number and the other is a numeric value, the function returns the numeric value.

 

fma/fmaf/fmal

Calculates (d1 * d2) + d3 as a single ternary operation.

[Format]

#include <math.h>
double fma(double d1, double d2, double d3);
float fmaf(float d1, float d2, float d3);
long double fmal(long double d1, long double d2, long double d3);


[Return values]

Result of (d1 * d2) + d3 calculated as ternary operation

[Parameters]

d1, d2, d3 Floating-point values

[Remarks]

The fma function group performs calculation as if infinite precision is available and rounds the result only one time in the rounding mode indicated by FLT_ROUNDS.