-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbsolute-Value.html
More file actions
129 lines (112 loc) · 6.48 KB
/
Absolute-Value.html
File metadata and controls
129 lines (112 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<html lang="en">
<head>
<title>Absolute Value - The GNU C Library</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU C Library">
<meta name="generator" content="makeinfo 4.9">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Arithmetic-Functions.html#Arithmetic-Functions" title="Arithmetic Functions">
<link rel="next" href="Normalization-Functions.html#Normalization-Functions" title="Normalization Functions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU C library.
This is Edition 0.11, last updated 2007-09-09,
of `The GNU C Library Reference Manual', for version 2.7.
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software Needs Free Documentation''
and ``GNU Lesser General Public License'', the Front-Cover texts being
``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Absolute-Value"></a>
Next: <a rel="next" accesskey="n" href="Normalization-Functions.html#Normalization-Functions">Normalization Functions</a>,
Up: <a rel="up" accesskey="u" href="Arithmetic-Functions.html#Arithmetic-Functions">Arithmetic Functions</a>
<hr>
</div>
<h4 class="subsection">20.8.1 Absolute Value</h4>
<p><a name="index-absolute-value-functions-2403"></a>
These functions are provided for obtaining the <dfn>absolute value</dfn> (or
<dfn>magnitude</dfn>) of a number. The absolute value of a real number
<var>x</var> is <var>x</var> if <var>x</var> is positive, −<var>x</var> if <var>x</var> is
negative. For a complex number <var>z</var>, whose real part is <var>x</var> and
whose imaginary part is <var>y</var>, the absolute value is <code>sqrt (</code><var>x</var><code>*</code><var>x</var><code> + </code><var>y</var><code>*</code><var>y</var><code>)</code><!-- /@w -->.
<p><a name="index-math_002eh-2404"></a><a name="index-stdlib_002eh-2405"></a>Prototypes for <code>abs</code>, <code>labs</code> and <code>llabs</code> are in <samp><span class="file">stdlib.h</span></samp>;
<code>imaxabs</code> is declared in <samp><span class="file">inttypes.h</span></samp>;
<code>fabs</code>, <code>fabsf</code> and <code>fabsl</code> are declared in <samp><span class="file">math.h</span></samp>.
<code>cabs</code>, <code>cabsf</code> and <code>cabsl</code> are declared in <samp><span class="file">complex.h</span></samp>.
<!-- stdlib.h -->
<!-- ISO -->
<div class="defun">
— Function: int <b>abs</b> (<var>int number</var>)<var><a name="index-abs-2406"></a></var><br>
<blockquote><!-- stdlib.h -->
<!-- ISO -->
— Function: long int <b>labs</b> (<var>long int number</var>)<var><a name="index-labs-2407"></a></var><br>
<blockquote><!-- stdlib.h -->
<!-- ISO -->
— Function: long long int <b>llabs</b> (<var>long long int number</var>)<var><a name="index-llabs-2408"></a></var><br>
<blockquote><!-- inttypes.h -->
<!-- ISO -->
— Function: intmax_t <b>imaxabs</b> (<var>intmax_t number</var>)<var><a name="index-imaxabs-2409"></a></var><br>
<blockquote><p>These functions return the absolute value of <var>number</var>.
<p>Most computers use a two's complement integer representation, in which
the absolute value of <code>INT_MIN</code> (the smallest possible <code>int</code>)
cannot be represented; thus, <code>abs (INT_MIN)</code><!-- /@w --> is not defined.
<p><code>llabs</code> and <code>imaxdiv</code> are new to ISO C99<!-- /@w -->.
<p>See <a href="Integers.html#Integers">Integers</a> for a description of the <code>intmax_t</code> type.
</blockquote></div>
<!-- math.h -->
<!-- ISO -->
<div class="defun">
— Function: double <b>fabs</b> (<var>double number</var>)<var><a name="index-fabs-2410"></a></var><br>
<blockquote><!-- math.h -->
<!-- ISO -->
— Function: float <b>fabsf</b> (<var>float number</var>)<var><a name="index-fabsf-2411"></a></var><br>
<blockquote><!-- math.h -->
<!-- ISO -->
— Function: long double <b>fabsl</b> (<var>long double number</var>)<var><a name="index-fabsl-2412"></a></var><br>
<blockquote><p>This function returns the absolute value of the floating-point number
<var>number</var>.
</p></blockquote></div>
<!-- complex.h -->
<!-- ISO -->
<div class="defun">
— Function: double <b>cabs</b> (<var>complex double z</var>)<var><a name="index-cabs-2413"></a></var><br>
<blockquote><!-- complex.h -->
<!-- ISO -->
— Function: float <b>cabsf</b> (<var>complex float z</var>)<var><a name="index-cabsf-2414"></a></var><br>
<blockquote><!-- complex.h -->
<!-- ISO -->
— Function: long double <b>cabsl</b> (<var>complex long double z</var>)<var><a name="index-cabsl-2415"></a></var><br>
<blockquote><p>These functions return the absolute value of the complex number <var>z</var>
(see <a href="Complex-Numbers.html#Complex-Numbers">Complex Numbers</a>). The absolute value of a complex number is:
<pre class="smallexample"> sqrt (creal (<var>z</var>) * creal (<var>z</var>) + cimag (<var>z</var>) * cimag (<var>z</var>))
</pre>
<p>This function should always be used instead of the direct formula
because it takes special care to avoid losing precision. It may also
take advantage of hardware support for this operation. See <code>hypot</code>
in <a href="Exponents-and-Logarithms.html#Exponents-and-Logarithms">Exponents and Logarithms</a>.
</p></blockquote></div>
</body></html>