xref: /freebsd/lib/msun/man/log.3 (revision bcf5c7a8b1dcdcd5f27c1aa694f66208dc07a0dd)
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.\" $FreeBSD$
26.\"
27.Dd March 22, 2020
28.Dt LOG 3
29.Os
30.Sh NAME
31.Nm log ,
32.Nm logf ,
33.Nm logl ,
34.Nm log10 ,
35.Nm log10f ,
36.Nm log10l ,
37.Nm log2 ,
38.Nm log2f ,
39.Nm log2l ,
40.Nm log1p ,
41.Nm log1pf ,
42.Nm log1pl
43.Nd logarithm functions
44.Sh LIBRARY
45.Lb libm
46.Sh SYNOPSIS
47.In math.h
48.Ft double
49.Fn log "double x"
50.Ft float
51.Fn logf "float x"
52.Ft long double
53.Fn logl "long double x"
54.Ft double
55.Fn log10 "double x"
56.Ft float
57.Fn log10f "float x"
58.Ft long double
59.Fn log10l "long double x"
60.Ft double
61.Fn log2 "double x"
62.Ft float
63.Fn log2f "float x"
64.Ft long double
65.Fn log2l "long double x"
66.Ft double
67.Fn log1p "double x"
68.Ft float
69.Fn log1pf "float x"
70.Ft long double
71.Fn log1pl "long double x"
72.Sh DESCRIPTION
73The
74.Fn log ,
75.Fn logf ,
76and
77.Fn logl
78functions compute the natural logarithm of
79.Fa x .
80.Pp
81The
82.Fn log10 ,
83.Fn log10f ,
84and
85.Fn log10l
86functions compute the logarithm base 10 of
87.Fa x ,
88while
89.Fn log2 ,
90.Fn log2f ,
91and
92.Fn log2l
93compute the logarithm base 2 of
94.Fa x .
95.Pp
96The
97.Fn log1p ,
98.Fn log1pf ,
99and
100.Fn log1pl
101functions compute the natural logarithm of
102.No "1 + x" .
103Computing the natural logarithm as
104.Li log1p(x)
105is more accurate than computing it as
106.Li log(1 + x)
107when
108.Fa x
109is close to zero.
110.Sh RETURN VALUES
111These functions return the requested logarithm; the logarithm of 1 is +0.
112An attempt to take the logarithm of \*(Pm0 results in a divide-by-zero
113exception, and -\*(If is returned.
114Otherwise, attempting to take the logarithm of a negative number
115results in an invalid exception and a return value of \*(Na.
116.Sh SEE ALSO
117.Xr exp 3 ,
118.Xr ilogb 3 ,
119.Xr math 3 ,
120.Xr pow 3
121.Sh STANDARDS
122The
123.Fn log ,
124.Fn logf ,
125.Fn logl ,
126.Fn log10 ,
127.Fn log10f ,
128.Fn log10l ,
129.Fn log2 ,
130.Fn log2f ,
131.Fn log2l ,
132.Fn log1p ,
133.Fn log1pf ,
134and
135.Fn log1pl
136functions conform to
137.St -isoC-99 .
138.Sh HISTORY
139The
140.Fn log
141function first appeared in
142.At v1 ;
143.Fn log10
144in
145.At v7 ;
146.Fn log1p
147in
148.Bx 4.3 .
149