Opened 9 years ago
Last modified 7 years ago
#9405 new Bugs
boost::spirit::karma::real_generator prints a number multiplied by 10
Reported by: | Owned by: | Hartmut Kaiser | |
---|---|---|---|
Milestone: | To Be Determined | Component: | spirit |
Version: | Boost 1.49.0 | Severity: | Problem |
Keywords: | Cc: |
Description
When using the attached example, the number 0.09999999999999987 is printed as 0.999999999999999, i.e. multiplied by 10.
Attachments (1)
Change History (3)
by , 9 years ago
Attachment: | spirit_karma_generator_bug.cxx added |
---|
comment:1 by , 9 years ago
Owner: | changed from | to
---|
comment:2 by , 7 years ago
I found the source of the issue, its this line here. The call to log10
rounds up to 15
instead of 14.9999...
.
Fixing the issue is tricky, at least for me since I don't know many floating point tricks. The ideas I have:
- Divide by 10 in a loop to simulate what the
int_inserter
is doing below - Have
int_inserter
write to a temporary stack buffer first (with output tracking), and then copy the stack buffer to the real one.- The stack buffer would be checked, and would error if it exceeded its bounds
- Remove the
+ 1
from this line.- Since the value no longer exceeds
digits10
, thelog10
function no longer rounds. - Doesn't seem portable or reliable, but I could be mistaken.
- Since the value no longer exceeds
Unfortunately I don't know of a way to reliably fix this without a performance impact. I can fix + add tests for this after some guidance.
Note:
See TracTickets
for help on using tickets.
Test that prints the number incorrectly