Definition
An instance a of the data type integer is an integer number of arbitrary length.
#include < LEDA/integer.h >
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(unsigned int i) | creates an instance a of type integer and initializes it with the value of n. |
integer | a(long l) | creates an instance a of type integer and initializes it with the value of l. |
integer | a(unsigned long i) | creates an instance a of type integer and initializes it with the value of i. |
integer | a(double x) | creates an instance a of type integer and initializes it with the integral part of x. |
integer | a(int sz, const digit* vec) | |
creates an instance a of type integer and initializes it with the value represented by the first sz digits vec. | ||
integer | a(char* s) | a creates an instance a of type integer from its decimal representation given by the string s. |
integer | a(number_string s) | a creates an instance a of type integer from its decimal representation given by the string s. |
Operations
The arithmetic operations +, -, *, /, + =, - =, * =, / =, -(unary), + +, - -, the modulus operation (%, % =), bitwise AND (&, & =), 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.is_long() | returns whether a fits in the data type long. |
long | a.to_long() | returns a long number which is initialized with the value of a. Precondition a.is_long() is true. |
double | a.to_double() | returns a double floating point approximation of a. |
number_string | a.to_string() | returns the decimal representation of a. |
integer& | a.from_string(number_string s) | |
sets a to the number that has decimal respresentation s. | ||
sz_t | a.used_words() | returns the length of the digit vector that represents a. |
digit | a.highword() | returns the most significant digit of a. |
digit | a.contents(int i) | returns the i-th digit of a. |
void | a.hex_print(ostream& o) | prints the digit vector that represents a in hex format to the output stream o. |
bool | a.iszero() | returns whether a is equal to zero. |
Non-member functions
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.