×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Log10() Function with Examples

Golang | math.Log10() Function: Here, we are going to learn about the Log10() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 01, 2021

math.Log10()

The Log10() function is an inbuilt function of the math package which is used to get the decimal logarithm (base-10 logarithm) of the given number.

It accepts a parameter (x) and returns the decimal logarithm of x.

Syntax

func Log10(x float64) float64

Parameters

  • x : The value whose decimal logarithm is to be found.

Return Value

The return type of Log10() function is a float64, it returns the decimal logarithm of the given value.

Special Cases

  • Log10(+Inf) = +Inf
    If the parameter is positive infinity (+Inf), the function returns the same (+Inf).
  • Log10(0) = -Inf
    If the parameter is 0, the function returns the -Inf.
  • Log10(x < 0) = NaN
    If the parameter is less than 0, the function returns NaN.
  • Log10(NaN) = NaN
    If the parameter is NaN, the function returns NaN.

Example 1

// Golang program to demonstrate the
// example of math.Log10() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Log10(1))
	fmt.Println(math.Log10(2))
	fmt.Println(math.Log10(10))
	fmt.Println(math.Log10(10.23))

	fmt.Println(math.Log10(0))
	fmt.Println(math.Log10(-1))
	fmt.Println(math.Log10(math.NaN()))
	fmt.Println(math.Log10(math.Inf(1)))
}

Output:

0
0.3010299956639812
1
1.0098756337121602
-Inf
NaN
NaN
+Inf

Example 2

// Golang program to demonstrate the
// example of math.Log10() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var Log10X float64

	x = 1
	Log10X = math.Log10(x)
	fmt.Println("Log10(", x, ") =", Log10X)

	x = 2
	Log10X = math.Log10(x)
	fmt.Println("Log10(", x, ") =", Log10X)

	x = 10
	Log10X = math.Log10(x)
	fmt.Println("Log10(", x, ") =", Log10X)

	x = 10.58
	Log10X = math.Log10(x)
	fmt.Println("Log10(", x, ") =", Log10X)

	x = math.Inf(1)
	Log10X = math.Log10(x)
	fmt.Println("Log10(", x, ") =", Log10X)

	x = math.NaN()
	Log10X = math.Log10(x)
	fmt.Println("Log10(", x, ") =", Log10X)
}

Output:

Log10( 1 ) = 0
Log10( 2 ) = 0.3010299956639812
Log10( 10 ) = 1
Log10( 10.58 ) = 1.024485667699167
Log10( +Inf ) = +Inf
Log10( NaN ) = NaN

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.