Skip to main content

nova_rt_str_to_float

Function nova_rt_str_to_float 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nova_rt_str_to_float( s: *const NovaStr, ) -> f64
Expand description

Parse decimal text as a Float.

Returns 0.0 for anything Rust’s parser rejects. That fallback is unreachable by construction: std/json’s scan_number validates the number’s lexical shape against JSON’s grammar — -?(0|[1-9][0-9]*) (\.[0-9]+)?([eE][+-]?[0-9]+)? — and only then slices the matched span and calls this, so every input is a text Rust’s f64 parser also accepts (its accepted grammar is a strict superset of JSON’s).

The fallback exists because this function must not panic. It is extern "C" with no -unwind, so a panic cannot unwind out of it: it escalates to panic in a function that cannot unwind and aborts the process. See nova_rt_float_fixed’s doc comment for the measured behaviour of that escalation. Hence unwrap_or, never unwrap.

§Safety

s must point to a valid NovaStr.