google / google/double-conversion
StringToDoubleConverter: how to detect error AND use nan/inf detection?
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 308
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 12
Description
Thank you for making double-conversion!
Though it has a [very unintuitive interface](https://www.securecoding.cert.org/confluence/display/c/ERR34-C.+Detect+errors+when+converting+a+string+to+a+number), 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
Contributor guide
Assessment
This issue has not been assessed yet.