pub fn parse_real(text: &str) -> Result<f64, RealParseFailReason> {
    //TODO @mark: make sure no leftover chars (no $ at the end)
    match REAL_RE.captures(text) {
        None => Err(RealParseFailReason::Invalid),
        Some(captures) => {
            if captures[0].len() < text.len() {
                // Part of `text` did not match the regex, so this input is invalid.
                return Err(RealParseFailReason::Invalid);
            }
            let multiplier = captures
                .name("multiplier")
                .unwrap()
                .as_str()
                .without_char('_')
                .parse::<f64>()
                .unwrap();
            match captures.name("exponent") {
                None => {
                    // This is a 'normal' real, no exponential notation
                    Ok(multiplier)
                }
                Some(exponent_match) => {
                    // This real is in exponential notation
                    let exponent = exponent_match.as_str().without_char('_').parse::<f64>().unwrap();
                    // TODO: is there a numerically smarter way to do this?
                    Ok(10f64.powf(exponent) * multiplier)
                }
            }
        }
    }
}
/// Convert a String that matches [real_pattern] to an f64 real. Overflow and loss of precision is possible.
Convert a String that matches [real_pattern] to an f64 real. Overflow and loss of precision is possible.
Convert a String that matches [ real_pattern ] to an f64 real . Overflow and loss of precision is possible .
pub fn parse_real(text: &str) -> Result<f64, RealParseFailReason> {
    //TODO @mark: make sure no leftover chars (no $ at the end)
    match REAL_RE.captures(text) {
        None => Err(RealParseFailReason::Invalid),
        Some(captures) => {
            if captures[0].len() < text.len() {
                // Part of `text` did not match the regex, so this input is invalid.
                return Err(RealParseFailReason::Invalid);
            }
            let multiplier = captures
                .name("multiplier")
                .unwrap()
                .as_str()
                .without_char('_')
                .parse::<f64>()
                .unwrap();
            match captures.name("exponent") {
                None => {
                    // This is a 'normal' real, no exponential notation
                    Ok(multiplier)
                }
                Some(exponent_match) => {
                    // This real is in exponential notation
                    let exponent = exponent_match.as_str().without_char('_').parse::<f64>().unwrap();
                    // TODO: is there a numerically smarter way to do this?
                    Ok(10f64.powf(exponent) * multiplier)
                }
            }
        }
    }
}
pub fn parse_real ( text : & str ) -> Result < f64 , RealParseFailReason > { //TODO @mark: make sure no leftover chars (no $ at the end) match REAL_RE . captures ( text ) { None => Err ( RealParseFailReason :: Invalid ) , Some ( captures ) => { if captures [ 0 ] . len ( ) < text . len ( ) { // Part of `text` did not match the regex, so this input is invalid. return Err ( RealParseFailReason :: Invalid ) ; } let multiplier = captures . name ( " " ) . unwrap ( ) . as_str ( ) . without_char ( '_' ) . parse :: < f64 > ( ) . unwrap ( ) ; match captures . name ( " " ) { None => { // This is a 'normal' real, no exponential notation Ok ( multiplier ) } Some ( exponent_match ) => { // This real is in exponential notation let exponent = exponent_match . as_str ( ) . without_char ( '_' ) . parse :: < f64 > ( ) . unwrap ( ) ; // TODO: is there a numerically smarter way to do this? Ok ( 10f64 . powf ( exponent ) * multiplier ) } } } } }
Convert a String that matches [real_pattern] to an f64 real.
Convert a String that matches [ real_pattern ] to an f64 real .
text
&str
text
&str