• No results found

Classification macros

In document Programming languages — C (Page 186-196)

7.12 Mathematics <math.h>

7.12.3 Classification macros

1 In the synopses in this subclause, real-floating indicates that the argument shall be an expression of real floating type.

7.12.3.1 Thefpclassifymacro Synopsis

1 #include <math.h>

int fpclassify(real-floating x);

Description

2 Thefpclassifymacro classifies its argument value as NaN, infinite, normal, subnormal, zero, or into another implementation-defined category. First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then classification is based on the type of the argument.239)

Returns

3 Thefpclassifymacro returns the value of the number classification macro appropriate to the value of its argument.

7.12.3.2 Theisfinitemacro Synopsis

1 #include <math.h>

int isfinite(real-floating x);

Description

2 Theisfinitemacro determines whether its argument has a finite value (zero, subnormal, or normal, and not infinite or NaN). First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.

Returns

3 Theisfinitemacro returns a nonzero value if and only if its argument has a finite value.

7.12.3.3 Theisinfmacro Synopsis

1 #include <math.h>

int isinf(real-floating x);

Description

2 Theisinfmacro determines whether its argument value is an infinity (positive or negative). First, an argument represented in a format wider than its semantic type is converted to its semantic type.

Then determination is based on the type of the argument.

Returns

3 Theisinfmacro returns a nonzero value if and only if its argument has an infinite value.

7.12.3.4 Theisnanmacro Synopsis

1 #include <math.h>

int isnan(real-floating x);

239)Since an expression can be evaluated with more range and precision than its type has, it is important to know the type that classification is based on. For example, a normallong doublevalue might become subnormal when converted to double, and zero when converted tofloat.

ISO/IEC 9899:20172x::(E) diff:::::::::marks— November 6, 2018 N2310

Description

2 Theisnanmacro determines whether its argument value is a NaN. First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.240)

Returns

3 Theisnanmacro returns a nonzero value if and only if its argument has a NaN value.

7.12.3.5 Theisnormalmacro Synopsis

1 #include <math.h>

int isnormal(real-floating x);

Description

2 Theisnormalmacro determines whether its argument value is normal (neither zero, subnormal, infinite, nor NaN). First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.

Returns

3 Theisnormalmacro returns a nonzero value if and only if its argument has a normal value.

7.12.3.6 Thesignbitmacro Synopsis

1 #include <math.h>

int signbit(real-floating x);

Description

2 Thesignbitmacro determines whether the sign of its argument value is negative.241) Returns

3 Thesignbitmacro returns a nonzero value if and only if the sign of its argument value is negative.

7.12.4 Trigonometric functions

7.12.4.1 Theacosfunctions Synopsis

1 #include <math.h>

double acos(double x);

float acosf(float x);

long double acosl(long double x);

Description

2 Theacosfunctions compute the principal value of the arc cosine ofx. A domain error occurs for arguments not in the interval [−1, +1].

Returns

3 Theacosfunctions return arccosxin the interval [0, π] radians.

240)For theisnanmacro, the type for determination does not matter unless the implementation supports NaNs in the evaluation type but not in the semantic type.

241)Thesignbitmacro reports the sign of all values, including infinities, zeros, and NaNs. If zero is unsigned, it is treated as positive.

7.12.4.2 Theasinfunctions Synopsis

1 #include <math.h>

double asin(double x);

float asinf(float x);

long double asinl(long double x);

Description

2 Theasinfunctions compute the principal value of the arc sine ofx. A domain error occurs for arguments not in the interval [−1, +1].

Returns

3 Theasinfunctions return arcsinxin the interval [−π/2, +π/2] radians.

7.12.4.3 Theatanfunctions Synopsis

1 #include <math.h>

double atan(double x);

float atanf(float x);

long double atanl(long double x);

Description

2 Theatanfunctions compute the principal value of the arc tangent ofx. Returns

3 Theatanfunctions return arctanxin the interval [−π/2, +π/2] radians.

