×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Pow10() Function with Examples

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

math.Pow10()

The Pow10() function is an inbuilt function of the math package which is used to get the 10**n, the base-10 exponential of n (we can say, 10 to the power n).

It accepts a parameter (n) and returns the 10**n, the base-10 exponential of n.

Syntax

func Pow10(n int) float64

Parameters

  • n : The value to be used to find 10**n (10 to the power n).

Return Value

The return type of Pow10() function is a float64, it returns the 10**n, the base-10 exponential of n.

Special Cases

  • Pow10(n) = 0 for n < -323
    If the parameter is less then -323, the function returns 0.
  • Pow10(n) = +Inf for n > 308
    If the parameter is greater than 308, the function returns +Inf.

Example 1

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

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Pow10(2))
	fmt.Println(math.Pow10(3))
	fmt.Println(math.Pow10(-10))
	fmt.Println(math.Pow10(10))
	fmt.Println(math.Pow10(149))

	fmt.Println(math.Pow10(0))
	fmt.Println(math.Pow10(1))
	fmt.Println(math.Pow10(-324))
	fmt.Println(math.Pow10(309))
}

Output:

100
1000
1e-10
1e+10
1e+149
1
10
0
+Inf

Example 2

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var result float64

	n = 2
	result = math.Pow10(n)
	fmt.Println(10, "to the power of", n, "is", result)

	n = 3
	result = math.Pow10(n)
	fmt.Println(10, "to the power of", n, "is", result)

	n = 15
	result = math.Pow10(n)
	fmt.Println(10, "to the power of", n, "is", result)

	n = 0
	result = math.Pow10(n)
	fmt.Println(10, "to the power of", n, "is", result)

	n = 309
	result = math.Pow10(n)
	fmt.Println(10, "to the power of", n, "is", result)
}

Output:

10 to the power of 2 is 100
10 to the power of 3 is 1000
10 to the power of 15 is 1e+15
10 to the power of 0 is 1
10 to the power of 309 is +Inf

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





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