Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

GoLang – Find Natural Logarithm – Log1p() Function – Examples & Explanation

Log1p() function is used to find the natural logarithm of 1 plus its argument x. It is more accurate than Log(1 + x) when x is near zero. The standard math package of Go programming language has Log1p() function.

Syntax of Log1p() Function in Go Language

The syntax of Log1p() function in Go Language is:

Note: float64 is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Log1p(+Inf) = +Inf
Log1p(±0) = ±0
Log1p(-1) = -Inf
Log1p(x < -1) = NaN
Log1p(NaN) = NaN

Parameters of Log1p() Function in Go Language

x – Where x is any Valid float64 Input value. This parameter is required.

 

Error Handling

If the x parameter is not a number (numeric value) Log1p() function returns an error .
If there is no argument (x – input value) passes to the function, then the compiler will produce an error.

 

Return Value of Log1p() Function in Go Language

Log1p() function will return the natural logarithm of 1 plus its parameter x. It is more accurate than Log(1 + x) when x is near zero.

 

Go Log1p() Function Example 1


Output:
NaN

 

GoLang Log1p() Function Example 2


Output:
1.6733512381777533

 

GoLang Log1p() Function Example 3


Output:
1.0986122886681096

 

LearnAndLearn.com © 2018 - All rights reserved