Skip to content

Instantly share code, notes, and snippets.

@c80609a
Forked from pithyless/integer.rb
Created November 8, 2016 11:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c80609a/1239a742908e7e3b4a5a2f00f18a7383 to your computer and use it in GitHub Desktop.
Save c80609a/1239a742908e7e3b4a5a2f00f18a7383 to your computer and use it in GitHub Desktop.
Ruby Integer::MAX and Integer::MIN
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment