<ppdoc>
<copyright>
    Copyright (c) 2001 by Addison Wesley Longman.  This
    material may be distributed only subject to the terms and
    conditions set forth in the Open Publication License, v1.0 or
    later (the latest version is presently available at
    http://www.opencontent.org/openpub/).
</copyright>
<class name="Fixnum" super="Integer" type="class" ref="xref-000001">
    A <classname>Fixnum</classname> holds <tt>Integer</tt> values that can be represented in a
  native machine word (minus 1 bit). If any operation on a
  <tt>Fixnum</tt> exceeds this range, the value is automatically converted
  to a <tt>Bignum</tt>.
<p/>
  <tt>Fixnum</tt> 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
  <tt>Fixnum</tt> objects. There is effectively only one <tt>Fixnum</tt>
  object instance for any given integer value, so, for example, you
  cannot add a singleton method to a <classname>Fixnum</classname>.
<p/>
  <methods type="instance">
        <method name="Arithmetic operations" ref="Arithmeticoperations">
      <callseq>
<p/>
      </callseq>
      <desc>
<p/>
      Performs various arithmetic operations on <obj>fix</obj>.                                    
<p/>
      <table>
<tr>
  <td><obj>fix</obj></td>
  <td>+</td>
  <td><obj>aNumeric</obj></td>
  <td>Addition</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>--</td>
  <td><obj>aNumeric</obj></td>
  <td>Subtraction</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>*</td>
  <td><obj>aNumeric</obj></td>
  <td>Multiplication</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>/</td>
  <td><obj>aNumeric</obj></td>
  <td>Division</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>%</td>
  <td><obj>aNumeric</obj></td>
  <td>Modulo</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>**</td>
  <td><obj>aNumeric</obj></td>
  <td>Exponentiation</td>
</tr>
</table>
<p/>
      </desc>
    </method>
<p/>
        <method name="Bit operations" ref="Bitoperations">
      <callseq>
<p/>
      </callseq>
      <desc>
<p/>
      Performs various operations on the binary representations of the
      <tt>Fixnum</tt>.                                    
<p/>
      <table>
<tr>
<td colspan="3">~ <obj>fix</obj></td>
  <td>Invert bits</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>|</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>OR</smallfont></td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>&amp;</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>AND</smallfont></td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>^</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>EXCLUSIVE</smallfont> <smallfont>OR</smallfont></td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>&lt;&lt;</td>
  <td><obj>aNumeric</obj></td>
  <td>Left-shift <em>aNumeric</em> bits</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>&gt;&gt;</td>
  <td><obj>aNumeric</obj></td>
  <td>Right-shift <em>aNumeric</em>
      bits (with sign extension)</td>
</tr>
</table>
<p/>
      </desc>
    </method>
<p/>
        <method name="&lt;=&gt;" ref="_lt_eq_lt">
      <callseq>
        <obj>fix</obj> &lt;=&gt; <obj>aNumeric</obj>
        <returns>-1, 0, +1</returns>
      </callseq>
      <desc>
<p/>
      Comparison---Returns -1, 0, or +1 depending on whether <obj>fix</obj> is less
      than, equal to, or greater than <obj>aNumeric</obj>. This is the
      basis for the tests in <tt>Comparable</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="[ ]" ref="_ob_cb">
      <callseq>
        <obj>fix</obj>[ <obj>n</obj> ] <returns>0, 1</returns>
      </callseq>
      <desc>
<p/>
      Bit Reference---Returns the <em>n</em>th bit in the binary
      representation of <obj>fix</obj>, where <obj>fix</obj>[0] is the least significant
      bit.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        a = 0b11001100101010
        30.downto(0) do |n| print a[n] end
!-        print "\n"
]]></fullcode>
a<nbsp/>=<nbsp/>0b11001100101010
30.downto(0)<nbsp/>do<nbsp/>|n|<nbsp/>print<nbsp/>a[n]<nbsp/>end
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
0000000000000000011001100101010
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="id2name" ref="id2name">
      <callseq>
        <obj>fix</obj>.id2name <returns><obj>aString</obj> or <tt>nil</tt></returns>
      </callseq>
      <desc>
                    Returns the name of the object whose symbol
      id is the value of <obj>fix</obj>.  If there is no symbol in the symbol
      table with this value, returns <tt>nil</tt>.
      <meth>id2name</meth> has nothing to do with the <tt>Object.id</tt>
      method. See also <cim><file>string</file><front>String</front><back>intern</back><mref>intern</mref></cim>
      on page 371 and class <classname>Symbol</classname> on page 383.
<p/>
<codefragment>
<fullcode><![CDATA[         symbol = :@inst_var
         id     = symbol.to_i
         id.id2name
]]></fullcode><rubycode>
<tr>
  <td><tt>symbol<nbsp/>=<nbsp/>:@inst_var</tt></td>
  <td>&#187;</td>
  <td><tt>:@inst_var</tt></td>
</tr>
<tr>
  <td><tt>id<nbsp/><nbsp/><nbsp/><nbsp/><nbsp/>=<nbsp/>symbol.to_i</tt></td>
  <td>&#187;</td>
  <td><tt>8978</tt></td>
</tr>
<tr>
  <td><tt>id.id2name</tt></td>
  <td>&#187;</td>
  <td><tt>"@inst_var"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="size" ref="size">
      <callseq>
        <obj>fix</obj>.size <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the number of <em>bytes</em> in the machine representation
      of a <tt>Fixnum</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_f" ref="to_f">
      <callseq>
        <obj>fix</obj>.to_f <returns><obj>aFloat</obj></returns>
      </callseq>
      <desc>
<p/>
      Converts <obj>fix</obj> to a <tt>Float</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_i" ref="to_i">
      <callseq>
        <obj>fix</obj>.to_i <returns><obj>fix</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns <obj>fix</obj>.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_s" ref="to_s">
      <callseq>
        <obj>fix</obj>.to_s <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a string containing the decimal representation of self.
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>
