- Inheritance
- < Integer
- Included Modules
- Precision
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.
Methods
Class
Visibility | Signature |
---|---|
public | induced_from (p1) |
Instance
Visibility | Signature |
---|---|
public | % (p1) |
public | & (p1) |
public | * (p1) |
public | ** (p1) |
public | ** (other) |
public | + (p1) |
public | - (p1) |
public | -@ () |
public | / (p1) |
public | / (p1) |
public | < (p1) |
public | << (p1) |
public | <= (p1) |
public | <=> (p1) |
public | == (p1) |
public | > (p1) |
public | >= (p1) |
public | >> (p1) |
public | [] (p1) |
public | ^ (p1) |
public | abs () |
public | dclone () |
public | div (p1) |
public | divmod (p1) |
public | even? () |
public | fdiv (p1) |
public | id2name () |
public | modulo (p1) |
public | odd? () |
public | power! (p1) |
public | quo (other) |
public | quo (p1) |
public | rdiv (p1) |
public | rpower (other) |
public | size () |
public | to_f () |
public | to_s (...) |
public | to_sym () |
public | zero? () |
public | | (p1) |
public | ~ () |
Class Method Detail
Fixnum.induced_from(obj) => fixnum
Convert obj to a Fixnum. Works with numeric parameters. Also works with Symbols, but this is deprecated.
Instance Method Detail
fix % other => Numeric
fix.modulo(other) => Numeric
Returns fix modulo other. See Numeric.divmod for more information.
fix & other => integer
Bitwise AND.
fix * numeric => numeric_result
Performs multiplication: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
fix ** other => Numeric
Raises fix to the other power, which may be negative or fractional.
2 ** 3 #=> 8 2 ** -1 #=> 0.5 2 ** 0.5 #=> 1.4142135623731
**(other)
Alias for rpower
fix + numeric => numeric_result
Performs addition: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
fix - numeric => numeric_result
Performs subtraction: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
-fix => integer
Negates fix (which might return a Bignum).
fix / numeric => numeric_result
fix.div(numeric) => numeric_result
Performs division: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
/(p1)
Alias for quo
fix < other => true or false
Returns true if the value of fix is less than that of other.
fix << count => integer
Shifts fix left count positions (right if count is negative).
fix <= other => true or false
Returns true if the value of fix is less thanor equal to that of other.
fix <=> numeric => -1, 0, +1
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.
fix == other
Return true if fix equals other numerically.
1 == 2 #=> false 1 == 1.0 #=> true
fix > other => true or false
Returns true if the value of fix is greater than that of other.
fix >= other => true or false
Returns true if the value of fix is greater than or equal to that of other.
fix >> count => integer
Shifts fix right count positions (left if count is negative).
fix[n] => 0, 1
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
fix ^ other => integer
Bitwise EXCLUSIVE OR.
fix.abs → aFixnum
Returns the absolute value of fix.
-12345.abs #=> 12345 12345.abs #=> 12345
dclone()
fix / numeric => numeric_result
fix.div(numeric) => numeric_result
Performs division: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
fix.divmod(numeric) => array
See Numeric#divmod.
fix.even? → true or false
Returns true if fix is an even number.
fix.quo(numeric) => float
fix.fdiv(numeric) => float
Returns the floating point result of dividing fix by numeric.
654321.quo(13731) #=> 47.6528293642124 654321.quo(13731.24) #=> 47.6519964693647
fix.id2name → string or nil
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"
fix % other => Numeric
fix.modulo(other) => Numeric
Returns fix modulo other. See Numeric.divmod for more information.
fix.odd? → true or false
Returns true if fix is an odd number.
power!(p1)
Alias for #**
quo(other)
fix.quo(numeric) => float
fix.fdiv(numeric) => float
Returns the floating point result of dividing fix by numeric.
654321.quo(13731) #=> 47.6528293642124 654321.quo(13731.24) #=> 47.6519964693647
rdiv(p1)
Alias for quo
rpower(other)
Returns a Rational number if the result is in fact rational (i.e. other < 0).
fix.size → fixnum
Returns the number of bytes in the machine representation of a Fixnum.
1.size #=> 4 -1.size #=> 4 2147483647.size #=> 4
fix.to_f → float
Converts fix to a Float.
fix.to_s( base=10 ) → aString
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"
fix.to_sym → aSymbol
Returns the symbol whose integer value is fix. See also Fixnum#id2name.
fred = :fred.to_i fred.id2name #=> "fred" fred.to_sym #=> :fred
fix.zero? => true or false
Returns true if fix is zero.
fix | other => integer
Bitwise OR.
~fix => integer
One‘s complement: returns a number where each bit is flipped.