This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: atof returns a value that is slightly greater than the original string


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]