1math.h(0P)                 POSIX Programmer's Manual                math.h(0P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       math.h — mathematical declarations
13

SYNOPSIS

15       #include <math.h>
16

DESCRIPTION

18       Some of the functionality described on this reference page extends  the
19       ISO C  standard. Applications shall define the appropriate feature test
20       macro (see the System Interfaces volume of POSIX.1‐2017,  Section  2.2,
21       The  Compilation Environment) to enable the visibility of these symbols
22       in this header.
23
24       The <math.h> header shall define at least the following types:
25
26       float_t     A real-floating type at least as wide as float.
27
28       double_t    A real-floating type at least as wide  as  double,  and  at
29                   least as wide as float_t.
30
31       If  FLT_EVAL_METHOD  equals  0, float_t and double_t shall be float and
32       double, respectively; if FLT_EVAL_METHOD equals 1, they shall  both  be
33       double;  if  FLT_EVAL_METHOD  equals 2, they shall both be long double;
34       for other values of FLT_EVAL_METHOD, they are otherwise implementation-
35       defined.
36
37       The  <math.h>  header  shall  define  the following macros, where real-
38       floating indicates that the argument shall be an  expression  of  real-
39       floating type:
40
41
42           int fpclassify(real-floating x);
43           int isfinite(real-floating x);
44           int isgreater(real-floating x, real-floating y);
45           int isgreaterequal(real-floating x, real-floating y);
46           int isinf(real-floating x);
47           int isless(real-floating x, real-floating y);
48           int islessequal(real-floating x, real-floating y);
49           int islessgreater(real-floating x, real-floating y);
50           int isnan(real-floating x);
51           int isnormal(real-floating x);
52           int isunordered(real-floating x, real-floating y);
53           int signbit(real-floating x);
54
55       The  <math.h> header shall define the following symbolic constants. The
56       values shall have type double and shall be accurate  to  at  least  the
57       precision of the double type.
58
59       M_E         Value of e
60
61       M_LOG2E     Value of log_2 e
62
63       M_LOG10E    Value of log_10 e
64
65       M_LN2       Value of log_e 2
66
67       M_LN10      Value of log_e 10
68
69       M_PI        Value of π
70
71       M_PI_2      Value of π/2
72
73       M_PI_4      Value of π/4
74
75       M_1_PI      Value of 1/π
76
77       M_2_PI      Value of 2/π
78
79       M_2_SQRTPI  Value of 2/π
80
81       M_SQRT2     Value of 2
82
83       M_SQRT1_2   Value of 1/2
84
85       The <math.h> header shall define the following symbolic constant:
86
87       MAXFLOAT    Same value as FLT_MAX in <float.h>.
88
89       The <math.h> header shall define the following macros:
90
91       HUGE_VAL    A positive double constant expression, not necessarily rep‐
92                   resentable as a float.  Used as an error value returned  by
93                   the mathematics library. HUGE_VAL evaluates to +infinity on
94                   systems supporting IEEE Std 754‐1985.
95
96       HUGE_VALF   A positive float constant  expression.  Used  as  an  error
97                   value returned by the mathematics library. HUGE_VALF evalu‐
98                   ates to +infinity on systems supporting IEEE Std 754‐1985.
99
100       HUGE_VALL   A positive long double  constant  expression.  Used  as  an
101                   error  value returned by the mathematics library. HUGE_VALL
102                   evaluates    to    +infinity    on    systems    supporting
103                   IEEE Std 754‐1985.
104
105       INFINITY    A  constant  expression of type float representing positive
106                   or unsigned infinity, if available; else  a  positive  con‐
107                   stant of type float that overflows at translation time.
108
109       NAN         A  constant  expression  of type float representing a quiet
110                   NaN. This macro is only defined if the implementation  sup‐
111                   ports quiet NaNs for the float type.
112
113       The  following  macros shall be defined for number classification. They
114       represent the mutually-exclusive kinds of floating-point  values.  They
115       expand to integer constant expressions with distinct values. Additional
116       implementation-defined floating-point classifications, with macro defi‐
117       nitions  beginning with FP_ and an uppercase letter, may also be speci‐
118       fied by the implementation.
119
120              FP_INFINITE FP_NAN FP_NORMAL FP_SUBNORMAL FP_ZERO
121
122       The following optional macros indicate  whether  the  fma()  family  of
123       functions are fast compared with direct code:
124
125              FP_FAST_FMA FP_FAST_FMAF FP_FAST_FMAL
126
127       If  defined, the FP_FAST_FMA macro shall expand to the integer constant
128       1 and shall indicate that the fma() function generally  executes  about
129       as  fast  as, or faster than, a multiply and an add of double operands.
130       If undefined, the speed of execution is unspecified. The  other  macros
131       have the equivalent meaning for the float and long double versions.
132
133       The following macros shall expand to integer constant expressions whose
134       values are returned by ilogb(x) if x is zero or NaN, respectively.  The
135       value  of FP_ILOGB0 shall be either {INT_MIN} or -{INT_MAX}.  The value
136       of FP_ILOGBNAN shall be either {INT_MAX} or {INT_MIN}.
137
138              FP_ILOGB0 FP_ILOGBNAN
139
140       The following macros shall expand to the integer  constants  1  and  2,
141       respectively;
142
143              MATH_ERRNO MATH_ERREXCEPT
144
145       The following macro shall expand to an expression that has type int and
146       the value MATH_ERRNO, MATH_ERREXCEPT, or the  bitwise-inclusive  OR  of
147       both:
148
149              math_errhandling
150
151       The  value of math_errhandling is constant for the duration of the pro‐
152       gram. It is unspecified whether math_errhandling is a macro or an iden‐
153       tifier  with external linkage. If a macro definition is suppressed or a
154       program defines an identifier with  the  name  math_errhandling  ,  the
155       behavior   is   undefined.   If   the  expression  (math_errhandling  &
156       MATH_ERREXCEPT) can be non-zero, the implementation  shall  define  the
157       macros FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in <fenv.h>.
158
159       The following shall be declared as functions and may also be defined as
160       macros. Function prototypes shall be provided.
161
162
163           double      acos(double);
164           float       acosf(float);
165           double      acosh(double);
166           float       acoshf(float);
167           long double acoshl(long double);
168           long double acosl(long double);
169           double      asin(double);
170           float       asinf(float);
171           double      asinh(double);
172           float       asinhf(float);
173           long double asinhl(long double);
174           long double asinl(long double);
175           double      atan(double);
176           double      atan2(double, double);
177           float       atan2f(float, float);
178           long double atan2l(long double, long double);
179           float       atanf(float);
180           double      atanh(double);
181           float       atanhf(float);
182           long double atanhl(long double);
183           long double atanl(long double);
184           double      cbrt(double);
185           float       cbrtf(float);
186           long double cbrtl(long double);
187           double      ceil(double);
188           float       ceilf(float);
189           long double ceill(long double);
190           double      copysign(double, double);
191           float       copysignf(float, float);
192           long double copysignl(long double, long double);
193           double      cos(double);
194           float       cosf(float);
195           double      cosh(double);
196           float       coshf(float);
197           long double coshl(long double);
198           long double cosl(long double);
199           double      erf(double);
200           double      erfc(double);
201           float       erfcf(float);
202           long double erfcl(long double);
203           float       erff(float);
204           long double erfl(long double);
205           double      exp(double);
206           double      exp2(double);
207           float       exp2f(float);
208           long double exp2l(long double);
209           float       expf(float);
210           long double expl(long double);
211           double      expm1(double);
212           float       expm1f(float);
213           long double expm1l(long double);
214           double      fabs(double);
215           float       fabsf(float);
216           long double fabsl(long double);
217           double      fdim(double, double);
218           float       fdimf(float, float);
219           long double fdiml(long double, long double);
220           double      floor(double);
221           float       floorf(float);
222           long double floorl(long double);
223           double      fma(double, double, double);
224           float       fmaf(float, float, float);
225           long double fmal(long double, long double, long double);
226           double      fmax(double, double);
227           float       fmaxf(float, float);
228           long double fmaxl(long double, long double);
229           double      fmin(double, double);
230           float       fminf(float, float);
231           long double fminl(long double, long double);
232           double      fmod(double, double);
233           float       fmodf(float, float);
234           long double fmodl(long double, long double);
235           double      frexp(double, int *);
236           float       frexpf(float, int *);
237           long double frexpl(long double, int *);
238           double      hypot(double, double);
239           float       hypotf(float, float);
240           long double hypotl(long double, long double);
241           int         ilogb(double);
242           int         ilogbf(float);
243           int         ilogbl(long double);
244           double      j0(double);
245           double      j1(double);
246           double      jn(int, double);
247           double      ldexp(double, int);
248           float       ldexpf(float, int);
249           long double ldexpl(long double, int);
250           double      lgamma(double);
251           float       lgammaf(float);
252           long double lgammal(long double);
253           long long   llrint(double);
254           long long   llrintf(float);
255           long long   llrintl(long double);
256           long long   llround(double);
257           long long   llroundf(float);
258           long long   llroundl(long double);
259           double      log(double);
260           double      log10(double);
261           float       log10f(float);
262           long double log10l(long double);
263           double      log1p(double);
264           float       log1pf(float);
265           long double log1pl(long double);
266           double      log2(double);
267           float       log2f(float);
268           long double log2l(long double);
269           double      logb(double);
270           float       logbf(float);
271           long double logbl(long double);
272           float       logf(float);
273           long double logl(long double);
274           long        lrint(double);
275           long        lrintf(float);
276           long        lrintl(long double);
277           long        lround(double);
278           long        lroundf(float);
279           long        lroundl(long double);
280           double      modf(double, double *);
281           float       modff(float, float *);
282           long double modfl(long double, long double *);
283           double      nan(const char *);
284           float       nanf(const char *);
285           long double nanl(const char *);
286           double      nearbyint(double);
287           float       nearbyintf(float);
288           long double nearbyintl(long double);
289           double      nextafter(double, double);
290           float       nextafterf(float, float);
291           long double nextafterl(long double, long double);
292           double      nexttoward(double, long double);
293           float       nexttowardf(float, long double);
294           long double nexttowardl(long double, long double);
295           double      pow(double, double);
296           float       powf(float, float);
297           long double powl(long double, long double);
298           double      remainder(double, double);
299           float       remainderf(float, float);
300           long double remainderl(long double, long double);
301           double      remquo(double, double, int *);
302           float       remquof(float, float, int *);
303           long double remquol(long double, long double, int *);
304           double      rint(double);
305           float       rintf(float);
306           long double rintl(long double);
307           double      round(double);
308           float       roundf(float);
309           long double roundl(long double);
310           double      scalbln(double, long);
311           float       scalblnf(float, long);
312           long double scalblnl(long double, long);
313           double      scalbn(double, int);
314           float       scalbnf(float, int);
315           long double scalbnl(long double, int);
316           double      sin(double);
317           float       sinf(float);
318           double      sinh(double);
319           float       sinhf(float);
320           long double sinhl(long double);
321           long double sinl(long double);
322           double      sqrt(double);
323           float       sqrtf(float);
324           long double sqrtl(long double);
325           double      tan(double);
326           float       tanf(float);
327           double      tanh(double);
328           float       tanhf(float);
329           long double tanhl(long double);
330           long double tanl(long double);
331           double      tgamma(double);
332           float       tgammaf(float);
333           long double tgammal(long double);
334           double      trunc(double);
335           float       truncf(float);
336           long double truncl(long double);
337           double      y0(double);
338           double      y1(double);
339           double      yn(int, double);
340
341       The following external variable shall be defined:
342
343
344           extern int signgam;
345
346       The behavior of each of the functions defined in <math.h> is  specified
347       in  the  System Interfaces volume of POSIX.1‐2017 for all representable
348       values of its input arguments,  except  where  stated  otherwise.  Each
349       function  shall execute as if it were a single operation without gener‐
350       ating any externally visible exceptional conditions.
351
352       The following sections are informative.
353

APPLICATION USAGE

355       The FP_CONTRACT pragma can be used to allow (if the  state  is  on)  or
356       disallow  (if  the state is off) the implementation to contract expres‐
357       sions. Each pragma can occur either outside  external  declarations  or
358       preceding  all  explicit  declarations and statements inside a compound
359       statement. When outside external declarations, the pragma takes  effect
360       from its occurrence until another FP_CONTRACT pragma is encountered, or
361       until the end of the translation unit. When inside  a  compound  state‐
362       ment, the pragma takes effect from its occurrence until another FP_CON‐
363       TRACT pragma is encountered (including within a nested compound  state‐
364       ment), or until the end of the compound statement; at the end of a com‐
365       pound statement the state for the pragma is restored to  its  condition
366       just before the compound statement. If this pragma is used in any other
367       context, the behavior is undefined. The default state (on or  off)  for
368       the pragma is implementation-defined.
369
370       Applications  should  use  FLT_MAX as described in the <float.h> header
371       instead of the obsolescent MAXFLOAT.
372
373       Note that if FLT_EVAL_METHOD is neither 0 nor 1,  then  some  constants
374       might  not compare equal as expected; for example, (double)M_PI == M_PI
375       can fail.
376

RATIONALE

378       Before the ISO/IEC 9899:1999 standard, the  math  library  was  defined
379       only  for  the floating type double.  All the names formed by appending
380       'f' or 'l' to a name in <math.h> were reserved to allow for the defini‐
381       tion  of  float  and  long  double libraries; and the ISO/IEC 9899:1999
382       standard provides for all three versions of math functions.
383
384       The functions ecvt(), fcvt(), and gcvt() have  been  dropped  from  the
385       ISO C standard since their capability is available through sprintf().
386

