xref: /netbsd-src/lib/libm/man/log.3 (revision 76c7fc5f6b13ed0b1508e6b313e88e59977ed78e)
1.\" $NetBSD: log.3,v 1.7 2019/09/02 00:37:47 sevan Exp $
2.\"
3.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi>
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25.\" POSSIBILITY OF SUCH DAMAGE.
26.\"
27.Dd September 2, 2019
28.Dt LOG 3
29.Os
30.Sh NAME
31.Nm log ,
32.Nm logf ,
33.Nm log10 ,
34.Nm log10f ,
35.Nm log1p ,
36.Nm log1pf ,
37.Nm log2 ,
38.Nm log2f
39.Nd logarithm functions
40.Sh LIBRARY
41.Lb libm
42.Sh SYNOPSIS
43.In math.h
44.Ft double
45.Fn log "double x"
46.Ft float
47.Fn logf "float x"
48.Ft double
49.Fn log10 "double x"
50.Ft float
51.Fn log10f "float x"
52.Ft double
53.Fn log1p "double x"
54.Ft float
55.Fn log1pf "float x"
56.Ft double
57.Fn log2 "double x"
58.Ft float
59.Fn log2f "float x"
60.Sh DESCRIPTION
61The following functions compute logarithms:
62.Bl -bullet -offset 2n
63.It
64The
65.Fn log
66and
67.Fn logf
68functions return the natural logarithm.
69.It
70The
71.Fn log10
72and
73.Fn log10f
74functions return the base 10 logarithm.
75.It
76The
77.Fn log1p
78and
79.Fn log1pf
80functions return the natural logarithm of (1.0 +
81.Fa x )
82accurately even for very small values of
83.Fa x .
84.It
85The
86.Fn log2
87and
88.Fn log2f
89functions return the base 2 logarithm.
90.El
91.Sh RETURN VALUES
92Upon successful completion, the functions return the logarithm of
93.Fa x
94as described above.
95Otherwise the following may occur:
96.Bl -enum -offset indent
97.It
98If
99.Fa x
100is \*(Na, all functions return \*(Na.
101.It
102If
103.Fa x
104is positive infinity, all functions return
105.Fa x .
106If
107.Fa x
108is negative infinity, all functions return \*(Na.
109.It
110If
111.Fa x
112is +0.0 or -0.0, the
113.Fn log ,
114.Fn log10 ,
115and
116.Fn log2
117families return either
118.Dv -HUGE_VAL ,
119.Dv -HUGE_VALF ,
120or
121.Dv -HUGE_VALL ,
122whereas the
123.Fn log1p
124family returns
125.Fa x .
126.It
127If
128.Fa x
129is +1.0, the
130.Fn log ,
131.Fn log10 ,
132and
133.Fn log2
134families return +0.0.
135If
136.Fa x
137is -1.0, the
138.Fn log1p
139family returns
140.Dv -HUGE_VAL ,
141.Dv -HUGE_VALF ,
142or
143.Dv -HUGE_VALL .
144.El
145.Pp
146In addition, on a
147.Tn VAX ,
148.Va errno
149is set to
150.Er EDOM
151and the reserved operand is returned
152by
153.Fn log
154unless
155.Fa x
156> 0, by
157.Fn log1p
158unless
159.Fa x
160> \-1.
161.Sh SEE ALSO
162.Xr exp 3 ,
163.Xr ilogb 3 ,
164.Xr math 3
165.Sh STANDARDS
166The described functions conform to
167.St -isoC-99 .
168.Sh HISTORY
169A
170.Fn log
171function appeared in
172.At v1 .
173