Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

<math.h> — mathematics

C's mathematics header: functions, number classification, special values, and error reporting.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <math.h>

#include <math.h> provides mathematical functions and macros.

HUGE_VAL, HUGE_VALF, HUGE_VALL: default-rounding overflow results for double, float, long double; not necessarily infinities. In C23, INFINITY is defined in both <math.h> and <float.h>. If the implementation supports infinity, the macro expands to a constant expression of type float representing positive infinity. Otherwise, it expands to a positive constant of type float that overflows at translation time. NAN is defined in both headers only if the implementation supports quiet NaNs of type float. When defined, it expands to a constant expression of type float representing a quiet NaN.

fpclassify categories: FP_INFINITE — infinity; FP_NAN — NaN; FP_NORMAL — normal; FP_SUBNORMAL — subnormal; FP_ZERO — zero. FP_ILOGB0 and FP_ILOGBNAN denote ilogb results for zero and NaN.

The math_errhandling mask: MATH_ERRNO (1) indicates errno; MATH_ERREXCEPT (2) indicates floating-point exceptions. Test bits using &.

Optional FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL equal 1: respectively, fma, fmaf, fmal generally are no slower than separate multiplication and addition. An absent macro does not mean an absent function.

Examples

#include <math.h>
#include <stdio.h>

int main(void)
{
    printf("zero: %d\n", fpclassify(0.0) == FP_ZERO);
    printf("normal: %d\n", fpclassify(1.0) == FP_NORMAL);
    return 0;
}

Result

zero: 1
normal: 1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources