delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/09/10/19:29:30

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Subject: Re: atof returns a value that is slightly greater than the
original string
From: Marco Craveiro <soupdragon AT clix DOT pt>
To: cygwin AT cygwin DOT com
In-Reply-To: <3B9D2BF5.5060100@ece.gatech.edu>
References: <1000153353 DOT 1101 DOT 8 DOT camel AT darkroom>
<3B9D2BF5 DOT 5060100 AT ece DOT gatech DOT edu>
Message-Id: <1000163983.1092.28.camel@darkroom>
Mime-Version: 1.0
X-Mailer: Evolution/0.12 (Preview Release)
Date: 11 Sep 2001 00:27:35 +0100

On 10 Sep 2001 17:09:09 -0400, Charles Wilson wrote:
> Marco Craveiro wrote:
> 
> > Hello Cygwinners,
> > 
> > I'm having some strange problems with atof. basically, it returns a
> > converted value that is 0.000024 bigger than the one on the string.
> 
> 
> Welcome to the wonderful world of floating point representation.  This 
> type of error is quite common with floats -- because the float format is 
> intrinsically incapable of representing every real number with infinite 
> precision.  Unfortunately, that leads to "roundoff" errors that are a 
> bit non-intuitive, like your 0.000024.  (It's actually rounding off to a 
>   nice "round" number -- in the bitshifted, base-2, fixed-point notation 
> used for the mantissa in the float data format.  It just doesn't look 
> like a roundoff error when printed out in "normal" base-10 notation).
> 
> Workarounds: use a bigger float. (double?  long double?)  You'll still 
> have this sort of problem, but you'll only be off by 0.00000000000xx 
> instead of 0.000024.
> 
> Or used fixed-point math (e.g. what the previous poster suggested).
> 
> --Chuck
> 
> 
> 

Thanks everyone for the quality and quickness of the replies. I'm going
to find my notes on floating point representation. I knew I shouldn't
have missed those classes when I was back at uni :-)))

cheers!

marco


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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