Definition
An instance a of the data type integer is an integer number of arbitrary length.
Creation
integer | a; | creates an instance a of type integer and initializes it with zero. |
integer |
a(int n); | creates an instance a of type integer and initializes it with the value of n. |
integer |
a(double x); | creates an instance a of type integer and initializes it with the integral part of x. |
|
Operations
The arithmetic operations +, -, *, /, +=, -=, *=, /=, -(unary), ++, -, the modulus operation ( bitwise OR (|, | =), the complement ( ), the shift operations (<<, >>), the comparison operations <, <=, >, >=, ==, != and the stream operations all are available.
int | a.length() | returns the number of bits of the representation of a. |
bool | a.islong() | returns whether a fits in the data type long. |
bool | a.iszero() | returns whether a is equal to zero. |
long | a.to_long() | returns a long number which is initialized with the value of a. Precondition: a.islong() is true. |
double | a.to_double() | returns a double floating point approximation of a. |
string | a.to_string() | returns the decimal representation of a. |
Non-member functions
double | Double(integer a) | returns a double floating point approximation of a. |
integer | sqrt(integer a) | returns the largest integer which is not larger than the squareroot of a. |
integer | abs(integer a) | returns the absolute value of a. |
integer | gcd(integer a, integer b) | returns the greatest common divisor of a and b. |
int | log(integer a) | returns the logarithm of a to the basis 2. |
int | sign(integer a) | returns the sign of a. |
integer | sqr(integer a) | returns a^2. |
integer | integer::random(int n) | returns a random integer of length n bits. |
Implementation
An integer is essentially implemented by a vector vec of unsigned long numbers. The sign and the size are stored in extra variables. Some time critical functions are also implemented in sparc assembler code.