1.\" $NetBSD: log.3,v 1.8 2024/01/26 19:27:30 nros 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 January 24, 2024 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 log1p , 38.Nm log1pf , 39.Nm log1pl , 40.Nm log2 , 41.Nm log2f 42.Nm log2l 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 log double 59.Fn log10l "long double x" 60.Ft double 61.Fn log1p "double x" 62.Ft float 63.Fn log1pf "float x" 64.Ft long double 65.Fn log1pl "long double x" 66.Ft double 67.Fn log2 "double x" 68.Ft float 69.Fn log2f "float x" 70.Ft long double 71.Fn log2l "long double x" 72.Sh DESCRIPTION 73The following functions compute logarithms: 74.Bl -bullet -offset 2n 75.It 76The 77.Fn log , 78.Fn logf 79and 80.Fn logl 81functions return the natural logarithm. 82.It 83The 84.Fn log10 , 85.Fn log10f 86and 87.Fn log10l 88functions return the base 10 logarithm. 89.It 90The 91.Fn log1p , 92.Fn log1pf 93and 94.Fn log1pl 95functions return the natural logarithm of (1.0 + 96.Fa x ) 97accurately even for very small values of 98.Fa x . 99.It 100The 101.Fn log2 , 102.Fn log2f 103and 104.Fn log2l 105functions return the base 2 logarithm. 106.El 107.Sh RETURN VALUES 108Upon successful completion, the functions return the logarithm of 109.Fa x 110as described above. 111Otherwise the following may occur: 112.Bl -enum -offset indent 113.It 114If 115.Fa x 116is \*(Na, all functions return \*(Na. 117.It 118If 119.Fa x 120is positive infinity, all functions return 121.Fa x . 122If 123.Fa x 124is negative infinity, all functions return \*(Na. 125.It 126If 127.Fa x 128is +0.0 or -0.0, the 129.Fn log , 130.Fn log10 , 131and 132.Fn log2 133families return either 134.Dv -HUGE_VAL , 135.Dv -HUGE_VALF , 136or 137.Dv -HUGE_VALL , 138whereas the 139.Fn log1p 140family returns 141.Fa x . 142.It 143If 144.Fa x 145is +1.0, the 146.Fn log , 147.Fn log10 , 148and 149.Fn log2 150families return +0.0. 151If 152.Fa x 153is -1.0, the 154.Fn log1p 155family returns 156.Dv -HUGE_VAL , 157.Dv -HUGE_VALF , 158or 159.Dv -HUGE_VALL . 160.El 161.Pp 162In addition, on a 163.Tn VAX , 164.Va errno 165is set to 166.Er EDOM 167and the reserved operand is returned 168by 169.Fn log 170unless 171.Fa x 172> 0, by 173.Fn log1p 174unless 175.Fa x 176> \-1. 177.Sh SEE ALSO 178.Xr exp 3 , 179.Xr ilogb 3 , 180.Xr math 3 181.Sh STANDARDS 182The described functions conform to 183.St -isoC-99 . 184.Sh HISTORY 185A 186.Fn log 187function appeared in 188.At v1 . 189