More debugging, harder realops test
[ipdf/code.git] / src / arbint.h
index 5fefa80..ae0b23e 100644 (file)
@@ -23,7 +23,7 @@ namespace IPDF
                        virtual ~Arbint() {}
                        Arbint(const Arbint & cpy);
                        
-                       int64_t AsDigit() const 
+                       int64_t AsDigit() const
                        {
                                int64_t digit = (m_digits.size() == 1) ? m_digits[0] : 0x7FFFFFFFFFFFFFFF;
                                return (m_sign) ? -digit : digit;
@@ -60,6 +60,20 @@ namespace IPDF
                                a -= add;
                                return a;
                        }
+
+                       inline Arbint operator-()
+                       {
+                               Arbint a(*this);
+                               a.m_sign = !a.m_sign;
+                               return a;
+                       }
+                       
+                       inline Arbint operator-() const
+                       {
+                               Arbint a(*this);
+                               a.m_sign = !a.m_sign;
+                               return a;
+                       }
                        
                        inline Arbint operator*(const Arbint & mul) const
                        {
@@ -92,6 +106,7 @@ namespace IPDF
                        
                        bool operator==(const Arbint & equ) const;
                        bool operator<(const Arbint & less) const;
+                       
 
                        inline bool operator!=(const Arbint & equ) const 
                        {
@@ -123,17 +138,31 @@ namespace IPDF
                                return result;
                        }
                        bool IsZero() const;
-                       
-                       //inline operator double() const {return double(AsDigit());}
+
+                       inline operator double() const
+                       {
+                               double acc = 0;
+                               for (int i = m_digits.size()-1; i >= 0; --i)
+                               {
+                                       acc += (double)m_digits[i];
+                                       acc *= (double)UINT64_MAX + 1.0;
+                               }
+                               if (m_sign) acc *= -1;
+                               return acc;
+                       }
                        inline operator int64_t() const {return AsDigit();}
                        //inline operator int() const {return int(AsDigit());}
                        
                        unsigned Shrink();
+                       
+                       inline Arbint Abs() const {Arbint a(*this); a.m_sign = false; return a;}
                private:                
                                
                        Arbint & AddBasic(const Arbint & add);
                        Arbint & SubBasic(const Arbint & sub);
                        
+                       void GrowDigit(digit_t new_msd); // add a new most significant digit
+                       
                        bool GetBit(unsigned i) const;
                        void BitClear(unsigned i);
                        void BitSet(unsigned i);
@@ -145,6 +174,8 @@ namespace IPDF
                        
        };      
 
+
+
 extern "C"
 {
        typedef uint64_t digit_t;
@@ -154,5 +185,7 @@ extern "C"
        digit_t div_digits(digit_t * dst, digit_t div, digit_t size, digit_t * rem);
 }
 
+
+
 }
 #endif //_ARBINT_H

UCC git Repository :: git.ucc.asn.au