Class: Fixnum
Overview
A Fixnum holds Integer values that can be represented in a native machine word (minus 2 bits). 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.
Class Method Summary (collapse)
-
+ induced_from
Convert obj to a Fixnum.
Instance Method Summary (collapse)
-
- %
Returns fix modulo other.
-
- &
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 numeric 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 real.
-
- <<
Shifts fix left count positions (right if count is negative).
-
- <=
Returns true if the value of fix is less than or equal to that of real.
-
- <=>
Comparison---Returns -1, 0, +1 or nil depending on whether fix is less than, equal to, or greater than numeric.
-
- ==
Return true if fix equals other numerically.
-
- >
Returns true if the value of fix is greater than that of real.
-
- >=
Returns true if the value of fix is greater than or equal to that of real.
-
- >>
Shifts fix right count positions (left if count is negative).
-
- []
Bit Reference---Returns the nth bit in the binary representation of fix, where fix is the least significant bit.
-
- ^
Bitwise EXCLUSIVE OR.
-
- abs
Returns the absolute value of fix.
-
- div
Performs integer division: returns integer value.
-
- divmod
See Numeric#divmod.
-
- even?
Returns true if fix is an even number.
-
- fdiv
Returns the floating point result of dividing fix by numeric.
-
- magnitude
Returns the absolute value of fix.
-
- modulo
Returns fix modulo other.
-
- odd?
Returns true if fix is an odd number.
-
- popcnt
Returns the number of 1 bits set in the internal representation of fix.
-
- size
Returns the number of bytes in the machine representation of a Fixnum.
-
- succ
Returns the Integer equal to int + 1.
-
- to_f
Converts fix to a Float.
-
- to_s
Returns a string containing the representation of fix radix base (between 2 and 36).
-
- zero?
Returns true if fix is zero.
-
- |
Bitwise OR.
-
- ~
One's complement: returns a number where each bit is flipped.
Methods included from Precision
included, #prec, #prec_f, #prec_i
Methods inherited from Integer
#ceil, #chr, #denominator, #downto, #floor, #gcd, #gcdlcm, #integer?, #lcm, #next, #numerator, #ord, #pred, #rationalize, #round, #times, #to_i, #to_int, #to_r, #truncate, #upto
Methods inherited from Numeric
#+@, #abs2, #angle, #arg, #ceil, #class, #coerce, #conj, #conjugate, #denominator, #dup, #eql?, #floor, #i, #imag, #imaginary, #initialize_copy, #integer?, #nonzero?, #numerator, #phase, #polar, #quo, #real, #real?, #rect, #rectangular, #remainder, #round, #scalar?, #singleton_method_added, #step, #to_c, #to_int, #truncate
Methods included from Comparable
Methods inherited from NSNumber
#boolValue, #charValue, #compare:, #decimalValue, #descriptionWithLocale:, #doubleValue, #floatValue, #initWithBool:, #initWithChar:, #initWithDouble:, #initWithFloat:, #initWithInt:, #initWithInteger:, #initWithLong:, #initWithLongLong:, #initWithShort:, #initWithUnsignedChar:, #initWithUnsignedInt:, #initWithUnsignedInteger:, #initWithUnsignedLong:, #initWithUnsignedLongLong:, #initWithUnsignedShort:, #intValue, #integerValue, #isEqualToNumber:, #longLongValue, #longValue, numberWithBool:, numberWithChar:, numberWithDouble:, numberWithFloat:, numberWithInt:, numberWithInteger:, numberWithLong:, numberWithLongLong:, numberWithShort:, numberWithUnsignedChar:, numberWithUnsignedInt:, numberWithUnsignedInteger:, numberWithUnsignedLong:, numberWithUnsignedLongLong:, numberWithUnsignedShort:, #objCType, #shortValue, #stringValue, #unsignedCharValue, #unsignedIntValue, #unsignedIntegerValue, #unsignedLongLongValue, #unsignedLongValue, #unsignedShortValue
Methods inherited from NSValue
#getValue:, #initWithBytes:objCType:, #isEqualToValue:, #nonretainedObjectValue, #objCType, #pointerValue, #rangeValue, value:withObjCType:, valueWithBytes:objCType:, valueWithNonretainedObject:, valueWithPointer:, valueWithRange:
Methods inherited from NSObject
#!, #!=, #!~, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
Instance Method Details
- (Object) %(other) - (Object) modulo(other)
Returns fix modulo other. See numeric.divmod for more information.
- (Object) &(integer)
Bitwise AND.
- (Object) *(numeric)
Performs multiplication: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
- (Object) **(numeric)
Raises fix to the numeric power, which may be negative or fractional.
2 ** 3 #=> 8
2 ** -1 #=> 0.5
2 ** 0.5 #=> 1.4142135623731
- (Object) +(numeric)
Performs addition: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
- (Object) -(numeric)
Performs subtraction: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
- (Object) /(numeric)
Performs division: the class of the resulting object depends on the class of numeric and on the magnitude of the result.
- (Boolean) <(real)
Returns true if the value of fix is less than that of real.
- (Integer) <<(count)
Shifts fix left count positions (right if count is negative).
- (Boolean) <=(real)
Returns true if the value of fix is less than or equal to that of real.
- (-1, ...) <=>(numeric)
Comparison---Returns -1, 0, +1 or nil depending on whether fix is less than, equal to, or greater than numeric. This is the basis for the tests in Comparable.
- (Boolean) ==(other)
Return true if fix equals other numerically.
1 == 2 #=> false
1 == 1.0 #=> true
- (Boolean) >(real)
Returns true if the value of fix is greater than that of real.
- (Boolean) >=(real)
Returns true if the value of fix is greater than or equal to that of real.
- (Integer) >>(count)
Shifts fix right count positions (left if count is negative).
- (0, 1) [](n)
Bit Reference---Returns the nth bit in the binary representation of fix, where fix is the least significant bit.
a = 0b11001100101010
30.downto(0) do |n| print a[n] end
produces:
0000000000000000011001100101010
- (Object) ^(integer)
Bitwise EXCLUSIVE OR.
- (Integer) abs - (Integer) magnitude
Returns the absolute value of fix.
-12345.abs #=> 12345
12345.abs #=> 12345
- (Integer) div(numeric)
Performs integer division: returns integer value.
- (Boolean) even?
Returns true if fix is an even number.
- (Float) fdiv(numeric)
Returns the floating point result of dividing fix by numeric.
654321.fdiv(13731) #=> 47.6528293642124
654321.fdiv(13731.24) #=> 47.6519964693647
- (Integer) abs - (Integer) magnitude
Returns the absolute value of fix.
-12345.abs #=> 12345
12345.abs #=> 12345
- (Object) %(other) - (Object) modulo(other)
Returns fix modulo other. See numeric.divmod for more information.
- (Boolean) odd?
Returns true if fix is an odd number.
- (Fixnum) popcnt
Returns the number of 1 bits set in the internal representation of fix. This function returns consistent results across platforms for positive numbers, but may vary for negative numbers.
- (Fixnum) size
Returns the number of bytes in the machine representation of a Fixnum.
1.size #=> 4
-1.size #=> 4
2147483647.size #=> 4
- (Integer) next - (Integer) succ
Returns the Integer equal to int + 1.
1.next #=> 2
(-1).next #=> 0
- (String) to_s(base = 10)
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"
- (Boolean) zero?
Returns true if fix is zero.
- (Object) |(integer)
Bitwise OR.
- (Integer) ~
One's complement: returns a number where each bit is flipped.