strtod
A general-purpose function in the C standard library (<stdlib.h>) that parses a string into a double. It must handle edge cases including signs, whitespace, decimal and scientific notation, inf/nan, and localized decimal points, following the C standard and IEEE 754 rounding requirements.
Timeline (last 90 days)
In the initial implementation, the parse_number performance of the Rust extension was actually faster than the C extension, because the parsing function in the Rust standard library equivalent to C's strtod is about twice as fast as strtod.
The custom C parser reduced decimal parsing from 106 ns to 18 ns, because the input domain of parse_number was narrowed (it only needs to strip currency symbols, thousands separators, and percent signs), allowing it to skip the branching and validation overhead that strtod pays for generality.
The C standard library provides the strtod, strtof, and strtold functions to perform string-to-floating-point conversion.
According to the standard, strtod should set errno to ERANGE when the conversion result overflows or underflows.
The endptr parameter points to the position where conversion stopped; if it equals the starting position of the input string, it indicates that no characters were successfully converted.
All Facts (5)
In the initial implementation, the parse_number performance of the Rust extension was actually faster than the C extension, because the parsing function in the Rust standard library equivalent to C's strtod is about twice as fast as strtod.
50%UnverifiedThe custom C parser reduced decimal parsing from 106 ns to 18 ns, because the input domain of parse_number was narrowed (it only needs to strip currency symbols, thousands separators, and percent signs), allowing it to skip the branching and validation overhead that strtod pays for generality.
50%UnverifiedThe C standard library provides the strtod, strtof, and strtold functions to perform string-to-floating-point conversion.
50%UnverifiedAccording to the standard, strtod should set errno to ERANGE when the conversion result overflows or underflows.
50%UnverifiedThe endptr parameter points to the position where conversion stopped; if it equals the starting position of the input string, it indicates that no characters were successfully converted.
50%