integer Specification Sheet
Computer Algebra Kit (c) 1992,00 by Comp.Alg.Objects. All Rights Reserved.
BigIntInherits from: CAObject
Maturity Index: Relatively mature
Class DescriptionAn integer (alias BigInt) is an array of digits, each digit is a value of type DIGIT declared as unsigned short int. So, abstractly, the integer is expressed base USHRT_MAX + 1, which is a power of two. (USHRT_MAX is defined in the ANSI header file limits.h) The most significant (or leading) digit is never zero; the last digit is the least significant digit of the integer. There are methods to count, access, insert or remove digits. Besides the normal elementary arithmetical operations, Integer also supports multiplication, division etc. by digits. For input and output, integers are in decimal representation.
Inserting and Removing Digits
Greatest Common Divisor
+newReturns a new integer equal to zero. The instance method zero returns a shared, zero integer object.
See also: - zero
+str:(STR)aStringReturns a new integer from the decimal representation aString, or returns nil if aString doesn't contain decimal characters (with optional unary minus sign).
+int:(int)intValueReturns a new integer with value equal to intValue.
+factorial:(int)nReturns a new integer object that is the n-th factorial.
+fibonacci:(int)nReturns a new object that is the n-th Fibonacci number. (Not implemented).
-copyMakes a copy of the digits.
-deepCopyFor integer objects, deepCopy is equivalent to copy.
-releaseFrees the array of digits of the integer object.
- (int)numDigitsReturns the number of DIGIT's in the integer. Returns zero if the integer is zero. The leading digit of an integer is at position numDigits minus one.
- (BOOL)isDigitWhether the integer consists of a single digit. If the integer is zero, this method returns NO. The method ignores the sign of the integer.
See also: digitValue
-insertDigit:(DIGIT)dInserts d as last digit, shifting the other digits one position up. The method doesn't insert anything if both the integer and d are equal to zero.
- (DIGIT)removeDigitRemoves and returns the last digit, shifting the other digits one position down. The method returns zero if the integer is equal to zero.
- (DIGIT)digitAt:(int)iReturns the digit at position i. The leading digit is position numDigits minus one. The last digit is at position zero. Returns 0 if the index is less than zero or equal to or greater than numDigits.
- (DIGIT)lastDigitReturns the least significant digit of the integer, the digit at position 0. Returns 0 if the integer is zero.
- (DIGIT)leadingDigitReturns the most significant digit of the integer, the digit at position numDigits minus one. The leading digit of a nonzero integer is never zero. The method returns 0 if the integer is zero.
- (STR)strReturns the decimal representation of the integer as a NULL-terminated string of characters. The string is automatically disposed off when freeing the integer, or when modifying the integer with methods that work destructively on the integer such as removeDigit or insertDigit:.
-str:(STR)aStringReturns a new integer from the decimal representation aString, or returns nil if aString doesn't contain decimal characters (with optional unary minus sign).
-asNumericalReturns a new instance of the Float class whose float value is equal to that of the integer.
See also: floatValue
-asModp:(unsigned short)pReturns a new instance of the IntegerModp class whose value is equal to that of the integer modulo p (with p a small prime number). Negative integers are mapped to the opposite (mod p) of their absolute value.
See also: IntegerModp
- (DIGIT)digitValueEquivalent to lastDigit. This method ignores the sign of the integer i.e., for a negative integer that consists of just one digit, it returns the absolute value of the integer.
-digitValue:(DIGIT)aValueReturns a new (positive) integer object, with value equal to aValue.
- (unsigned long)ulongValueReturns the two last digits of the integer as an unsigned long value.
-ulongValue:(unsigned long)aValueReturns a (positive) integer with value as unsigned long equal to aValue.
- (int)intValueReturns the value of the integer as int value, if possible. If the integer is too large to represented as int, the method returns INT_MIN or INT_MAX depending on the sign of the integer.
-intValue:(int)aValueReturns a new integer with value equal to aValue.
- (double)doubleValueReturns the integer as a floating-point double value, if possible. If the integer is too big to be represented as double, the method returns DBL_MIN or DBL_MAX depending on the sign of the integer.
- (float)floatValueReturns the integer as a floating-point float value, if possible. If the integer is too big to be represented as float, the method returns FLT_MIN or FLT_MAX depending on the sign of the integer.
-zeroReturns a copy of a shared integer instance with value equal to zero.
-addDigit:(DIGIT)dReturns a new integer that is the sum of the integer self and the digit d.
-subtractDigit:(DIGIT)dReturns a new integer that is the equal to the integer self minus the digit d.
-oneReturns a copy of a shared integer instance with value equal to one.
-minusOneReturns a copy of the integer minus one.
-multiplyDigit:(DIGIT)dReturns the product of the integer and the digit d (the product is a new object).
-inverseReturns nil, except if the integer is one or minus one, in which case the method returns a copy of the object itself.
-divide:bReturns the exact quotient on division by b. Returns nil if the divisor b is zero or if the division is not exact (when the remainder is not zero).
See also: quotient:
-divideDigit:(DIGIT)bReturns the exact quotient on division by the digit b. Returns nil if the divisor b is zero or if the division is not exact (when the remainder is not zero).
-quotientDigit:(DIGIT)bReturns the quotient on division by the digit b; the division need not necessarily be exact. Returns nil if b is equal to zero.
-remainder:bquotient:(id *)qReturns the remainder and, if a non-NULL pointer is passed for q, the quotient on division of the dividend self by a divisor b. Both remainder and quotient are new integer objects. The remainder is signed i.e., its sign is the same as the sign of the dividend; the relation dividend == quotient divisor + remainder holds for all integers.
-quotientDigit:(DIGIT)dremainder:(DIGIT *)rReturns the quotient and, if a non-NULL pointer is passed along for r, the unsigned remainder on division by a digit d; the relation dividend == quotient divisor + remainder does not hold if the dividend is negative.
- (DIGIT)remainderDigit:(DIGIT)dReturns the unsigned remainder on division by a digit d i.e., the sign of the object is ignored. The divisor d shouldn't be equal to zero.
- (BOOL)isEvenWhether the integer is even i.e., zero or divisible by two.
- (BOOL)isOddWhether the integer is odd i.e., not divisible by two.
-gcd:bReturns a new (non-negative) integer, the greatest common divisor of the two integers, computed by the Euclidean algorithm.
- (BOOL)printsLeadingSignReturns YES if the integer is negative.
-printOn:(IOD)aFilePrints the integer in decimal representation to aFile.