Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spirit::karma::generate generates 10.0e-04, but expecting 1.0e-03 #628

Closed
markusjrmueller opened this issue Nov 20, 2020 · 3 comments · Fixed by #629
Closed

spirit::karma::generate generates 10.0e-04, but expecting 1.0e-03 #628

markusjrmueller opened this issue Nov 20, 2020 · 3 comments · Fixed by #629

Comments

@markusjrmueller
Copy link

markusjrmueller commented Nov 20, 2020

Code is:

std::string s;
double value = 0.00099999999999999829;
std::back_insert_iterator<std::string> sink(s);
boost::spirit::karma::generate(sink, boost::spirit::karma::real_generator<>(), value);
std::cout << s << std::endl; // outputs 10.0e-04
@markusjrmueller markusjrmueller changed the title spirit::karma::generate generates 10.0e-4, but expecting 1.0e-3 spirit::karma::generate generates 10.0e-04, but expecting 1.0e-03 Nov 20, 2020
@hkaiser
Copy link
Collaborator

hkaiser commented Nov 20, 2020

The 64 bit IEEE floating point format supports only up to 15.9 digits of precision (see https://en.wikipedia.org/wiki/Double-precision_floating-point_format). The number you are trying to convert requires at least 17 digits in order to be represented. The behavior of the generator is undefined in those cases. Please see #529 for more details.

@markusjrmueller
Copy link
Author

markusjrmueller commented Nov 21, 2020

I am using MSCV from visual studio 2017 in 64bit. The value comes out when doing some math. They claim to be IEEE conform when not compiling with the compiler flag /fast. At the moment I use the precise-flag.
I did tests with a precision of 6 and even changed the code according to #529 but nothing changes.
I do not know what I can do to fix this issue when using karma.

@hkaiser
Copy link
Collaborator

hkaiser commented Nov 21, 2020

@markusjrmueller please see #629 for a possible fix. Please let us know if this resolves your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants