delorie.com/archives/browse.cgi | search |
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 |
To: | Marco Craveiro <soupdragon AT clix DOT pt> |
Cc: | cygwin AT cygwin DOT com |
Subject: | Re: atof returns a value that is slightly greater than the original string |
References: | <1000153353 DOT 1101 DOT 8 DOT camel AT darkroom> |
From: | Andrew Markebo <flognat AT flognat DOT myip DOT 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 |
/ Marco Craveiro <soupdragon AT clix DOT 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/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |