Hi mpf_trunc is driving me mad...

Carlos Torres torresc at gmail.com
Fri Nov 25 06:25:17 CET 2011

Hi mpf_trunc is driving me mad...

first of all forgive my poor english is not my default language...

... mpf_trunc in aix with gmp-5.0.2 is not working. Or there is something i
am missing

when i try to mpf_trunc a number like 1415 instead of doing nothing trunc
is decrementing the original number



example code.

#include <gmp.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

void trunc(char * pcsz ,int digits) {
        mpf_t f = {0};
        mpf_t ten = {};
        mpf_init2(ten, 256);
        mpf_init_set_str(f, pcsz, 10);
        mpf_set_ui(ten, digits);
        gmp_fprintf(stderr,"begin: %+12.05Ff\n", f);
        mpf_mul(f, f, ten);
        gmp_fprintf(stderr,"before trunc: %+12.05Ff\n", f);
        mpf_trunc(f, f);
        gmp_fprintf(stderr,"after trunc: %+12.05Ff\n", f);
        mpf_div(f, f, ten);
        gmp_fprintf(stderr,"end: %+12.05Ff\n", f);

int main( int argc, char** argv) {
        trunc("52618562.77", 100);
        trunc("52618562.77605", 100);
        trunc("52618562.7701", 100);
        return 0;

--- output ---

begin: +52618562.77000
before trunc: +5261856277.00000
after trunc: +5261856276.00000 << this is wrong
end: +52618562.76000

begin: +52618562.77605
before trunc: +5261856277.60500
after trunc: +5261856277.00000
end: +52618562.77000

begin: +52618562.77010
before trunc: +5261856277.01000
after trunc: +5261856277.00000
end: +52618562.77000

Porque los programadores confunden halloween con navidad?

Porque, OCT(31) = DEC(25)

More information about the gmp-bugs mailing list