I need to be able to determine a systems maximum integer in Ruby. Anybody know how, or if it’s possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ruby automatically converts integers to a large integer class when they overflow, so there’s (practically) no limit to how big they can be.
If you are looking for the machine’s size, i.e. 64- or 32-bit, I found this trick at ruby-forum.com:
If you are looking for the size of Fixnum objects (integers small enough to store in a single machine word), you can call
0.sizeto get the number of bytes. I would guess it should be 4 on 32-bit builds, but I can’t test that right now. Also, the largest Fixnum is apparently2**30 - 1(or2**62 - 1), because one bit is used to mark it as an integer instead of an object reference.