Integer: Fixed compiler warnings
authorArjen Baart <arjen@andromeda.nl>
Mon, 4 Nov 2019 18:21:35 +0000 (19:21 +0100)
committerArjen Baart <arjen@andromeda.nl>
Mon, 4 Nov 2019 18:21:35 +0000 (19:21 +0100)
src/Integer.cpp
src/Integer.h
src/builtin.h
test/tInteger.cpp

index c6a931a..57de7d2 100644 (file)
@@ -1747,7 +1747,8 @@ IntRep* bitop(const IntRep* x, long y, IntRep* r, char op)
   unsigned short tmp[SHORT_PER_LONG];
   unsigned long u;
   int newsgn;
-  if (newsgn = (y >= 0))
+  newsgn = (y >= 0);
+  if (newsgn != 0)
     u = y;
   else
     u = -y;
@@ -2169,7 +2170,7 @@ void Integer::printon(std::ostream& s, int base /* =10 */, int width /* =0 */) c
   char* f = cvtItoa(x, fmtbase, fmtlen, base, showbase, width, align_right,
                    fillchar, Xcase, showpos);
   s.write(f, fmtlen);
-  delete fmtbase;
+  delete[] fmtbase;
 }
 
 char*  cvtItoa(const IntRep* x, char* fmt, int& fmtlen, int base, int showbase,
index 58da747..7ed5797 100644 (file)
@@ -208,8 +208,16 @@ public:
                   operator long() const;
                   operator double() const;
 
-  friend char*    Itoa(const Integer& x, int base = 10, int width = 0);
-  friend Integer  atoI(const char* s, int base = 10);
+  friend char*    Itoa(const Integer& x, int base = 10, int width = 0)
+  {
+    return Itoa(x.rep, base, width);
+  }
+
+  friend Integer  atoI(const char* s, int base = 10)
+  {
+    Integer r; r.rep = atoIntRep(s, base); return r;
+  }
+
   void           printon(std::ostream& s, int base = 10, int width = 0) const;
   
   friend std::istream& operator >> (std::istream& s, Integer& y);
@@ -759,11 +767,6 @@ inline int odd(const Integer& y)
   return y.rep->len > 0 && (y.rep->s[0] & 1);
 }
 
-inline char* Itoa(const Integer& y, int base, int width)
-{
-  return Itoa(y.rep, base, width);
-}
-
 
 
 inline long lg(const Integer& x) 
@@ -940,10 +943,6 @@ inline Integer operator ~ (const Integer& x)
   Integer r; complement(x, r); return r;
 }
 
-inline Integer  atoI(const char* s, int base) 
-{
-  Integer r; r.rep = atoIntRep(s, base); return r;
-}
 
 inline Integer  gcd(const Integer& x, const Integer& y) 
 {
index 8a00f6e..9600daf 100644 (file)
@@ -28,7 +28,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 #endif
 #define _builtin_h 1
 
-#include <_G_config.h>
+//#include <_G_config.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
index d0b7c83..4945eef 100644 (file)
@@ -317,7 +317,7 @@ void facttest(Integer& one, Integer& two)
   result = sqrt(fact30);
   std::cout << "sqrt(fact30) = " << result << "\n";
 
-  Integer negfact31 = fact30 * -31;
+  Integer negfact31 = fact30 * long(-31);
   Integer posfact31 = abs(negfact31);
   assert(negfact31.OK());
   assert(posfact31.OK());
@@ -380,14 +380,14 @@ void modtest()
   Integer b, e, m;
 
   m = 1; m <<= 32;
-  b = m + 1;
+  b = m + long(1);
 
   e = Ipow( 2, 32 );
   b = Ipow( 2, 32 );                  // use b as a comparison
   std::cout << "2^32 = " << e << "\n";
 
-  e %= (e-1);                         // do same op two ways...
-  b = b % (b - 1);
+  e %= (e-long(1));                         // do same op two ways...
+  b = b % (b - long(1));
 
   std::cout << "2^32 % (2^32-1) = " << e << "\n"; // e is incorrect here
   std::cout << "2^32 % (2^32-1) = " << b << "\n"; // but b is ok