Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange Errors

0 views
Skip to first unread message

lemonite

unread,
Dec 22, 2002, 9:50:19 AM12/22/02
to
Hi newsgroup,

the following test program causes me trouble under GCC-3.2.1 (Linux
2.4.19-gentoo-r9 #1 SMP i686 Intel(R) Pentium(R) 4 CPU 2.40GHz
GenuineIntel GNU/Linux gcc-3.2.1 glibc-2.3.1)

#include <stdio.h>
#include <math.h>

int main()
{
double x = 1.1;
double y;

printf("Calling modf() for %f\n", x);
printf("fractional part = %f\ninteger part = %f\n",
modf(x, &y), y);

return 0;
}

The expected output would be:

Calling modf() for 1.100000
fractional part = 0.100000
integer part = 1.000000

However I get:

$ gcc test.c -o test
$ ./test
Calling modf() for 1.100000
fractional part = 1.100000
integer part = -0.000000

which is obviously false (I get a similar wrong result with MinGW under Win2k).

Can anyone please help me with that issue? How can I locate the error? Is
is a bug with gcc-3.2.1? Thanks!

Kind regards,
lemonite


Rolf Magnus

unread,
Dec 22, 2002, 10:26:59 AM12/22/02
to
lemonite wrote:

Seems so, or maybe in the libc. It's working here with gcc 3.2. The
output is:

Wei Wang (weiwang1)

unread,
Dec 25, 2002, 5:13:52 PM12/25/02
to

The evaluation order of the function parameters is undefined.
It's better to do something like:

z = modf(x,&y);
printf("fractional part = %f\ninteger part = %f\n", z, y);

Wei


Rolf Magnus

unread,
Dec 25, 2002, 9:44:42 PM12/25/02
to
Wei Wang (weiwang1) wrote:

>> Seems so, or maybe in the libc. It's working here with gcc 3.2. The
>> output is:
>>
>> Calling modf() for 1.100000
>> fractional part = 0.100000
>> integer part = 1.000000
>>
>>
>
> The evaluation order of the function parameters is undefined.
> It's better to do something like:
>
> z = modf(x,&y);
> printf("fractional part = %f\ninteger part = %f\n", z, y);

Of course. I just overlooked that.

lemonite

unread,
Dec 27, 2002, 3:25:02 PM12/27/02
to

I forgot ;). However it does not 'solve' the problem.

Kind regards,
lemonite

0 new messages