Module: Cognum

Included in:
Bignum, Fixnum
Defined in:
lib/cog/primitive.rb

Overview

Helpers for Bignum and Fixnum

Instance Method Summary collapse

Instance Method Details

#signed?(bits) ⇒ Boolean

Returns whether or not this number can fit in a singed integer of the given size in the Cog.active_language.

Parameters:

  • bits (Fixnum)

    the size of a signed integer

Returns:

  • (Boolean)

    whether or not this number can fit in a singed integer of the given size in the Cog.active_language



34
35
36
37
# File 'lib/cog/primitive.rb', line 34

def signed?(bits)
  limit = 2 ** (bits - 1)
  self >= -limit && self < limit
end

#to_litString

Returns literal representation in the Cog.active_language.

Returns:



28
29
30
# File 'lib/cog/primitive.rb', line 28

def to_lit
  Cog.active_language.to_integer(self) || Cog.active_language.to_long(self)
end