VTK  9.3.0
vtkLargeInteger.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
8 #ifndef vtkLargeInteger_h
9 #define vtkLargeInteger_h
10 
11 #include "vtkCommonCoreModule.h" // For export macro
12 #include "vtkObject.h"
13 
14 VTK_ABI_NAMESPACE_BEGIN
15 class VTKCOMMONCORE_EXPORT VTK_WRAPEXCLUDE vtkLargeInteger
16 {
17 public:
19  vtkLargeInteger(long n);
20  vtkLargeInteger(unsigned long n);
22  vtkLargeInteger(unsigned int n);
24  vtkLargeInteger(long long n);
25  vtkLargeInteger(unsigned long long n);
26 
28 
29  char CastToChar() const;
30  short CastToShort() const;
31  int CastToInt() const;
32  long CastToLong() const;
33  unsigned long CastToUnsignedLong() const;
34 
35  int IsEven() const;
36  int IsOdd() const;
37  int GetLength() const; // in bits
38  int GetBit(unsigned int p) const; // p'th bit (from zero)
39  int IsZero() const; // is zero
40  int GetSign() const; // is negative
41 
42  void Truncate(unsigned int n); // reduce to lower n bits
43  void Complement(); // * -1
44 
45  bool operator==(const vtkLargeInteger& n) const;
46  bool operator!=(const vtkLargeInteger& n) const;
47  bool operator<(const vtkLargeInteger& n) const;
48  bool operator<=(const vtkLargeInteger& n) const;
49  bool operator>(const vtkLargeInteger& n) const;
50  bool operator>=(const vtkLargeInteger& n) const;
51 
64  // no change of sign for following operators
68 
74  // no change of sign for following operators
80 
81  friend ostream& operator<<(ostream& s, const vtkLargeInteger& n);
82  friend istream& operator>>(istream& s, vtkLargeInteger& n);
83 
84 private:
85  char* Number;
86  int Negative;
87  unsigned int Sig;
88  unsigned int Max;
89 
90  // unsigned operators
91  bool IsSmaller(const vtkLargeInteger& n) const; // unsigned
92  bool IsGreater(const vtkLargeInteger& n) const; // unsigned
93  void Expand(unsigned int n); // ensure n'th bit exits
94  void Contract(); // remove leading 0s
95  void Plus(const vtkLargeInteger& n); // unsigned
96  void Minus(const vtkLargeInteger& n); // unsigned
97 };
98 
99 VTK_ABI_NAMESPACE_END
100 #endif
101 
102 // VTK-HeaderTest-Exclude: vtkLargeInteger.h
class for arbitrarily large ints
vtkLargeInteger & operator=(const vtkLargeInteger &n)
vtkLargeInteger(long n)
short CastToShort() const
friend ostream & operator<<(ostream &s, const vtkLargeInteger &n)
vtkLargeInteger(unsigned long long n)
vtkLargeInteger operator--(int)
int GetSign() const
vtkLargeInteger & operator*=(const vtkLargeInteger &n)
vtkLargeInteger & operator&=(const vtkLargeInteger &n)
vtkLargeInteger(long long n)
vtkLargeInteger operator/(const vtkLargeInteger &n) const
vtkLargeInteger & operator/=(const vtkLargeInteger &n)
void Truncate(unsigned int n)
vtkLargeInteger operator<<(int n) const
bool operator<(const vtkLargeInteger &n) const
int IsZero() const
bool operator>(const vtkLargeInteger &n) const
long CastToLong() const
int CastToInt() const
vtkLargeInteger & operator%=(const vtkLargeInteger &n)
vtkLargeInteger operator+(const vtkLargeInteger &n) const
int GetBit(unsigned int p) const
vtkLargeInteger operator|(const vtkLargeInteger &n) const
vtkLargeInteger & operator^=(const vtkLargeInteger &n)
int IsOdd() const
vtkLargeInteger(unsigned int n)
char CastToChar() const
vtkLargeInteger & operator-=(const vtkLargeInteger &n)
bool operator<=(const vtkLargeInteger &n) const
bool operator==(const vtkLargeInteger &n) const
bool operator>=(const vtkLargeInteger &n) const
friend istream & operator>>(istream &s, vtkLargeInteger &n)
vtkLargeInteger operator%(const vtkLargeInteger &n) const
vtkLargeInteger operator^(const vtkLargeInteger &n) const
vtkLargeInteger(unsigned long n)
vtkLargeInteger operator++(int)
unsigned long CastToUnsignedLong() const
vtkLargeInteger & operator--()
vtkLargeInteger & operator++()
vtkLargeInteger(const vtkLargeInteger &n)
vtkLargeInteger & operator+=(const vtkLargeInteger &n)
vtkLargeInteger operator*(const vtkLargeInteger &n) const
vtkLargeInteger operator-(const vtkLargeInteger &n) const
vtkLargeInteger(int n)
vtkLargeInteger & operator<<=(int n)
vtkLargeInteger & operator|=(const vtkLargeInteger &n)
int IsEven() const
vtkLargeInteger operator&(const vtkLargeInteger &n) const
bool operator!=(const vtkLargeInteger &n) const
vtkLargeInteger & operator>>=(int n)
vtkLargeInteger operator>>(int n) const
int GetLength() const
#define VTK_WRAPEXCLUDE