Mailing-List: contact cygwin-help@sourceware.cygnus.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@sources.redhat.com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin@sources.redhat.com>
List-Help: <mailto:cygwin-help@sources.redhat.com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner@sources.redhat.com
Delivered-To: mailing list cygwin@sources.redhat.com
To: Marco Craveiro <soupdragon@clix.pt>
Cc: cygwin@cygwin.com
Subject: Re: atof returns a value that is slightly greater than the original string
References: <1000153353.1101.8.camel@darkroom>
From: Andrew Markebo <flognat@flognat.myip.org>
Date: 10 Sep 2001 22:52:47 +0200
In-Reply-To: <1000153353.1101.8.camel@darkroom>
Message-ID: <m3heualqe8.fsf@localhost.localdomain>
Lines: 40
User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

/ Marco Craveiro <soupdragon@clix.pt> 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.
| 
| Google searching suggested that the problem was to do with #include
| <stdlib.h>, but I already have that #include in my program and I still
| get strange results. A program like this:
| 

Same problem here if I do:

#include <cstdlib>
#include <iostream>

int main (void)
{
float f=695.40;

cout << f;
}

my gdb says f is 695.400024

If my mind doesn't fail me completely this is a 'misfeature' in float,
the way that the data is stored in can't be exact.. or something..

The recommendations I have seen was to use some alternative
bignum/smallnum package :-) Or if you know how many decimals you can
get, multiply the value by that amount.. and convert to int.

The reason to why you don't see it on cout is that cout prints floats
with 1 or two decimals per default, if you tell it to print.. MANY
decimals.. 

        /Andy

-- 
 The eye of the beholder rests on the beauty!

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

