[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
trouble with modf
From: |
Thomas Kähler |
Subject: |
trouble with modf |
Date: |
Fri, 24 Aug 2001 18:10:29 GMT |
Hej here,
I am using gcc version 2.95.2 19991024 (release) on an Intel-arch machine
with OS SuSe-Linux 7.1 (kernel 2.4.0) and have a problem with the
modf-function,
it seems to return an uncorrect value. I have written this little program
to test the function:
/*
* hugo.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char ** argv[])
{
double val, comp, predec, postdec;
/***********************************************/
val = comp = predec = postdec = 0.0;
val=122.170;
comp=0.70;
printf("val=%lf, predec=%lf, postdec= %lf, comp=%lf\n", val,
predec, postdec, comp);
postdec = modf(val*10, &predec);
if ( postdec == comp )
{
printf("gotcha!\n");
val += 0.005;
}
printf("val=%lf, predec=%lf, postdec= %lf, comp=%lf\n", val, predec,
postdec, comp);
printf("but:\n");
exit (0);
}
The printf-output shows no differerences between the values of comp and
postdec.
But then I copied the two variables by memcpy into a buffer and had a
look at the bytes:
comp showed: x66 x66 x66 x66 x66 x66 xFFFFFFE6 xEF
postdec showed: x00 x68 x66 x66 x66 x66 xFFFFFFE6 xEF
How this?
Am I too blind and made a mistake (special headerfile missing ? ) or is
there a bug in the modf-function?
Thanks in advance!
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- trouble with modf,
Thomas Kähler <=