You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Though it has a very unintuitive interface, the "standard" strtod/strtof can detect the following errors:
fprintf(stderr, "%s: not a decimal number\n", buff); fprintf(stderr, "%s: extra characters at end of input: %s\n", buff, end); fprintf(stderr, "%s out of range of type double/float\n", buff);
How can I accomplish the same thing with StringToDoubleConverter ?
How can I detect all of those error cases (ideally separately, but how can I even detect that one of them has happened regardless of which one) while also using the "nan"/"inf" parsing feature?
It seems I can detect "extra characters" with
processed_characters_count < length
But what about overflow and other malformed string errors?
If I set junk_string_value/empty_string_value to NaN then I lose the useful feature of the routine by which it detects the "nan" string (I cannot tell if the string is a well-formed "nan" or whether the string contains malformed content that got mapped to junk_string_value/empty_string_value==NaN).
Is there a way to do this currently? If so, please add it to the dox in double-conversion.h. If not, can we add it?
Thanks
The text was updated successfully, but these errors were encountered:
A bit more info: I fed in a string with 2048 '9's (which should overflow doubles with 11 bits of mantissa) and after return from StringToDouble() I got length==processed_characters_count and a double of +Infinity.
So two things:
If this is the intended behavior for reporting overflow, it would be nice to document this in double-conversion.h
This still leads to the same dilemma as in the OP: how to detect overflow as opposed to a well-formed "Inf" in the string?
Currently it looks like I have to parse Inf and Nan outside of StringToDoubleConverter and then pass NULL for infinity_symbol and nan_symbol in order to get useful error checking. It sure would be nice not to have to do this.
Seems like the API needs to separate these two concepts rather than using the same channel to report both a valid parsing result and a parse error.
Thank you for making double-conversion!
Though it has a very unintuitive interface, the "standard" strtod/strtof can detect the following errors:
fprintf(stderr, "%s: not a decimal number\n", buff);
fprintf(stderr, "%s: extra characters at end of input: %s\n", buff, end);
fprintf(stderr, "%s out of range of type double/float\n", buff);
How can I accomplish the same thing with StringToDoubleConverter ?
How can I detect all of those error cases (ideally separately, but how can I even detect that one of them has happened regardless of which one) while also using the "nan"/"inf" parsing feature?
It seems I can detect "extra characters" with
processed_characters_count < length
But what about overflow and other malformed string errors?
If I set junk_string_value/empty_string_value to NaN then I lose the useful feature of the routine by which it detects the "nan" string (I cannot tell if the string is a well-formed "nan" or whether the string contains malformed content that got mapped to junk_string_value/empty_string_value==NaN).
Is there a way to do this currently? If so, please add it to the dox in double-conversion.h. If not, can we add it?
Thanks
The text was updated successfully, but these errors were encountered: