Rust: `f32::from_str` and `f64::from_str`: parser returned error on just a '.' (a dot)

Created on 1 Sep 2017  路  6Comments  路  Source: rust-lang/rust

Hi! I found a mismatch between documentation and behavior of stable Rust.
When I tried to parse a string equal "." f32/f64::from_str returned Err(...) instead of Ok(0.0), as it states in official documentation here.

Tests (based on mentioned doc)

f32: https://play.rust-lang.org/?gist=c7495df140e0991473fb914b0b468b34&version=stable
f64: https://play.rust-lang.org/?gist=c319d2f10762767b9983907cb9d7f2dc&version=stable

C-bug E-easy E-mentor T-doc

Most helpful comment

I'd like to work on this.

All 6 comments

This is a docs issue. The libs team decided in https://github.com/rust-lang/rust/issues/30344 to consider "." an invalid input instead of parsing it as 0.

I'd be happy to mentor anyone who wants to fix this, it'd be a great first bug!

I'd like to work on this.

@mcomstock are you fixing this?

Yeah! Sorry for the delay.

@mcomstock ok let me know if you need help

Was this page helpful?
0 / 5 - 0 ratings