[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
maybey an error in mpf_cmp
From: |
Toine Bommelijn |
Subject: |
maybey an error in mpf_cmp |
Date: |
Mon, 25 Nov 2002 18:17:40 +0100 |
Hi,
I suspect that there is a problem with the function "mpf_cmp". I compare two
floating-point values, the left argument is the result of the calculation
truncate((1/12 * 1) * 100) / 100 and contains the value 0.08 and the other
value that has been directly converted from a string and is also 0.08.
I added the following two lines in front of the call to "mpf_cmp" because of
the result it returned.
char *Str1, *Str2;
gmp_asprintf( &Str1, "%0.Fg", *(Arg1->GFloat()) );
gmp_asprintf( &Str2, "%0.Fg", *(Arg2->GFloat()) );
The debugger shows that both strings are "0.08", but "mpf_cmp" returns the
value "1"
int Result = mpf_cmp( *(Arg2->GFloat()), *(Arg1->GFloat()) );
With the debugger I could see that the left argument has size 6 and the
right argument has size 5.
_mp_prec = 5
_mp_size = 6
_mp_exp = 0
The values of the right mpf structure are:
_mp_prec = 5
_mp_size = 5
_mp_exp = 0
Looking at the source of "mpf_cmp" I suspect the following lines might
contain an error.
if (usize > vsize)
{
cmp = mpn_cmp (up + usize - vsize, vp, vsize);
if (cmp == 0)
return usign;
}
else if (vsize > usize)
{
cmp = mpn_cmp (up, vp + vsize - usize, usize);
if (cmp == 0)
return -usign;
}
else
{
cmp = mpn_cmp (up, vp, usize);
if (cmp == 0)
return 0;
}
The first condition is true because usize=6 and vsize=5, the result of the
"mpn_cmp" function is 0 but the returned value is 1 because "usign" is
returned. The value of usign is determined in "mpf_cmp" by the line:
usign = usize >= 0 ? 1 : -1;
I cannot explain that the string conversion function returns 0.08 twice but
that the compare function returns 1 and not 0. I downloaded the latest GNUmp
last week and I use Borland C++ builder v5 under Windows.
Regards,
Toine Bommelijn
www.trinc-prolog.com
- maybey an error in mpf_cmp,
Toine Bommelijn <=