[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cannot create fractions using generic GMP 4.1.4 in C++

From: Randall L. Rathbun
Subject: cannot create fractions using generic GMP 4.1.4 in C++
Date: Sun, 17 Oct 2004 14:39:43 -0700
User-agent: KMail/1.5

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --enable-shared --enable-threads=posix 
--disable-checking --with-system-zlib --enable-__cxa_atexit 
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

Linux npl 2.4.20-28.9smp #1 SMP Thu Dec 18 13:37:36 EST 2003 i686 i686 i386 

Using gmp 4.1.4 version

test.cpp program:
#include <gmp.h>
#include <gmpxx.h>
#include <iostream>
typedef mpz_class INT;
typedef mpq_class RAT;
int main()
INT a,b;
RAT c;
std::cout << "a " << a << " b " << b << " and c " << c << std::endl;
std::cout << "a " << a << " b " << b << " and c " << c << std::endl;
return 1;

both the constructor for mpq_class and the assignment operator appear to be 

There is no way to actually set c = (11,23) as 11/23 as we understand it, the 
assignment operator actually sets c = 23/1 and the operator function overload 
only allows 1 operator. (see the gmpxx.h header for this)

Similar the constructor does not create c(11,23) as 11/23, it creates 23/1

The gmpxx.h file seems to be missing the mpq_set_si(MP,i,j) function and the 
mpq_set_ui(MP,i,j) and instead uses the unitary mpq_set_si(MP,i,1) and 
mpq_set_ui(MP,i,1) instead, thus setting the denominators to 1.  Is this an 

Also the syntax  c = 11/23 if c is in the mpq_class should work in the 
traditional way as either a constructor or assignment, as we write fractions, 
assigning 11 to the numerator and 23 to the denominator. (perhaps the 
canonical operator can be used to insure that no factors are in common)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]