ADVERTISEMENT
ADVERTISEMENT

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

Parameter(s):

  • 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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.