Class | Fixnum |
In: |
numeric.c
lib/mathn.rb lib/rational.rb lib/rexml/xpath_parser.rb |
Parent: | Integer |
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.
Convert obj to a Fixnum. Works with numeric parameters. Also works with Symbols, but this is deprecated.
Returns fix modulo other. See Numeric.divmod for more information.
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.
2 ** 3 #=> 8 2 ** -1 #=> 0.5 2 ** 0.5 #=> 1.4142135623731
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.
Performs division: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
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.
Bit Reference—Returns the nth bit in the binary representation of fix, where fix[0] is the least significant bit.
a = 0b11001100101010 30.downto(0) do |n| print a[n] end
produces:
0000000000000000011001100101010
Performs division: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
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.
symbol = :@inst_var #=> :@inst_var id = symbol.to_i #=> 9818 id.id2name #=> "@inst_var"
Returns fix modulo other. See Numeric.divmod for more information.
Returns the floating point result of dividing fix by numeric.
654321.quo(13731) #=> 47.6528293642124 654321.quo(13731.24) #=> 47.6519964693647
Returns the number of bytes in the machine representation of a Fixnum.
1.size #=> 4 -1.size #=> 4 2147483647.size #=> 4
Returns a string containing the representation of fix radix base (between 2 and 36).
12345.to_s #=> "12345" 12345.to_s(2) #=> "11000000111001" 12345.to_s(8) #=> "30071" 12345.to_s(10) #=> "12345" 12345.to_s(16) #=> "3039" 12345.to_s(36) #=> "9ix"
Returns the symbol whose integer value is fix. See also Fixnum#id2name.
fred = :fred.to_i fred.id2name #=> "fred" fred.to_sym #=> :fred
ruby-doc.org is a service of James Britt and Neurogami, a Ruby application development company in Phoenix, AZ.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.