bug-gmp
[Top][All Lists]
Advanced

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

Bug in division for long integers?


From: Max Neunhoeffer
Subject: Bug in division for long integers?
Date: Wed, 23 Jan 2002 14:49:55 +0100
User-agent: Mutt/1.2.5i

Dear authors,

I suspect a bug in some function which is used in mpz_fdiv_qr, because the
following little program gives me a segmentation violation on my 
Pentium III processor running Linux 2.4 and compiled with gcc 2.95.
I am using gmp 4.0.1 compiled on the same machine.

#include "gmp.h"

int main(void)
{
        unsigned long exponent=100000000 ;
        mpz_t power ;
        mpz_t power2 ;
        mpz_t power10;
        mpz_t ten;
        mpz_t q,r;

        mpz_init(power) ;
        mpz_init(power2) ;
        mpz_init(ten);
        mpz_init(power10);

        mpz_set_ui(power, 1);
        mpz_mul_2exp(power2, power, exponent) ;

        mpz_set_ui(ten,10);
        mpz_pow_ui(power10,ten,16777216L);

        mpz_init(q);
        mpz_init(r);
        mpz_fdiv_qr(q,r,power2,power10);
        return 0;
}

The gnu debugger shows:

GNU gdb 19990928
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) run
Starting program: /export/home/neunhoef/karatsuba/gmptest2 

Program received signal SIGSEGV, Segmentation fault.
__gmpn_tdiv_qr (qp=0x41a4b008, rp=0x413a6008, qxn=0, np=0x400f9008, nn=3125001, 
dp=0x40ce5008, dn=1741648)
    at tdiv_qr.c:253
253                     cy = mpn_lshift (n2p, np + nn - 2 * qn, 2 * qn, cnt);
(gdb) info stack
#0  __gmpn_tdiv_qr (qp=0x41a4b008, rp=0x413a6008, qxn=0, np=0x400f9008, 
nn=3125001, dp=0x40ce5008, dn=1741648)
    at tdiv_qr.c:253
#1  0x8048b3c in __gmpz_tdiv_qr (quot=0xbffff79c, rem=0xbffff790, 
num=0xbffff7c0, den=0xbffff7b4)
    at tdiv_qr.c:100
#2  0x8048661 in __gmpz_fdiv_qr (quot=0xbffff79c, rem=0xbffff790, 
dividend=0xbffff7c0, divisor=0xbffff7b4)
    at fdiv_qr.c:47
#3  0x80485ed in main () at gmptest2.c:25
(gdb) p n2p
$1 = 0xbf02a9a4
(gdb) p np
$2 = 0x400f9008
(gdb) p nn
$3 = 3125001
(gdb) p qn
$4 = 1383353
(gdb) p cnt
$5 = 30

This looks all reasonable. Is this a bug?

Best regards,
  Max Neunhoeffer

-- 
   //  //   Max Neunhöffer <address@hidden>
  //  //   Alexianergraben 4-6, 52062 Aachen, Germany
 //  //   Tel.: +49 241 406605 (private) / +49 241 8094550 (institute)
//  //   May the Source be with you!



reply via email to

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