math.NaN() Function in Golang With Examples
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 get an IEEE 754 “not-a-number” value with the help of NaN() 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 NaN() function.
Syntax:
func NaN() float64
Example 1:
package main
import (
"fmt"
"math"
)
func main() {
res := math.NaN()
fmt.Println( "Result: " , res)
}
|
Output:
Result: NaN
Example 2:
package main
import (
"fmt"
"math"
)
func main() {
nvalue := math.NaN()
if nvalue == math.NaN() {
fmt.Println( "Given value is not-a-number" )
} else {
fmt.Println( "Given value is not a not-a-number" )
}
}
|
Output:
Given value is not a not-a-number
Last Updated :
13 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...