859079b4399f22b8379893248400271ec5e4af20
[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.2 $
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.2  2002-11-04 07:24:31  arjen
27    Use proper namespace for iostream classes
28
29    Revision 1.1  2002/07/25 08:01:27  arjen
30    First checkin, AXE release 0.2
31
32 *****************************/
33
34 /* static const char *RCSID = "$Id: integer.h,v 1.2 2002-11-04 07:24:31 arjen Exp $"; */
35
36
37 #include <iostream>
38
39 /*
40  *  The integer class (not int !) implements an arbitrary length
41  *  number. It allocates more words as the number grows.
42  *  When a number consists of more than one word, only the first
43  *  is signed (the most significant), the rest of the words is
44  *  unsigned.
45  *
46  *  When adding, overflow is detected if the addends are of the same
47  *  sign and the result has a different sign.
48  */
49
50 class integer
51 {
52    int nr_words;
53    short msw;     // Most significant word, in 2s complement
54    unsigned short *Number;  // least significant words.
55
56 public:
57
58    integer()
59    {
60       nr_words = 0;
61       msw = 0;
62    }
63
64    integer (long l)
65    {
66       nr_words = 1;
67       Number = new unsigned short[1];
68       Number[0] = l;
69       msw = l >> 16;
70    }
71
72    ~integer()
73    {
74       if (nr_words > 0)
75          delete Number;
76    }
77
78    integer& operator=(integer &);
79    integer operator+(integer &);
80 //   operator-()
81 //   operator*()
82 //   operator/()
83 //   operator%()
84 //   operator<<()
85 //   operator>>()
86
87    friend std::ostream& operator<<(std::ostream&, integer&);
88    friend std::istream& operator>>(std::istream&, integer&);
89 };