Find Base-10 Exponential of Given Number in Golang
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the base-10 exponential(10**a) of the specified number with the help of the pow10() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to access the Pow10() function.
Syntax:
func Pow10(a int) float64
- If the value of a<-323, then this function will return 0.
- If the value of a>308, then this function will return +Inf.
Example 1:
package main
import (
"fmt"
"math"
)
func main() {
res_1 := math.Pow10(3)
res_2 := math.Pow10(-2)
res_3 := math.Pow10(310)
res_4 := math.Pow10(-300)
fmt.Printf( "Result 1: %.1f" , res_1)
fmt.Printf( "\nResult 2: %.1f" , res_2)
fmt.Printf( "\nResult 3: %.1f" , res_3)
fmt.Printf( "\nResult 4: %.1f" , res_4)
}
|
Output:
Result 1: 1000.0
Result 2: 0.0
Result 3: +Inf
Result 4: 0.0
Example 2:
package main
import (
"fmt"
"math"
)
func main() {
nvalue_1 := math.Pow10(2)
nvalue_2 := math.Pow10(3)
res := nvalue_1 + nvalue_2
fmt.Printf( "%.2f + %.2f = %.2f" ,
nvalue_1, nvalue_2, res)
}
|
Output:
100.00 + 1000.00 = 1100.00
Last Updated :
13 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...