![]()
|
integer Specification SheetComputer Algebra Kit (c) 1992,00 by Comp.Alg.Objects. All Rights Reserved.
BigIntInherits from: CAObjectMaturity 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.
Method typesCreationIdentityInserting and Removing DigitsAccessing DigitsString ValueCoercion
ComparingAdditionMultiplicationDivisionParityGreatest Common DivisorPrintingMethodsnew+newReturns a new integer equal to zero. The instance method zero returns a shared, zero integer object. See also: - zero
str:+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:(int)intValueReturns a new integer with value equal to intValue.
factorial:+factorial:(int)nReturns a new integer object that is the n-th factorial.
fibonacci:+fibonacci:(int)nReturns a new object that is the n-th Fibonacci number. (Not implemented).
copy-copyMakes a copy of the digits.
deepCopy-deepCopyFor integer objects, deepCopy is equivalent to copy.
release-releaseFrees the array of digits of the integer object.
numDigits- (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.
isDigit- (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:-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.
removeDigit- (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.
digitAt:- (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.
lastDigit- (DIGIT)lastDigitReturns the least significant digit of the integer, the digit at position 0. Returns 0 if the integer is zero.
leadingDigit- (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- (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:(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).
asNumerical-asNumericalReturns a new instance of the Float class whose float value is equal to that of the integer. See also: floatValue
asModp:-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
digitValue- (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:-digitValue:(DIGIT)aValueReturns a new (positive) integer object, with value equal to aValue.
ulongValue- (unsigned long)ulongValueReturns the two last digits of the integer as an unsigned long value.
ulongValue:-ulongValue:(unsigned long)aValueReturns a (positive) integer with value as unsigned long equal to aValue.
intValue- (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:-intValue:(int)aValueReturns a new integer with value equal to aValue.
doubleValue- (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.
floatValue- (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.
zero-zeroReturns a copy of a shared integer instance with value equal to zero.
addDigit:-addDigit:(DIGIT)dReturns a new integer that is the sum of the integer self and the digit d.
subtractDigit:-subtractDigit:(DIGIT)dReturns a new integer that is the equal to the integer self minus the digit d.
one-oneReturns a copy of a shared integer instance with value equal to one.
minusOne-minusOneReturns a copy of the integer minus one.
multiplyDigit:-multiplyDigit:(DIGIT)dReturns the product of the integer and the digit d (the product is a new object).
inverse-inverseReturns nil, except if the integer is one or minus one, in which case the method returns a copy of the object itself.
divide:-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:-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:-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:quotient:-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:remainder:-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.
remainderDigit:- (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.
isEven- (BOOL)isEvenWhether the integer is even i.e., zero or divisible by two.
isOdd- (BOOL)isOddWhether the integer is odd i.e., not divisible by two.
gcd:-gcd:bReturns a new (non-negative) integer, the greatest common divisor of the two integers, computed by the Euclidean algorithm.
printsLeadingSign- (BOOL)printsLeadingSignReturns YES if the integer is negative.
printOn:-printOn:(IOD)aFilePrints the integer in decimal representation to aFile.
|