Opened 8 years ago

Last modified 8 years ago

#10188 assigned Bugs

Loses floating point precision on round trip

Reported by: Magne OEstlyngen <magne+boost@…> Owned by: Sebastian Redl
Milestone: To Be Determined Component: property_tree
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

ptrees stream_translator uses a precision of std::numeric_limits<F>::digits10 + 1 when converting floating point values. This is not always enough, and a more correct value would be digits10+2 or max_digits10 (c++11 only). See ticket:9177 for a similar issue.

The attached test produces the following output pre-patch:

in : -1.8312345000098765e-08
out: -1.8312345000098762e-08
Wrong

and after patch:

in : -1.8312345000098765e-08
out: -1.8312345000098765e-08
Right

Attachments (2)

test.cpp (499 bytes ) - added by Magne OEstlyngen <magne+boost@…> 8 years ago.
Test-case showing the problem
ptree_precision.patch (629 bytes ) - added by Magne OEstlyngen <magne+boost@…> 8 years ago.
Patch fixing the problem

Download all attachments as: .zip

Change History (3)

by Magne OEstlyngen <magne+boost@…>, 8 years ago

Attachment: test.cpp added

Test-case showing the problem

by Magne OEstlyngen <magne+boost@…>, 8 years ago

Attachment: ptree_precision.patch added

Patch fixing the problem

comment:1 by Sebastian Redl, 8 years ago

Status: newassigned

Fixed on develop by commit #4034703.

Note: See TracTickets for help on using tickets.