如何在Ruby中表达无穷大? [英] How to express infinity in Ruby?
本文介绍了如何在Ruby中表达无穷大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ruby 中是否有表达 Infinity 的关键字?
Is there a keyword to express Infinity in Ruby?
推荐答案
如果你使用ruby 1.9.2,你可以使用:
>> Float::INFINITY #=> Infinity
>> 3 < Float::INFINITY #=> true
或者您可以使用以下内容创建自己的常量*:
我已经检查过在 Ruby 1.8.6、1.8.7 和 1.9.2 中你有 Float.infinite?.
Or you can create your own constant using the following*:
I've checked that in Ruby 1.8.6, 1.8.7, and 1.9.2 you have Float.infinite?.
PositiveInfinity = +1.0/0.0
=> Infinity
NegativeInfinity = -1.0/0.0
=> -Infinity
CompleteInfinity = NegativeInfinity..PositiveInfinity
=> -Infinity..Infinity
*我已经在 Ruby 1.8.6 和 1.9.2 中验证了这一点
这篇关于如何在Ruby中表达无穷大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文