7.12.4.4 Theatan2functions Synopsis

1 #include <math.h>

double atan2(double y, double x);

float atan2f(float y, float x);

long double atan2l(long double y, long double x);

Description

2 Theatan2functions compute the value of the arc tangent ofy/x, using the signs of both arguments to determine the quadrant of the return value. A domain error may occur if both arguments are zero.

Returns

3 Theatan2functions return arctany/xin the interval [−π, +π] radians.

7.12.4.5 Thecosfunctions Synopsis

1 #include <math.h>

double cos(double x);

float cosf(float x);

long double cosl(long double x);

Description

2 Thecosfunctions compute the cosine ofx(measured in radians).

Returns

3 Thecosfunctions return cosx.

ISO/IEC 9899:20172x::(E) diff:::::::::marks— November 6, 2018 N2310

7.12.4.6 Thesinfunctions Synopsis

1 #include <math.h>

double sin(double x);

float sinf(float x);

long double sinl(long double x);

Description

2 Thesinfunctions compute the sine ofx(measured in radians).

Returns

3 Thesinfunctions return sinx. 7.12.4.7 Thetanfunctions Synopsis

1 #include <math.h>

double tan(double x);

float tanf(float x);

long double tanl(long double x);

Description

2 Thetanfunctions return the tangent ofx(measured in radians).

Returns

3 Thetanfunctions return tanx.

7.12.5 Hyperbolic functions

7.12.5.1 Theacoshfunctions Synopsis

1 #include <math.h>

double acosh(double x);

float acoshf(float x);

long double acoshl(long double x);

Description

2 Theacoshfunctions compute the (nonnegative) arc hyperbolic cosine ofx. A domain error occurs for arguments less than 1.

Returns

3 Theacoshfunctions return arcoshxin the interval [0, +∞].

7.12.5.2 Theasinhfunctions Synopsis

1 #include <math.h>

double asinh(double x);

float asinhf(float x);

long double asinhl(long double x);

Description

2 Theasinhfunctions compute the arc hyperbolic sine ofx. Returns

3 Theasinhfunctions return arsinhx.

7.12.5.3 Theatanhfunctions Synopsis

1 #include <math.h>

double atanh(double x);

float atanhf(float x);

long double atanhl(long double x);

Description

2 Theatanhfunctions compute the arc hyperbolic tangent ofx. A domain error occurs for arguments not in the interval [−1, +1]. A pole error may occur if the argument equals-1 or+1.

Returns

3 Theatanhfunctions return artanhx. 7.12.5.4 Thecoshfunctions Synopsis

1 #include <math.h>

double cosh(double x);

float coshf(float x);

long double coshl(long double x);

Description

2 Thecoshfunctions compute the hyperbolic cosine ofx. A range error occurs if the magnitude ofx is too large.

Returns

3 Thecoshfunctions return coshx. 7.12.5.5 Thesinhfunctions Synopsis

1 #include <math.h>

double sinh(double x);

float sinhf(float x);

long double sinhl(long double x);

Description

2 Thesinhfunctions compute the hyperbolic sine ofx. A range error occurs if the magnitude ofxis too large.

Returns

3 Thesinhfunctions return sinhx. 7.12.5.6 Thetanhfunctions Synopsis

1 #include <math.h>

double tanh(double x);

float tanhf(float x);

long double tanhl(long double x);

Description

2 Thetanhfunctions compute the hyperbolic tangent ofx. Returns

3 Thetanhfunctions return tanhx.

ISO/IEC 9899:20172x::(E) diff:::::::::marks— November 6, 2018 N2310

7.12.6 Exponential and logarithmic functions

7.12.6.1 Theexpfunctions Synopsis

1 #include <math.h>

double exp(double x);

float expf(float x);

long double expl(long double x);

Description

2 Theexpfunctions compute the base-e exponential ofx. A range error occurs if the magnitude ofxis too large.

Returns

