atof returns a value that is slightly greater than the originalstring
Marco Craveiro
soupdragon@clix.pt
Mon Sep 10 13:35:00 GMT 2001
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:
#include <cstdlib>
#include <iostream>
int main (void)
{
float f = atof ("695.40");
cout << f;
}
compiles and outpus nicelly:
$ ./main
695.4
but if i debug it, its actually not correct:
(gdb) b 6
Breakpoint 1 at 0x80485f6: file main.cpp, line 6.
(gdb) r
Starting program: /home/phase/work/src/a.out
Breakpoint 1, main () at main.cpp:6
(gdb) p f
$1 = 3.99009619e-34 ----> before assignment
(gdb) n
(gdb) p f
$2 = 695.400024 ----> after assignment
(gdb)
since I need this the data to generate a sum, the sum ends up a bit off
because of this. and unfortunatelly, because there is so many people
with the #include problem, its impossible to search the web properly.
I'm sure its something i'm doing (or not doing), just can't see what...
A cygcheck is attached.
Many thanks for your time.
marco.
More information about the Cygwin
mailing list