www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/02/21:35:35

From: Joe Wright <wrightj AT exis DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problems with DJGPP V2.01 - atof() function
Date: Mon, 02 Dec 1996 15:29:56 -0500
Organization: Alpha Solutions
Lines: 31
Message-ID: <32A33C44.68FE@exis.net>
References: <329e68a5 DOT 10316617 AT news DOT ua DOT pt> <32A03F1D DOT 4967 AT pobox DOT oleane DOT com> <32a3151a DOT 978532 AT news DOT ox DOT ac DOT uk>
Reply-To: wrightj AT exis DOT net
NNTP-Posting-Host: ppp-2-33.exis.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

George Foot wrote:
> 
> On Sat, 30 Nov 1996 14:05:17 GMT, Francois Charton
> <deef AT pobox DOT oleane DOT com> wrote:
> 
> >float f;
> >int i,j;
> >i=(int) (1.13*100.0);
> >f=1.13*100.0;
> >j=(int) f;
> >printf("%d %d\n",i,j);
> >
> >
> >prints 112 113...
> >
> >And this is not because you don't have a FPU : I got a 486DX.
> >I'd say this is a parsing problem, with the way DJGPP represents
> >internally floating point numbers :
> 
> I don't think this is quite correct... It's not a parsing problem, and
> it's not DJGPP's (or gcc's) fault. I think it's more a problem with
> converting binary floating point into decimal, combined with a lack of
> understanding of the cast from float to int.
> 

Not so fast.  Before the answer, we have the real question:  Not why is
the result 'wrong' but why are they different?  Why does i=(int)(f*100);
yield a different result than f=f*100; i=(int)f; ?  Why?  Clearly the
compiler is doing conversions differently in the two cases.

Joe

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019