Skip to content

Instantly share code, notes, and snippets.

@darbio
Forked from pithyless/integer.rb
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save darbio/54852fc8bca4c47444c1 to your computer and use it in GitHub Desktop.

Select an option

Save darbio/54852fc8bca4c47444c1 to your computer and use it in GitHub Desktop.

Revisions

  1. @pithyless pithyless created this gist Mar 24, 2014.
    10 changes: 10 additions & 0 deletions integer.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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