localedef.1, access.2, ioctl_console.2, ioctl_fslabel.2, openat2.2, write.2, dlsym...
[man-pages.git] / man3 / log.3
blobd29b2cc4b8b6551301e7fc5d7f076a89207b2fb5
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" References consulted:
28 .\"     Linux libc source code
29 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
30 .\"     386BSD man pages
31 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
32 .\" Modified 1995-08-14 by Arnt Gulbrandsen <agulbra@troll.no>
33 .\" Modified 2002-07-27 by Walter Harms
34 .\"     (walter.harms@informatik.uni-oldenburg.de)
35 .\"
36 .TH LOG 3  2021-03-22  "" "Linux Programmer's Manual"
37 .SH NAME
38 log, logf, logl \- natural logarithmic function
39 .SH SYNOPSIS
40 .nf
41 .B #include <math.h>
42 .PP
43 .BI "double log(double " x );
44 .BI "float logf(float " x );
45 .BI "long double logl(long double " x );
46 .fi
47 .PP
48 Link with \fI\-lm\fP.
49 .PP
50 .RS -4
51 Feature Test Macro Requirements for glibc (see
52 .BR feature_test_macros (7)):
53 .RE
54 .PP
55 .BR logf (),
56 .BR logl ():
57 .nf
58     _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
59         || /* Since glibc 2.19: */ _DEFAULT_SOURCE
60         || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
61 .fi
62 .SH DESCRIPTION
63 These functions return the natural logarithm of
64 .IR x .
65 .SH RETURN VALUE
66 On success, these functions return the natural logarithm of
67 .IR x .
68 .PP
70 .I x
71 is a NaN,
72 a NaN is returned.
73 .PP
75 .I x
76 is 1, the result is +0.
77 .PP
79 .I x
80 is positive infinity,
81 positive infinity is returned.
82 .PP
84 .I x
85 is zero,
86 then a pole error occurs, and the functions return
87 .RB \- HUGE_VAL ,
88 .RB \- HUGE_VALF ,
90 .RB \- HUGE_VALL ,
91 respectively.
92 .PP
94 .I x
95 is negative (including negative infinity), then
96 a domain error occurs, and a NaN (not a number) is returned.
97 .SH ERRORS
98 See
99 .BR math_error (7)
100 for information on how to determine whether an error has occurred
101 when calling these functions.
103 The following errors can occur:
105 Domain error: \fIx\fP is negative
106 .I errno
107 is set to
108 .BR EDOM .
109 An invalid floating-point exception
110 .RB ( FE_INVALID )
111 is raised.
113 Pole error: \fIx\fP is zero
114 .I errno
115 is set to
116 .BR ERANGE .
117 A divide-by-zero floating-point exception
118 .RB ( FE_DIVBYZERO )
119 is raised.
120 .SH ATTRIBUTES
121 For an explanation of the terms used in this section, see
122 .BR attributes (7).
123 .ad l
126 allbox;
127 lbx lb lb
128 l l l.
129 Interface       Attribute       Value
131 .BR log (),
132 .BR logf (),
133 .BR logl ()
134 T}      Thread safety   MT-Safe
138 .sp 1
139 .SH CONFORMING TO
140 C99, POSIX.1-2001, POSIX.1-2008.
142 The variant returning
143 .I double
144 also conforms to
145 SVr4, 4.3BSD, C89.
146 .SH BUGS
147 In glibc 2.5 and earlier,
148 taking the
149 .BR log ()
150 of a NaN produces a bogus invalid floating-point
151 .RB ( FE_INVALID )
152 exception.
153 .SH SEE ALSO
154 .BR cbrt (3),
155 .BR clog (3),
156 .BR log10 (3),
157 .BR log1p (3),
158 .BR log2 (3),
159 .BR sqrt (3)