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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
  
}

chevron_right


Output:

Result:  NaN

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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")
    }
  
}

chevron_right


Output:

Given value is not a not-a-number



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.