www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/03/14:40:24

Newsgroups: comp.os.msdos.djgpp
From: design AT netcom DOT com (Chris Waters)
Subject: Re: Problems with DJGPP V2.01 - atof() function
Message-ID: <designE1uKsL.5n9@netcom.com>
Organization: Design and Delivery
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> <32A33C44 DOT 68FE AT exis DOT net>
Date: Tue, 3 Dec 1996 17:05:09 GMT
Lines: 14
Sender: design AT netcom23 DOT netcom DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <32A33C44 DOT 68FE AT exis DOT net>, Joe Wright  <wrightj AT exis DOT net> wrote:

>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.

Once again (for those who missed the answer the first time it was
posted): with (int)(f*100), the precision of the intermediate value
(f*100) must be at _least_ equal to the precision of a float; it may be
a double or long double.  To be exact, it's probably whatever size fits
in the FPU (80 bits).  When you assign it to a float first, it will be
converted to a size which fits in a float, an operation which involves
round-to-nearest.  The round-to-nearest-float is the difference.

- Raw text -


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