majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Precision of doubles in output is only 6 digits (loses significant information) #69

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. double n = 2.0/3.0;
2. emitter << n;
3. parse result into double n2
4. (n - n2)/(n+n2)  >  1e-10

What is the expected output?
n2 should be much closer to n

What do you see instead?
n gets truncated to 6 digits when it is emitted as yaml.

What version of the product are you using? On what operating system?
0.2.5  on Ubuntu 9.10 with g++ (GCC) 4.1.3 20080704 (prerelease) (Ubuntu
4.1.2-27ubuntu1)

Please provide any additional information below.

Great library!.

I was just writing some test cases to confirm proper save/load operation
when I discovered significant precision loss on floating point numbers.

If I save an object containing doubles, and then load it into a copy
object, double members with lots of digits
differ by 1 part in a million or so (even though double precision can
express 15 decimal digits)

I think it would be a good idea to call str.precision(15) in
Emitter::WriteStreamable(T value).

I have modified the code as attached in my installation and it works
much better.

Original issue reported on code.google.com by stevemad...@gmail.com on 3 May 2010 at 9:56

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed, r453. Thanks for the report, and sorry for the (enormous) delay!

Original comment by jbe...@gmail.com on 3 Mar 2011 at 2:38