3 Theexpfunctions return ex. 7.12.6.2 Theexp2functions Synopsis

1 #include <math.h>

double exp2(double x);

float exp2f(float x);

long double exp2l(long double x);

Description

2 Theexp2functions compute the base-2 exponential ofx. A range error occurs if the magnitude ofx is too large.

Returns

3 Theexp2functions return 2x. 7.12.6.3 Theexpm1functions Synopsis

1 #include <math.h>

double expm1(double x);

float expm1f(float x);

long double expm1l(long double x);

Description

2 Theexpm1functions compute the base-e exponential of the argument, minus 1. A range error occurs if positivexis too large.242)

Returns

3 Theexpm1functions return ex− 1.

7.12.6.4 Thefrexpfunctions Synopsis

1 #include <math.h>

double frexp(double value, int *exp);

float frexpf(float value, int *exp);

long double frexpl(long double value, int *exp);

242)For small magnitudex,expm1(x)is expected to be more accurate thanexp(x)-1.

Description

2 Thefrexpfunctions break a floating-point number into a normalized fraction and an integral power of 2. They store the integer in theintobject pointed to byexp.

Returns

3 Ifvalue is not a floating-point number or if the integral power of 2 is outside the range ofint, the results are unspecified. Otherwise, thefrexpfunctions return the valuex, such thatxhas a magnitude in the interval [1/2, 1) or zero, andvalueequalsx× 2*exp. Ifvalueis zero, both parts of the result are zero.

7.12.6.5 Theilogbfunctions Synopsis

1 #include <math.h>

int ilogb(double x);

int ilogbf(float x);

int ilogbl(long double x);

Description

2 Theilogbfunctions extract the exponent ofxas a signedintvalue. Ifxis zero they compute the valueFP_ILOGB0; ifxis infinite they compute the valueINT_MAX; ifxis a NaN they compute the valueFP_ILOGBNAN; otherwise, they are equivalent to calling the correspondinglogbfunction and casting the returned value to typeint. A domain error or range error may occur ifxis zero, infinite, or NaN. If the correct value is outside the range of the return type, the numeric result is unspecified and a domain error or range error may occur.

Returns

3 Theilogbfunctions return the exponent ofxas a signedintvalue.

Forward references: thelogbfunctions (7.12.6.11).

7.12.6.6 Theldexpfunctions Synopsis

1 #include <math.h>

double ldexp(double x, int exp);

float ldexpf(float x, int exp);

long double ldexpl(long double x, int exp);

Description

2 Theldexpfunctions multiply a floating-point number by an integral power of 2. A range error may occur.

Returns

3 Theldexpfunctions returnx× 2exp. 7.12.6.7 Thelogfunctions

Synopsis

1 #include <math.h>

double log(double x);

float logf(float x);

long double logl(long double x);

Description

2 Thelog functions compute the base-e (natural) logarithm of x. A domain error occurs if the argument is negative. A pole error may occur if the argument is zero.

ISO/IEC 9899:20172x::(E) diff:::::::::marks— November 6, 2018 N2310

Returns

3 Thelogfunctions return logex. 7.12.6.8 Thelog10functions Synopsis

1 #include <math.h>

double log10(double x);

float log10f(float x);

long double log10l(long double x);

Description

2 Thelog10functions compute the base-10 (common) logarithm ofx. A domain error occurs if the argument is negative. A pole error may occur if the argument is zero.

Returns

3 Thelog10functions return log10x. 7.12.6.9 Thelog1pfunctions Synopsis

1 #include <math.h>

double log1p(double x);

float log1pf(float x);

long double log1pl(long double x);

Description

2 Thelog1pfunctions compute the base-e (natural) logarithm of 1 plus the argument.243) A domain error occurs if the argument is less than −1. A pole error may occur if the argument equals −1.

Returns

3 Thelog1pfunctions return loge(1 +x). 7.12.6.10 Thelog2functions

Synopsis

1 #include <math.h>

