1 # depends on: class.rb integer.rb
4 # Bignum objects hold integers outside the range of Fixnum. Bignum objects are
5 # created automatically when integer calculations would otherwise overflow a
6 # Fixnum. When a calculation involving Bignum objects returns a result that
7 # will fit in a Fixnum, the result is automatically converted.
9 # For the purposes of the bitwise operations and [], a Bignum is treated as if
10 # it were an infinite-length bitstring with 2's complement representation.
12 # While Fixnum values are immediate, Bignum objects are not. Assignment and
13 # parameter passing work with references to objects, not the objects
16 class Bignum < Integer
18 # see README-DEVELOPERS regarding safe math compiler plugin
19 alias_method :/, :divide
22 if other.kind_of?(Float)
26 return self.to_f % other
30 raise TypeError unless other.kind_of?(Numeric)
31 raise ZeroDivisionError if other == 0
33 if self == 0 || self.abs == other.abs
36 mod_primitive(other)#.to_int)
41 s = Type.coerce_to(s, Integer, :to_int)
42 return self << -s if s < 0
43 unless s.is_a?(Fixnum)
48 __bignum_right_shift__(s)
52 s = Type.coerce_to(s, Integer, :to_int)
53 raise RangeError, "Object is out of range for a Fixnum" unless s.is_a?(Fixnum)
54 s < 0 ? __bignum_right_shift__(-s) : __bignum_left_shift__(s)
58 return false unless value.is_a?(Bignum)
63 alias_method :modulo, :%
67 private :radix_to_s # in kernel/bootstrap/bignum.rb