Class: Fixnum

Inherits:
Integer show all
Includes:
Precision

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)

Instance Method Summary (collapse)

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

#between?

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

+ (Fixnum) induced_from(obj)

Convert obj to a Fixnum. Works with numeric parameters. Also works with Symbols, but this is deprecated.

Returns:

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.

- (Integer) -

Negates fix (which might return a Bignum).

Returns:

- (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.

Returns:

  • (Boolean)

- (Integer) <<(count)

Shifts fix left count positions (right if count is negative).

Returns:

- (Boolean) <=(real)

Returns true if the value of fix is less than or equal to that of real.

Returns:

  • (Boolean)

- (-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.

Returns:

  • (-1, 0, +1, nil)

- (Boolean) ==(other)

Return true if fix equals other numerically.

1 == 2      #=> false
1 == 1.0    #=> true

Returns:

  • (Boolean)

- (Boolean) >(real)

Returns true if the value of fix is greater than that of real.

Returns:

  • (Boolean)

- (Boolean) >=(real)

Returns true if the value of fix is greater than or equal to that of real.

Returns:

  • (Boolean)

- (Integer) >>(count)

Shifts fix right count positions (left if count is negative).

Returns:

- (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

Returns:

  • (0, 1)

- (Object) ^(integer)

Bitwise EXCLUSIVE OR.

- (Integer) abs - (Integer) magnitude

Returns the absolute value of fix.

-12345.abs   #=> 12345
12345.abs    #=> 12345

Overloads:

- (Integer) div(numeric)

Performs integer division: returns integer value.

Returns:

- (Array) divmod(numeric)

See Numeric#divmod.

Returns:

- (Boolean) even?

Returns true if fix is an even number.

Returns:

  • (Boolean)

Returns:

  • (Boolean)

- (Float) fdiv(numeric)

Returns the floating point result of dividing fix by numeric.

654321.fdiv(13731)      #=> 47.6528293642124
654321.fdiv(13731.24)   #=> 47.6519964693647

Returns:

- (Integer) abs - (Integer) magnitude

Returns the absolute value of fix.

-12345.abs   #=> 12345
12345.abs    #=> 12345

Overloads:

- (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.

Returns:

  • (Boolean)

Returns:

  • (Boolean)

- (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.

Returns:

- (Fixnum) size

Returns the number of bytes in the machine representation of a Fixnum.

1.size            #=> 4
-1.size           #=> 4
2147483647.size   #=> 4

Returns:

- (Integer) next - (Integer) succ

Returns the Integer equal to int + 1.

1.next      #=> 2
(-1).next   #=> 0

Overloads:

- (Float) to_f

Converts fix to a Float.

Returns:

- (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"

Returns:

- (Boolean) zero?

Returns true if fix is zero.

Returns:

  • (Boolean)

Returns:

  • (Boolean)

- (Object) |(integer)

Bitwise OR.

- (Integer) ~

One's complement: returns a number where each bit is flipped.

Returns: