Back: LargeNegativeInteger-reverting to LargePositiveInteger
Up: Class reference
Forward: LargePositiveInteger-arithmetic
 
Top: GNU Smalltalk User's Guide
Contents: Table of Contents
Index: Class index
About: About this document

6.84 LargePositiveInteger

Defined in namespace Smalltalk
Category: Language-Data types

Just like my brother LargeNegativeInteger, I provide a few methods that allow LargeInteger to determine the sign of a large integer in a fast way during its calculations. For example, I know that I am larger than any LargeNegativeInteger. In addition I implement the guts of arbitrary precision arithmetic.

6.84.1 LargePositiveInteger: arithmetic  (instance)
6.84.2 LargePositiveInteger: converting  (instance)
6.84.3 LargePositiveInteger: helper byte-level methods  (instance)
6.84.4 LargePositiveInteger: numeric testing  (instance)
6.84.5 LargePositiveInteger: primitive operations  (instance)


6.84.1 LargePositiveInteger: arithmetic

+ aNumber
Sum the receiver and aNumber, answer the result

- aNumber
Subtract aNumber from the receiver, answer the result

gcd: anInteger
Calculate the GCD between the receiver and anInteger

highBit
Answer the receiver's highest bit's index


6.84.2 LargePositiveInteger: converting

asFloat
Answer the receiver converted to a Float

reverseStringBase: radix on: str
Return in a string the base radix representation of the receiver in reverse order


6.84.3 LargePositiveInteger: helper byte-level methods

bytes: byteArray1 from: j compare: byteArray2
Private - Answer the sign of byteArray2 - byteArray1; the j-th byte of byteArray1 is compared with the first of byteArray2, the j+1-th with the second, and so on.

bytes: byteArray1 from: j subtract: byteArray2
Private - Sutract the bytes in byteArray2 from those in byteArray1

bytes: bytes multiply: anInteger
Private - Multiply the bytes in bytes by anInteger, which must be < 255. Put the result back in bytes.

bytesLeftShift: aByteArray
Private - Left shift by 1 place the bytes in aByteArray

bytesLeftShift: aByteArray big: totalShift
Private - Left shift the bytes in aByteArray by totalShift places

bytesLeftShift: aByteArray n: shift
Private - Left shift by shift places the bytes in aByteArray (shift <= 7)

bytesRightShift: aByteArray big: totalShift
Private - Right shift the bytes in aByteArray by totalShift places

bytesRightShift: bytes n: aNumber
Private - Right shift the bytes in `bytes' by 'aNumber' places (shift <= 7)

bytesTrailingZeros: bytes
Private - Answer the number of trailing zero bits in the receiver

primDivide: rhs
Private - Implements Knuth's divide and correct algorithm from `Seminumerical Algorithms' 3rd Edition, section 4.3.1 (which is basically an enhanced version of the divide `algorithm' for two-digit divisors which is taught in primary school!!!)


6.84.4 LargePositiveInteger: numeric testing

abs
Answer the receiver's absolute value

negative
Answer whether the receiver is < 0

positive
Answer whether the receiver is >= 0

sign
Answer the receiver's sign

strictlyPositive
Answer whether the receiver is > 0


6.84.5 LargePositiveInteger: primitive operations

divide: aNumber using: aBlock
Private - Divide the receiver by aNumber (unsigned division). Evaluate aBlock passing the result ByteArray, the remainder ByteArray, and whether the division had a remainder

isSmall
Private - Answer whether the receiver is small enough to employ simple scalar algorithms for division and multiplication

multiply: aNumber
Private - Multiply the receiver by aNumber (unsigned multiply)




This document was generated on May, 12 2002 using texi2html