math.IsNaN() Function in Golang with Examples
Last Updated :
28 Apr, 2020
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides IsNaN() function which is used to check whether x is an IEEE 754 “not-a-number” value or not. This function return true if x is an IEEE 754 “not-a-number” value. Otherwise, this function will returns false. So, you need to add a math package in your program with the help of the import keyword to access the IsNaN() function.
Syntax:
func IsNaN(x float64) (is bool)
Example 1:
package main
import (
"fmt"
"math"
)
func main() {
a1 := 4.4
res1 := math.IsNaN(a1)
fmt.Println( "Result 1:" , res1)
a2 := math.NaN()
res2 := math.IsNaN(a2)
fmt.Println( "Result 2:" , res2)
}
|
Output:
Result 1: false
Result 2: true
Example 2:
package main
import (
"fmt"
"math"
)
func main() {
a := math.NaN()
res := math.IsNaN(a)
if (res == true ){
fmt.Println( "a is not-a-number" )
} else {
fmt.Println( "a is not a NaN(not-a-number)" )
}
}
|
Output:
a is not-a-number
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...