FUTURE DIRECTIONS

388       None.
389

SEE ALSO

391       <float.h>, <stddef.h>, <sys_types.h>
392
393       The System Interfaces volume of POSIX.1‐2017, Section 2.2, The Compila‐
394       tion Environment, acos(), acosh(), asin(),  asinh(),  atan(),  atan2(),
395       atanh(),  cbrt(),  ceil(),  copysign(),  cos(),  cosh(), erf(), erfc(),
396       exp(), exp2(), expm1(), fabs(), fdim(), floor(), fma(), fmax(), fmin(),
397       fmod(),    fpclassify(),   frexp(),   hypot(),   ilogb(),   isfinite(),
398       isgreater(),  isgreaterequal(),   isinf(),   isless(),   islessequal(),
399       islessgreater(),  isnan(),  isnormal(),  isunordered(),  j0(), ldexp(),
400       lgamma(), llrint(), llround(), log(), log10(), log1p(), log2(), logb(),
401       lrint(),  lround(),  modf(),  nan(),  nearbyint(),  nextafter(), pow(),
402       remainder(), remquo(), rint(), round(),  scalbln(),  signbit(),  sin(),
403       sinh(), sqrt(), tan(), tanh(), tgamma(), trunc(), y0()
404
406       Portions  of  this text are reprinted and reproduced in electronic form
407       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
408       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
409       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
410       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
411       event of any discrepancy between this version and the original IEEE and
412       The  Open Group Standard, the original IEEE and The Open Group Standard
413       is the referee document. The original Standard can be  obtained  online
414       at http://www.opengroup.org/unix/online.html .
415
416       Any  typographical  or  formatting  errors that appear in this page are
417       most likely to have been introduced during the conversion of the source
418       files  to  man page format. To report such errors, see https://www.ker
419       nel.org/doc/man-pages/reporting_bugs.html .
420
421
422
423IEEE/The Open Group                  2017                           math.h(0P)
Impressum