public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Int cast / floating point isuses
@ 2004-07-23 19:14 Joe Hughes
  2004-07-24 12:00 ` Brian Gough
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Hughes @ 2004-07-23 19:14 UTC (permalink / raw)
  To: gcc-help

I've been doing some work with floating point numbers and stumbled across
some peculiar results and I'm not sure where to go from here.

The code below generates this output on RedHat 2.1 ix86 using g++ 2.96,
3.2 & 3.41
original -79.937384
int cast: -79937383
lrint: -79937384
trunc: -79937384

Using g++ 3.2 on MacOSX, and g++ 2.96 on Solaris 2.7 and g++ 3.2 on 
Solaris 2.8 as well as .net studio on windows xp all return -79937384 
for int cast.

I'm stumped as to what is causing this error to occur for int cast,
especially when lrint and trunc seem to work properly.

Any insight anyone has would be much appreciated.

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

int main(int argc, char *argv[])
{
     int iTmp = 0;
     double dTmp =-79.937384;

     printf("original %.6f\n",dTmp);

     iTmp = (int)(dTmp * 1000000.0);
     printf("int cast: %d\n",iTmp);

     iTmp = llrint(dTmp * 1000000.0);
     printf("lrint: %d\n",iTmp);

     iTmp = trunc(dTmp * 1000000.0);
     printf("trunc: %d\n\n",iTmp);
}//end int main(int argc, char *argv[])

Joe

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-07-26 20:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-23 19:14 Int cast / floating point isuses Joe Hughes
2004-07-24 12:00 ` Brian Gough
2004-07-25  0:33   ` joe
2004-07-25 10:00     ` Brian Gough
2004-07-26 20:02       ` Joe Hughes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).