红宝石 | BigDecimal 类南?价值
BigDecimal#nan?() : nan?()是一个 BigDecimal 类方法,用于检查 BigDecimal 值是否为 nan 值。
Syntax: BigDecimal.nan?()
Parameter: BigDecimal values to check regarding the NaN value.
Return: true : if value is a NaN value; otherwise false
代码 #1:nan?() 方法的示例
# Ruby code for nan?() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
a = 42.1**13
# declaring BigDecimal
b = -BigDecimal("10")
# declaring BigDecimal
c = -(22 ** 7.1) * 10
puts "nan? example 1 : #{a.nan?()}\n\n"
puts "nan? example 2 : #{b.nan?()}\n\n"
puts "nan? example 3 : #{c.nan?()}\n\n"
输出 :
nan? example 1 : false
nan? example 2 : false
nan? example 3 : false
代码 #2:nan?() 方法的示例
# Ruby code for nan?() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
# declaring BigDecimal
c = BigDecimal('-3')
puts "nan? example 2 : #{b.nan?()}\n\n"
puts "nan? example 3 : #{c.nan?()}\n\n"
输出 :
nan? example 2 : false
nan? example 3 : false