I'm wondering the range of Fixnum and Bignum. In Float, I can get the range of Float with Float::MAX and Float::MIN. There are not analogous constants in Fixnum and Bignum. What's the best way to achieve this?
Forget Fixnum
and Bignum
. They are private internal implementation details. They are optimizations. You should ignore them. The only class you should be concerned about is Integer
.
The ISO Ruby Language Specification only specifies the Integer
class. It allows for implementation-specific subclasses, but it doesn't specify them.
Fixnum
s are an optimization that should be internal to the implementation and should never have been exposed to the programmer. Think about flonums in YARV. Did you even notice flonums were introduced in YARV 2.0? All they do is make certain Float
s faster. But you never see them. Which is as it should be.
And in fact, YARV 2.4 removes Fixnum
and Bignum
and will only have Integer
s in the future. Fixnum
and Bignum
will stay around for a while as aliases for Integer
, for backwards-compatibility reasons, but the classes themselves will be gone.
In Ruby, Integer
s don't have a maximum or minimum value; they are arbitrary-size integers. Therefore, there aren't any such constants.
The size limit for Fixnum
s (if they exist at all) depends on the platform and implementation. On JRuby, Fixnum
s are always 64-bit, on YARV, they are 63-bit on 64-bit platforms and 31-bit on 32-bit platforms. On Opal, Integer
s are implemented as ECMAScript Number
s (which are actually IEEE754 floats and thus are only accurate for 53-bits), and I don't think they even have Fixnum
s or Bignum
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With