------- Comment #4 from sylvain dot pion at sophia dot inria dot fr  2007-03-19 
16:50 -------
(sorry I still can't create attachments)

-ftrapw makes the program work (no loop).

Let me copy-paste here the non-preprocessed source files which show everything
which is executed, while waiting for bugzilla to allow me to add the large
pre-processed file.

-----------------------------
#ifndef CGAL_MP_FLOAT_H
#define CGAL_MP_FLOAT_H

#include <vector>

typedef short      limb;   // unused
typedef int        limb2;  // unused

struct MP_Float
{
  typedef std::vector<short>  V;
  typedef V::iterator        iterator; // unused

  V v;
  int exp; // unused

  MP_Float(short i)
    : v(1)
  {
    v[0] = i;
    canonicalize();
  }

  void remove_leading_zeros()
  {
    while ((!v.empty()) && (v.back() == 0))
      v.pop_back();
  }

  void remove_trailing_zeros()
  {
    if (v.empty() || (v.front() != 0))
      return;

    V::iterator i = v.begin();
    for (++i; *i == 0; ++i) ;
    //v.erase(v.begin(), i);
  }

  void canonicalize()
  {
    remove_leading_zeros();
    remove_trailing_zeros();
  }

  // replacing int by std::size_t appears to also fix the loop...
  int max_exp() const
  {
    return v.size();
  }

  short of_exp(int i) const
  {
    if (i >= max_exp()) return 0;
    return v[i];
  }
};

// This union is used to convert an unsigned short to a short with
// the same binary representation, without invoking implementation-defined
// behavior (standard 4.7.3).
union to_signed {
    unsigned short us;
    short s;
};

inline
void split(int l, short & high, short & low)
{
    to_signed l2 = {l};
    low = l2.s;
    high = (l - low) >> 16;
}

MP_Float
operator_minus(const MP_Float &a, const MP_Float & b /* unused */)
{
  int max_exp = std::max(a.max_exp(), b.max_exp());

  MP_Float r(0);
  r.v.resize(2);
  for(int i = 0; i < max_exp ; ++i)
  {
    int tmp = r.v[i] + (a.of_exp(i) - b.of_exp(i));
    split(tmp, r.v[i+1], r.v[i]);
  }
  r.canonicalize();
  return r;
}

#endif // CGAL_MP_FLOAT_H

// #include <CGAL/MP_Float_loop.h>
#include <CGAL/number_type_basic_loop.h> // this one pulls up unrelated stuff
but necessary for the bug to show up

int main()
{
  MP_Float a=2, b=1;
  MP_Float d= operator_minus(a, a);
}

-----------------------------


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31268

Reply via email to