1FABS(3P) POSIX Programmer's Manual FABS(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
11
13 fabs, fabsf, fabsl — absolute value function
14
16 #include <math.h>
17
18 double fabs(double x);
19 float fabsf(float x);
20 long double fabsl(long double x);
21
23 The functionality described on this reference page is aligned with the
24 ISO C standard. Any conflict between the requirements described here
25 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
26 defers to the ISO C standard.
27
28 These functions shall compute the absolute value of their argument
29 x,|x|.
30
32 Upon successful completion, these functions shall return the absolute
33 value of x.
34
35 If x is NaN, a NaN shall be returned.
36
37 If x is ±0, +0 shall be returned.
38
39 If x is ±Inf, +Inf shall be returned.
40
42 No errors are defined.
43
44 The following sections are informative.
45
47 Computing the 1-Norm of a Floating-Point Vector
48 This example shows the use of fabs() to compute the 1-norm of a vector
49 defined as follows:
50
51 norm1(v) = |v[0]| + |v[1]| + ... + |v[n−1]|
52
53 where |x| denotes the absolute value of x, n denotes the vector's
54 dimension v[i] denotes the i-th component of v (0≤i<n).
55
56 #include <math.h>
57
58 double
59 norm1(const double v[], const int n)
60 {
61 int i;
62 double n1_v; /* 1-norm of v */
63
64 n1_v = 0;
65 for (i=0; i<n; i++) {
66 n1_v += fabs (v[i]);
67 }
68
69 return n1_v;
70 }
71
73 None.
74
76 None.
77
79 None.
80
82 isnan()
83
84 The Base Definitions volume of POSIX.1‐2008, <math.h>
85
87 Portions of this text are reprinted and reproduced in electronic form
88 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
89 -- Portable Operating System Interface (POSIX), The Open Group Base
90 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
91 cal and Electronics Engineers, Inc and The Open Group. (This is
92 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
93 event of any discrepancy between this version and the original IEEE and
94 The Open Group Standard, the original IEEE and The Open Group Standard
95 is the referee document. The original Standard can be obtained online
96 at http://www.unix.org/online.html .
97
98 Any typographical or formatting errors that appear in this page are
99 most likely to have been introduced during the conversion of the source
100 files to man page format. To report such errors, see https://www.ker‐
101 nel.org/doc/man-pages/reporting_bugs.html .
102
103
104
105IEEE/The Open Group 2013 FABS(3P)