1FDIM(3P) POSIX Programmer's Manual FDIM(3P)
2
3
4
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
12 fdim, fdimf, fdiml - compute positive difference between two floating-
13 point numbers
14
16 #include <math.h>
17
18 double fdim(double x, double y);
19 float fdimf(float x, float y);
20 long double fdiml(long double x, long double y);
21
22
24 These functions shall determine the positive difference between their
25 arguments. If x is greater than y, x- y is returned. If x is less than
26 or equal to y, +0 is returned.
27
28 An application wishing to check for error situations should set errno
29 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
30 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID
31 | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
32 occurred.
33
35 Upon successful completion, these functions shall return the positive
36 difference value.
37
38 If x- y is positive and overflows, a range error shall occur and
39 fdim(), fdimf(), and fdiml() shall return the value of the macro
40 HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively.
41
42 If x- y is positive and underflows, a range error may occur, and either
43 ( x- y) (if representable), or 0.0 (if supported), or an implementa‐
44 tion-defined value shall be returned.
45
46 If x or y is NaN, a NaN shall be returned.
47
49 The fdim() function shall fail if:
50
51 Range Error
52 The result overflows.
53
54 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
55 then errno shall be set to [ERANGE]. If the integer expression
56 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow
57 floating-point exception shall be raised.
58
59
60 The fdim() function may fail if:
61
62 Range Error
63 The result underflows.
64
65 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
66 then errno shall be set to [ERANGE]. If the integer expression
67 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the underflow
68 floating-point exception shall be raised.
69
70
71 The following sections are informative.
72
74 None.
75
77 On implementations supporting IEEE Std 754-1985, x- y cannot underflow,
78 and hence the 0.0 return value is shaded as an extension for implemen‐
79 tations supporting the XSI extension rather than an MX extension.
80
81 On error, the expressions (math_errhandling & MATH_ERRNO) and
82 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
83 at least one of them must be non-zero.
84
86 None.
87
89 None.
90
92 feclearexcept(), fetestexcept(), fmax(), fmin(), the Base Definitions
93 volume of IEEE Std 1003.1-2001, Section 4.18, Treatment of Error Condi‐
94 tions for Mathematical Functions, <math.h>
95
97 Portions of this text are reprinted and reproduced in electronic form
98 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
99 -- Portable Operating System Interface (POSIX), The Open Group Base
100 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
101 Electrical and Electronics Engineers, Inc and The Open Group. In the
102 event of any discrepancy between this version and the original IEEE and
103 The Open Group Standard, the original IEEE and The Open Group Standard
104 is the referee document. The original Standard can be obtained online
105 at http://www.opengroup.org/unix/online.html .
106
107
108
109IEEE/The Open Group 2003 FDIM(3P)