Skip to main content

Module number

Module number 

Source
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:

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 of parseIntWithRadix (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, calling digit with 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 of parseIntWithRadixDigits (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 — mirroring fastStrToDouble’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’s fast_float, so results are bit-identical.