Why am I getting the wrong output?

Shlomi Fish shlomif at shlomifish.org
Sat Jul 14 17:30:27 CEST 2012


Hi all,

With this C program:

[CODE]
/*
 *       Filename:  gmp_test.c
 *         Author:  Shlomi Fish (under MIT/X11).
 *         Build with:
 *          gcc gmp_test.c -lgmp
 */
#include <stdlib.h>
#include <stdio.h>
#include "gmp.h"

int main(int argc, char * argv[])
{
    mpz_t data, q, r;
    unsigned long base = 52;

    mpz_init_set_ui(data, 4444);
    mpz_init(q);
    mpz_init(r);

    mpz_cdiv_qr_ui(q, r, data, base);

    printf("GMP: 4444 % 52 ==  %d\n", (int)mpz_get_ui(r));
    printf("[C]: 4444 % 52 ==  %d\n", (int)(4444 % 52));

    mpz_clear(data);
    mpz_clear(q);
    mpz_clear(r);

    return 0;
}

[/CODE]

I am getting:

[SHELL]
shlomif at lap:~$ gcc gmp_test.c -lgmp
shlomif at lap:~$ LD_LIBRARY_PATH="$HOME/apps/gmp/lib" ldd ./a.out 
        linux-vdso.so.1 =>  (0x00007fff037ff000)
        libgmp.so.10 => /home/shlomif/apps/gmp/lib/libgmp.so.10 (0x00007f4b8e191000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f4b8de05000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4b8e3fd000)
shlomif at lap:~$ LD_LIBRARY_PATH="$HOME/apps/gmp/lib" ./a.out 
GMP: 4444 % 52 ==  28
[C]: 4444 % 52 ==  24
shlomif at lap:~$ 
[/SHELL]

Why? Is this a bug?

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
"Star Trek: We, the Living Dead" - http://shlom.in/st-wtld

Chuck Norris taught God how to create the universe.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


More information about the gmp-discuss mailing list