Open In App

math.NaN() Function in Golang With Examples

Last Updated : 13 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
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 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: C
// Golang program to illustrate math.NaN() Function

package main

import (
    "fmt"
    "math"
)

// Main function
func main() {

    // Getting Not-a-number value
    // Using NaN() function
    res := math.NaN()

    // Displaying the result
    fmt.Println("Result: ", res)

}
Output:
Result:  NaN
Example 2: C
// Golang program to illustrate math.NaN() Function

package main

import (
    "fmt"
    "math"
)

// Main function
func main() {
 
    // Checking whether the given 
    // value is not-a-number or not
    // Using NaN() function
    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

Next Article
Article Tags :

Similar Reads