First checkin, AXE release 0.2
[AXE.git] / src / integer.h
1 /**************************************************************************
2 **  (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : integer.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.1 $
9 **
10 **  DESCRIPTION      :  Arbitrary length integer
11 **
12 **  EXPORTED OBJECTS : 
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Feb 06, 1998
20 **      LAST UPDATE     : Oct 16, 1999
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: integer.h,v $
26    Revision 1.1  2002-07-25 08:01:27  arjen
27    First checkin, AXE release 0.2
28
29 *****************************/
30
31 /* static const char *RCSID = "$Id: integer.h,v 1.1 2002-07-25 08:01:27 arjen Exp $"; */
32
33
34 #include <stream.h>
35
36 /*
37  *  The integer class (not int !) implements an arbitrary length
38  *  number. It allocates more words as the number grows.
39  *  When a number consists of more than one word, only the first
40  *  is signed (the most significant), the rest of the words is
41  *  unsigned.
42  *
43  *  When adding, overflow is detected if the addends are of the same
44  *  sign and the result has a different sign.
45  */
46
47 class integer
48 {
49    int nr_words;
50    short msw;     // Most significant word, in 2s complement
51    unsigned short *Number;  // least significant words.
52
53 public:
54
55    integer()
56    {
57       nr_words = 0;
58       msw = 0;
59    }
60
61    integer (long l)
62    {
63       nr_words = 1;
64       Number = new unsigned short[1];
65       Number[0] = l;
66       msw = l >> 16;
67    }
68
69    ~integer()
70    {
71       if (nr_words > 0)
72          delete Number;
73    }
74
75    integer& operator=(integer &);
76    integer operator+(integer &);
77 //   operator-()
78 //   operator*()
79 //   operator/()
80 //   operator%()
81 //   operator<<()
82 //   operator>>()
83
84    friend ostream& operator<<(ostream&, integer&);
85    friend istream& operator>>(istream&, integer&);
86 };