Open In App

Find Base-10 Exponential of Given Number in Golang

Improve
Improve
Like Article
Like
Save
Share
Report

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:




// Golang program to illustrate how to find
// base-10 exponential of the given numbers
  
package main
  
import (
    "fmt"
    "math"
)
  
// Main function
func main() {
  
    // Finding the base-10 exponential
    // of the given numbers
    // Using Pow10() function
    res_1 := math.Pow10(3)
    res_2 := math.Pow10(-2)
    res_3 := math.Pow10(310)
    res_4 := math.Pow10(-300)
  
    // Displaying the result
    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:




// Golang program to illustrate how to find
// base-10 exponential of the given numbers
  
package main
  
import (
    "fmt"
    "math"
)
  
// Main function
func main() {
  
    // Finding the base-10 exponential
    // of the given numbers
    // Using Pow10() function
    nvalue_1 := math.Pow10(2)
    nvalue_2 := math.Pow10(3)
  
    // Sum of the given exponentials
    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
Previous
Next
Share your thoughts in the comments
Similar Reads