1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkLargeInteger.h,v $
6 Date: $Date: 2002/01/22 15:25:33 $
7 Version: $Revision: 1.6 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkLargeInteger - class for arbitrarily large ints
20 #ifndef __vtkLargeInteger_h
21 #define __vtkLargeInteger_h
23 #include "vtkObject.h"
25 class VTK_COMMON_EXPORT vtkLargeInteger
28 vtkLargeInteger(void);
29 vtkLargeInteger(long n);
30 vtkLargeInteger(unsigned long n);
31 vtkLargeInteger(int n);
32 vtkLargeInteger(unsigned int n);
33 vtkLargeInteger(const vtkLargeInteger& n);
34 ~vtkLargeInteger(void);
36 char CastToChar(void) const;
37 short CastToShort(void) const;
38 int CastToInt(void) const;
39 long CastToLong(void) const;
40 unsigned long CastToUnsignedLong(void) const;
42 int IsEven(void) const;
43 int IsOdd(void) const;
44 int GetLength(void) const; // in bits
45 int GetBit(unsigned int p) const; // p'th bit (from zero)
46 int IsZero() const; // is zero
47 int GetSign(void) const; // is negative
49 void Truncate(unsigned int n); // reduce to lower n bits
50 void Complement(void); // * -1
52 int operator==(const vtkLargeInteger& n) const;
53 int operator!=(const vtkLargeInteger& n) const;
54 int operator<(const vtkLargeInteger& n) const;
55 int operator<=(const vtkLargeInteger& n) const;
56 int operator>(const vtkLargeInteger& n) const;
57 int operator>=(const vtkLargeInteger& n) const;
59 vtkLargeInteger& operator=(const vtkLargeInteger& n);
60 vtkLargeInteger& operator+=(const vtkLargeInteger& n);
61 vtkLargeInteger& operator-=(const vtkLargeInteger& n);
62 vtkLargeInteger& operator<<=(int n);
63 vtkLargeInteger& operator>>=(int n);
64 vtkLargeInteger& operator++(void);
65 vtkLargeInteger& operator--(void);
66 vtkLargeInteger operator++(int);
67 vtkLargeInteger operator--(int);
68 vtkLargeInteger& operator*=(const vtkLargeInteger& n);
69 vtkLargeInteger& operator/=(const vtkLargeInteger& n);
70 vtkLargeInteger& operator%=(const vtkLargeInteger& n);
71 // no change of sign for following operators
72 vtkLargeInteger& operator&=(const vtkLargeInteger& n);
73 vtkLargeInteger& operator|=(const vtkLargeInteger& n);
74 vtkLargeInteger& operator^=(const vtkLargeInteger& n);
76 vtkLargeInteger operator+(const vtkLargeInteger& n) const;
77 vtkLargeInteger operator-(const vtkLargeInteger& n) const;
78 vtkLargeInteger operator*(const vtkLargeInteger& n) const;
79 vtkLargeInteger operator/(const vtkLargeInteger& n) const;
80 vtkLargeInteger operator%(const vtkLargeInteger& n) const;
81 // no change of sign for following operators
82 vtkLargeInteger operator&(const vtkLargeInteger& n) const;
83 vtkLargeInteger operator|(const vtkLargeInteger& n) const;
84 vtkLargeInteger operator^(const vtkLargeInteger& n) const;
85 vtkLargeInteger operator<<(int n) const;
86 vtkLargeInteger operator>>(int n) const;
88 friend ostream& operator<<(ostream& s, const vtkLargeInteger& n);
89 friend istream& operator>>(istream& s, vtkLargeInteger& n);
98 int IsSmaller(const vtkLargeInteger& n) const; // unsigned
99 int IsGreater(const vtkLargeInteger& n) const; // unsigned
100 void Expand(unsigned int n); // ensure n'th bit exits
101 void Contract(); // remove leading 0s
102 void Plus(const vtkLargeInteger& n); // unsigned
103 void Minus(const vtkLargeInteger& n); // unsigned