www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/01/00:39:04

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problems with DJGPP V2.01 - atof() function
Date: Sat, 30 Nov 1996 20:37:12 -0800
Organization: Alcyone Systems
Lines: 24
Message-ID: <32A10B78.742AEEA5@alcyone.com>
References: <329e68a5 DOT 10316617 AT news DOT ua DOT pt> <57mtq1$4mo AT vidar DOT diku DOT dk>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Morten Welinder wrote:

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

-- 
                             Erik Max Francis | max AT alcyone DOT com
                              Alcyone Systems | http://www.alcyone.com/max/
                         San Jose, California | 37 20 07 N 121 53 38 W
                                 &tSftDotIotE | R^4: the 4th R is respect
         "But since when can wounded eyes see | If we weren't who we were"

- Raw text -


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