Expand description
Numeric-literal conversion primitives for the JS lexer, ported from
include/hermes/Support/Conversions.h. The decimal/real path uses Rust std’s
correctly-rounded str::parse::<f64>() (the same fast_float algorithm the
C++ lexer uses) — no FFI, no third-party crate.
Public API:
parse_int_with_radix_digits— digit-by-digit radix parser (callback style).parse_int_with_radix— full integer-radix parse with power-of-2 rounding path.str_to_double— decimal/real path: pure-Rust, bit-identical tofastStrToDouble.
Functions§
- parse_
int_ with_ radix - Takes a non-empty string (without the leading “0x” if hex) and parses it
as radix
radix.allow_sep: when true, allow ‘_’ as a separator and ignore it when parsing. Returns the f64 that results on success, or None on error. Port ofparseIntWithRadix(Conversions.h:204), including the >2^53 power-of-two bit-by-bit rounding path (lines 222–328). - parse_
int_ with_ radix_ digits - Takes a non-empty string (without the leading “0x” if hex) and parses it
as radix
radix, callingdigitwith the value of each digit, going from left to right.allow_sep: when true, allow ‘_’ as a separator and ignore it when parsing. Returns true if the string was successfully parsed, false otherwise. Port ofparseIntWithRadixDigits(Conversions.h:166). - str_
to_ double - Parse a cleaned decimal/real numeric buffer (only
[0-9.eE+-], separators already stripped) to an f64. Returns the value if the WHOLE buffer parses, or None on invalid input — mirroringfastStrToDouble’s “consume all or fail” contract. Out-of-range inputs parse to +/-inf or 0.0 (as fast_float and Rust std both do). Rust std’s parser is the same correctly-rounded algorithm as the lexer’sfast_float, so results are bit-identical.