📜  Ruby Float nan?() 方法与示例

📅  最后修改于: 2022-05-13 01:54:46.336000             🧑  作者: Mango

Ruby Float nan?() 方法与示例

Float nan?()是一个浮点类方法,用于检查值是否“不是数字”。 “Not A Number”表示无效的 IEEE 浮点数。

示例 #1:

Ruby
# 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"


Ruby
# 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"


输出 :

a is not_a_number : false

b is not_a_number : false

示例 #2:

红宝石

# 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"

输出 :

a is not_a_number : false

b is not_a_number : false