What is num.nan? in Ruby?

The num.nan? function returns true if the num is Not a Number (NaN), and false otherwise.

A visual representation of the num.nan? function

Syntax

num.nan?
# where num is to be checked for nan

Parameter

This function does not require a parameter.

Return value

This function returns true if the num is not a number (NaN). Otherwise, it returns false.

Code

#Not nan value
num1=0.00
puts "num1.nan? : #{num1.nan?}\n"
#nan value
num2=0.00/0.00
puts "num2.nan? : #{num2.nan?}\n"

Free Resources