A Fixnum holds Integer values that can be represented in a native machine word (minus 1 bit). If any operation on a Fixnum exceeds this range, the value is automatically converted to a Bignum.
Fixnum objects have immediate value. This means that when they are assigned or passed as parameters, the actual object is passed, rather than a reference to that object. Assignment does not alias Fixnum objects. There is effectively only one Fixnum object instance for any given integer value, so, for example, you cannot add a singleton method to a Fixnum.
| Public Methods | |
|---|---|
| | | Bitwise OR. |
| % | Returns fix modulo other. See Numeric.divmod for more information. |
| & | Bitwise AND. |
| * | Performs multiplication: the class of the resulting object depends on the class of numeric and on the magnitude of the result. |
| ** | Raises fix to the other power, which may be negative or fractional. |
| + | Performs addition: the class of the resulting object depends on the class of numeric and on the magnitude of the result. |
| - | Performs subtraction: the class of the resulting object depends on the class of numeric and on the magnitude of the result. |
| -@ | Negates fix (which might return a Bignum). |
| / | Performs division: the class of the resulting object depends on the class of numeric and on the magnitude of the result. |
| < | Returns true if the value of fix is less than that of other. |
| << | Shifts fix left count positions (right if count is negative). |
| <= | Returns true if the value of fix is less thanor equal to that of other. |
| <=> | Comparison—Returns -1, 0, or +1 depending on whether fix is less than, equal to, or greater than numeric. This is the basis for the tests in Comparable. |
| == | Return true if fix equals other numerically. |
| > | Returns true if the value of fix is greater than that of other. |
| >= | Returns true if the value of fix is greater than or equal to that of other. |
| >> | Shifts fix right count positions (left if count is negative). |
| [] | Bit Reference—Returns the nth bit in the binary representation of fix, where fix[0] is the least significant bit. |
| ^ | Bitwise EXCLUSIVE OR. |
| abs | Returns the absolute value of fix. |
| div | Performs division: the class of the resulting object depends on the class of numeric and on the magnitude of the result. |
| divmod | See Numeric#divmod. |
| id2name | Returns the name of the object whose symbol id is fix. If there is no symbol in the symbol table with this value, returns nil. id2name has nothing to do with the Object.id method. See also Fixnum#to_sym, String#intern, and class Symbol. |
| induced_ |
Convert obj to a Fixnum. Works with numeric parameters. Also works with Symbols, but this is deprecated. |
| modulo | Returns fix modulo other. See Numeric.divmod for more information. |
| quo | Returns the floating point result of dividing fix by numeric. |
| size | Returns the number of bytes in the machine representation of a Fixnum. |
| to_ |
Converts fix to a Float. |
| to_ |
Returns a string containing the representation of fix radix base (between 2 and 36). |
| to_ |
Returns the symbol whose integer value is fix. See also Fixnum#id2name. |
| zero? | Returns true if fix is zero. |
| ~ | One’s complement: returns a number where each bit is flipped. |
<code/>and<pre/>for code samples.