[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fw: maybey an error in mpf_cmp
From: |
Paul Zimmermann |
Subject: |
Re: Fw: maybey an error in mpf_cmp |
Date: |
Tue, 26 Nov 2002 12:18:41 +0100 |
> Indeed. But in your case, the numbers were slightly different.
> The mpf_cmp function will find numbers equal that are equal even
> if they are not canonically represented,
Looking more closely at the example from Toine Bommelijn, there is clearly
a bug, either in mpf_cmp or in mpf_out_str, since two numbers with the same
binary representation (according to mpf_out_str) are said different by mpf_cmp:
lucrezia(zimmerma): ./a.out 2
x=0.101000111101011100001010001111010111000010100011110101110000101001e-3
y=0.101000111101011100001010001111010111000010100011110101110000101001e-3
cmp (x, y) = -1
Paul
#include <stdio.h>
#include "gmp.h"
int
main(int argc, char *argv[])
{
mpf_t x, y;
int iprec = atoi(argv[1]);
mpf_init2 (x, iprec);
mpf_init2 (y, iprec);
mpf_set_ui (x, 1);
mpf_div_ui (x, x, 12);
mpf_mul_ui (x, x, 100);
mpf_floor (x, x);
mpf_div_ui (x, x, 100);
mpf_set_str (y, "0.08", 10);
printf ("x=");
mpf_out_str (stdout, 2, x->_mp_size * mp_bits_per_limb, x);
printf ("\n");
printf ("y=");
mpf_out_str (stdout, 2, y->_mp_size * mp_bits_per_limb, y);
printf ("\n");
printf ("cmp (x, y) = %d\n", mpf_cmp (x, y));
mpf_clear (x);
mpf_clear (y);
return 0;
}