13.1 Not a Public Affair: The Representation of Numbers in LINT

Team-Fly

13.1 Not a Public Affair: The Representation of Numbers in LINT

And if my ways are not as theirs

Let them mind their own affairs.

A. E. Housman, Last Poems IX

The representation of large numbers that has been chosen for our class is an extension of the representation presented in Part I for the C language. We take from there the arrangement of the digits of a natural number as a vector of clint values, where more-significant digits occupy the places of higher index (cf. Chapter 2). The memory required for this is automatically allocated when an object is generated. This is carried out by the constructors, which are invoked either explicitly by the program or implicitly by the compiler using the allocation function new(). In the class declaration we therefore require a variable of type clint *n_l, to which is associated within one of the constructor functions a pointer to the memory allocated there. As the second element of our numerical representation we define the variable maxlen, which holds the amount of memory that was allocated by a constructor to a particular object. The variable maxlen specifies the maximum number of clint digits an object can accept. Furthermore, we would like to determine whether a LINT object has been initialized, that is, whether any numerical value at all has been assigned to it, before it is used in a numerical expression on the right side of the equal sign. To this end we introduce the integer variable init, which is initialized to zero and is then set to 1 the first time an object is assigned a numerical value. We shall organize our LINT functions and operators in such a way that an error message results if the value of a LINT object, and consequently the value of an expression, is undefined.

The variable status is, strictly speaking, not an element of our numerical representation. It is used to indicate an overflow or underflow (cf. page 18) if such an event occurs as a result of operations on LINT objects. The types and mechanisms of error messages and error handling are discussed in detail in Chapter 15.

The class LINT thus defines altogether the following elements for the representation of integers and for storing the states of objects:

   clint* n_l;   int init;   int maxlen;   int status; 

Since we are dealing here with private elements, access to these class elements is possible only by means of member or friend functions or operators. In particular, there is no possibility of direct access to the individual digits of a number represented by a LINT object.


Team-Fly


Cryptography in C and C++
Cryptography in C and C++
ISBN: 189311595X
EAN: 2147483647
Year: 2001
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net