Problem with assignment operator

Linus Nordberg linus at nordberg.se
Tue Jan 11 20:40:21 CET 2005


William Garrett Mitchener <wgm at math.duke.edu> wrote
Tue, 11 Jan 2005 13:57:33 -0500 (EST):

|  #include <gmp.h>
|  #include <gmpxx.h>
|  #include <iostream>
|  
|  using namespace std;
|  
|  int
|  main(int, char**)
|  {
|     mpz_class a, b;
|     a = 9;
|     b = -14;
|  
|     mpq_class c;
|     c = mpq_class(a, b); // seg fault here
|  
|     cout << c << endl;
|  }

The denominator mustn't be negative.  From the fine manual, section
Rational Number Functions:

     All rational arithmetic functions assume operands have a canonical
  form, and canonicalize their result.  The canonical from means that the
  denominator and the numerator have no common factors, and that the
  denominator is positive.  Zero has the unique representation 0/1.

Wether a segfault is a reasonable punishment for not obeying this rule
or not, I couldn't tell.  Cc to the GMP discussion list.


More information about the gmp-discuss mailing list