xref: /freebsd/lib/msun/man/log.3 (revision 02e9120893770924227138ba49df1edb3896112a)
1.\" Copyright (c) 2008-2010 David Schultz <das@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd March 22, 2020
26.Dt LOG 3
27.Os
28.Sh NAME
29.Nm log ,
30.Nm logf ,
31.Nm logl ,
32.Nm log10 ,
33.Nm log10f ,
34.Nm log10l ,
35.Nm log2 ,
36.Nm log2f ,
37.Nm log2l ,
38.Nm log1p ,
39.Nm log1pf ,
40.Nm log1pl
41.Nd logarithm functions
42.Sh LIBRARY
43.Lb libm
44.Sh SYNOPSIS
45.In math.h
46.Ft double
47.Fn log "double x"
48.Ft float
49.Fn logf "float x"
50.Ft long double
51.Fn logl "long double x"
52.Ft double
53.Fn log10 "double x"
54.Ft float
55.Fn log10f "float x"
56.Ft long double
57.Fn log10l "long double x"
58.Ft double
59.Fn log2 "double x"
60.Ft float
61.Fn log2f "float x"
62.Ft long double
63.Fn log2l "long double x"
64.Ft double
65.Fn log1p "double x"
66.Ft float
67.Fn log1pf "float x"
68.Ft long double
69.Fn log1pl "long double x"
70.Sh DESCRIPTION
71The
72.Fn log ,
73.Fn logf ,
74and
75.Fn logl
76functions compute the natural logarithm of
77.Fa x .
78.Pp
79The
80.Fn log10 ,
81.Fn log10f ,
82and
83.Fn log10l
84functions compute the logarithm base 10 of
85.Fa x ,
86while
87.Fn log2 ,
88.Fn log2f ,
89and
90.Fn log2l
91compute the logarithm base 2 of
92.Fa x .
93.Pp
94The
95.Fn log1p ,
96.Fn log1pf ,
97and
98.Fn log1pl
99functions compute the natural logarithm of
100.No "1 + x" .
101Computing the natural logarithm as
102.Li log1p(x)
103is more accurate than computing it as
104.Li log(1 + x)
105when
106.Fa x
107is close to zero.
108.Sh RETURN VALUES
109These functions return the requested logarithm; the logarithm of 1 is +0.
110An attempt to take the logarithm of \*(Pm0 results in a divide-by-zero
111exception, and -\*(If is returned.
112Otherwise, attempting to take the logarithm of a negative number
113results in an invalid exception and a return value of \*(Na.
114.Sh SEE ALSO
115.Xr exp 3 ,
116.Xr ilogb 3 ,
117.Xr math 3 ,
118.Xr pow 3
119.Sh STANDARDS
120The
121.Fn log ,
122.Fn logf ,
123.Fn logl ,
124.Fn log10 ,
125.Fn log10f ,
126.Fn log10l ,
127.Fn log2 ,
128.Fn log2f ,
129.Fn log2l ,
130.Fn log1p ,
131.Fn log1pf ,
132and
133.Fn log1pl
134functions conform to
135.St -isoC-99 .
136.Sh HISTORY
137The
138.Fn log
139function first appeared in
140.At v1 ;
141.Fn log10
142in
143.At v7 ;
144.Fn log1p
145in
146.Bx 4.3 .
147