double log2(double x);

float log2f(float x);

long double log2l(long double x);

Description

2 Thelog2functions compute the base-2 logarithm ofx. A domain error occurs if the argument is less than zero. A pole error may occur if the argument is zero.

Returns

3 Thelog2functions return log2x. 7.12.6.11 Thelogbfunctions Synopsis

1 #include <math.h>

double logb(double x);

float logbf(float x);

long double logbl(long double x);

243)For small magnitudex,log1p(x)is expected to be more accurate thanlog(1 + x).

Description

2 Thelogbfunctions extract the exponent ofx, as a signed integer value in floating-point format. Ifx is subnormal it is treated as though it were normalized; thus, for positive finitex,

1 ≤x×FLT_RADIXlogb(x)<FLT_RADIX

A domain error or pole error may occur if the argument is zero.

Returns

3 Thelogbfunctions return the signed exponent ofx. 7.12.6.12 Themodffunctions

Synopsis

1 #include <math.h>

double modf(double value, double *iptr);

float modff(float value, float *iptr);

long double modfl(long double value, long double *iptr);

Description

2 Themodffunctions break the argumentvalueinto integral and fractional parts, each of which has the same type and sign as the argument. They store the integral part (in floating-point format) in the object pointed to byiptr.

Returns

3 Themodffunctions return the signed fractional part ofvalue. 7.12.6.13 Thescalbnandscalblnfunctions

Synopsis

1 #include <math.h>

double scalbn(double x, int n);

float scalbnf(float x, int n);

long double scalbnl(long double x, int n);

double scalbln(double x, long int n);

float scalblnf(float x, long int n);

long double scalblnl(long double x, long int n);

Description

2 Thescalbnandscalblnfunctions computex×FLT_RADIXnefficiently, not normally by computing FLT_RADIXnexplicitly. A range error may occur.

Returns

3 Thescalbnandscalblnfunctions returnx×FLT_RADIXn.

7.12.7 Power and absolute-value functions

7.12.7.1 Thecbrtfunctions Synopsis

1 #include <math.h>

double cbrt(double x);

float cbrtf(float x);

long double cbrtl(long double x);

Description

2 Thecbrtfunctions compute the real cube root ofx.

ISO/IEC 9899:20172x::(E) diff:::::::::marks— November 6, 2018 N2310

Returns

3 Thecbrtfunctions returnx1/3. 7.12.7.2 Thefabsfunctions Synopsis

1 #include <math.h>

double fabs(double x);

float fabsf(float x);

long double fabsl(long double x);

Description

2 Thefabsfunctions compute the absolute value of a floating-point numberx. Returns

3 Thefabsfunctions return |x|.

7.12.7.3 Thehypotfunctions Synopsis

1 #include <math.h>

double hypot(double x, double y);

float hypotf(float x, float y);

long double hypotl(long double x, long double y);

Description

2 Thehypotfunctions compute the square root of the sum of the squares ofxandy, without undue overflow or underflow. A range error may occur.

3

Returns

4 Thehypotfunctions returnp

x2+y2. 7.12.7.4 Thepowfunctions

Synopsis

1 #include <math.h>

double pow(double x, double y);

float powf(float x, float y);

long double powl(long double x, long double y);

Description

2 Thepowfunctions computexraised to the powery. A domain error occurs ifxis finite and negative andyis finite and not an integer value. A range error may occur. A domain error may occur ifxis zero andyis zero. A domain error or pole error may occur ifxis zero andyis less than zero.

Returns

3 Thepowfunctions returnxy. 7.12.7.5 Thesqrtfunctions Synopsis

1 #include <math.h>

double sqrt(double x);

float sqrtf(float x);

long double sqrtl(long double x);

Description

2 Thesqrtfunctions compute the nonnegative square root ofx. A domain error occurs if the argument is less than zero.

Returns

3 Thesqrtfunctions return√ x.

In document Programming languages — C (Page 186-196)