Skip to content

Commit

Permalink
Rollup merge of #94838 - antonok-edm:float-parse-docs, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Make float parsing docs more comprehensive

I was working on some code with some specialized restrictions on float parsing. I noticed the doc comments for `f32::from_str` and `f64::from_str` were missing several cases of valid inputs that are otherwise difficult to discover without looking at source code.

I'm not sure if the doc comments were initially intended to contain a comprehensive description of valid inputs, but I figured it's useful to include these extra cases for reference.
  • Loading branch information
Dylan-DPC committed Mar 11, 2022
2 parents 9e70b1a + 4c17217 commit ad51354
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions library/core/src/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,24 @@ macro_rules! from_str_float_impl {
/// * '2.5E-10'
/// * '5.'
/// * '.5', or, equivalently, '0.5'
/// * 'inf', '-inf', 'NaN'
/// * 'inf', '-inf', '+infinity', 'NaN'
///
/// Note that alphabetical characters are not case-sensitive.
///
/// Leading and trailing whitespace represent an error.
///
/// # Grammar
///
/// All strings that adhere to the following [EBNF] grammar
/// will result in an [`Ok`] being returned:
/// All strings that adhere to the following [EBNF] grammar when
/// lowercased will result in an [`Ok`] being returned:
///
/// ```txt
/// Float ::= Sign? ( 'inf' | 'NaN' | Number )
/// Float ::= Sign? ( 'inf' | 'infinity' | 'nan' | Number )
/// Number ::= ( Digit+ |
/// '.' Digit* |
/// Digit+ '.' Digit* |
/// Digit* '.' Digit+ ) Exp?
/// Exp ::= [eE] Sign? Digit+
/// Exp ::= 'e' Sign? Digit+
/// Sign ::= [+-]
/// Digit ::= [0-9]
/// ```
Expand Down

0 comments on commit ad51354

Please sign in to comment.