Ruby max integer

后端 未结 6 1256
北海茫月
北海茫月 2020-11-29 20:21

I need to be able to determine a systems maximum integer in Ruby. Anybody know how, or if it\'s possible?

6条回答
  •  一个人的身影
    2020-11-29 20:35

    There is no maximum since Ruby 2.4, as Bignum and Fixnum got unified into Integer. see Feature #12005

    > (2 << 1000).is_a? Fixnum
    (irb):322: warning: constant ::Fixnum is deprecated
    => true
    
    > 1.is_a? Bignum
    (irb):314: warning: constant ::Bignum is deprecated
    => true
    
    > (2 << 1000).class
    => Integer
    

    There won't be any overflow, what would happen is an out of memory.

提交回复
热议问题