-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<charconv>: from_chars, incorrect conversion of tiny doubles, when specified without a fractional part #3161
Comments
In brief the code discards the trailing 1, and rounds down, rather than up. |
Thanks for the bug report! I'll investigate (this might be similar to issues we've previously fixed, but I'm not sure yet). |
Stephan, this is different than the bug I previously reported, and you fixed. I checked the code on top of tree, and it appears to still be incorrect there. However, I didn't test TOT either, because I am not sure how to point Visual Studio to use the code here, instead of the installed version. |
This looks like #3375 to me. I guess the method suggested by @statementreply (#3375 (comment)) works.
|
I believe that this is unnecessary. |
I have found a large number of values that do not convert correctly in MSVC's implementation. I compared these inputs to other implementations such as strtod in GLIBC and David Gay's strtod. These other implementations correctly parse in these cases. Here is an example of a case MSVC's
from_chars
fails:This value is only slightly larger than an exact round point. However the way I have constructed the number confuses the code in charconv. Notably, it processes the entire number in the "Scan the integer part of the mantissa" phase of the code. This part of the code never sets
_Has_zero_tail
. Then the code breaks out of the "Scan the fractional part of the mantissa" loop on the first iteration due to,if (_Digit_value >= _Base)
, never setting _Has_zero_tail.My naive fix of adding the
else _Has_zero_tail = _Has_zero_tail && _Digit_value == 0;
to the integer part as well, seems to work.The text was updated successfully, but these errors were encountered: