Skip to content

Commit ad51354

Browse files
authored
Rollup merge of #94838 - antonok-edm:float-parse-docs, r=Dylan-DPC
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.
2 parents 9e70b1a + 4c17217 commit ad51354

File tree

1 file changed

+8
-5
lines changed
  • library/core/src/num/dec2flt

1 file changed

+8
-5
lines changed

library/core/src/num/dec2flt/mod.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,24 @@ macro_rules! from_str_float_impl {
112112
/// * '2.5E-10'
113113
/// * '5.'
114114
/// * '.5', or, equivalently, '0.5'
115-
/// * 'inf', '-inf', 'NaN'
115+
/// * 'inf', '-inf', '+infinity', 'NaN'
116+
///
117+
/// Note that alphabetical characters are not case-sensitive.
116118
///
117119
/// Leading and trailing whitespace represent an error.
118120
///
119121
/// # Grammar
120122
///
121-
/// All strings that adhere to the following [EBNF] grammar
122-
/// will result in an [`Ok`] being returned:
123+
/// All strings that adhere to the following [EBNF] grammar when
124+
/// lowercased will result in an [`Ok`] being returned:
123125
///
124126
/// ```txt
125-
/// Float ::= Sign? ( 'inf' | 'NaN' | Number )
127+
/// Float ::= Sign? ( 'inf' | 'infinity' | 'nan' | Number )
126128
/// Number ::= ( Digit+ |
129+
/// '.' Digit* |
127130
/// Digit+ '.' Digit* |
128131
/// Digit* '.' Digit+ ) Exp?
129-
/// Exp ::= [eE] Sign? Digit+
132+
/// Exp ::= 'e' Sign? Digit+
130133
/// Sign ::= [+-]
131134
/// Digit ::= [0-9]
132135
/// ```

0 commit comments

Comments
 (0)