www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/01/19:28:35

Message-ID: <32A23A40.4AEB@gbrmpa.gov.au>
Date: Mon, 02 Dec 1996 10:09:05 +0800
From: Leath Muller <leathm AT gbrmpa DOT gov DOT au>
Reply-To: leathm AT gbrmpa DOT gov DOT au
Organization: Great Barrier Reef Marine Park Authority
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Problems with DJGPP V2.01 - atof() function
References: <329e68a5 DOT 10316617 AT news DOT ua DOT pt> <57mtq1$4mo AT vidar DOT diku DOT dk> <32A10B78 DOT 742AEEA5 AT alcyone DOT com>

> > Getting 112 is well within the C standard.  If your program does
> > not work in this situation then you have a bug.
 
> The original response seems to be accurate.  atof("1.13")*100 gives you
> 112.9..., which a printf call will nicely round to 1.13 for you.  However,
> it is still less than 113 -- casting it to an int will round down, giving
> you 112.  Unfortunate, but a limitation of floating point calculations.
 
> I just checked this on my Pentium Pro 200 which runs gcc 2.7.2 under Linux,
> and got the same result.
 
> > Floating point numbers are not exactly represented; you will see
> > rounding errors.
 
> That's the problem exactly.

Eli, can this go in the FAQ??? The reason being that I think all this
mail has just solved one of my problems I am having at the moment. Good
timing too, I nearly threw the computer out the window last night!!! :)

Leathal.

- Raw text -


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