Ruby Float nan?() method with example

Float nan?() is a float class method which checks whetger the value is ‘not a number’. ‘Not A Number’ means an invalid IEEE floating point number.

Syntax: float.nan?()

Parameter: float value to be passed

Return: Return true – if the value is ‘not a number’ otherwise return false

Example #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for nan?() method
  
# Initializing value
a = 0.0
b = 0.0.modulo(4.0)
  
# Printing result
puts "a is not_a_number : #{a.nan?}\n\n"
puts "b is not_a_number : #{b.nan?}\n\n"

chevron_right


Output :

a is not_a_number : false

b is not_a_number : false

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for nan?() method
  
# Initializing value
a = 26.00
b = 8.0
  
# Printing Result
puts "a is not_a_number : #{a.nan?}\n\n"
puts "b is not_a_number : #{b.nan?}\n\n"

chevron_right


Output :

a is not_a_number : false

b is not_a_number : false
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.