-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Closed
Closed
Copy link
Description
When parsing an f32, f64, etc., more special syntaxes for infinity and not-a-number should be expected:
fn f64_parse(text: &str){
match text.parse::<f64>(){
Some(v) => println!("Parsing {} yields {}", text, v),
None => println!("Parsing {} fails", text)
};
}
fn main(){
f64_parse("NaN");
f64_parse("nan");
f64_parse("NAN");
f64_parse("-nan");
f64_parse("inf");
f64_parse("INF");
f64_parse("infinity");
}
Result:
Parsing NaN yields NaN
Parsing nan fails
Parsing NAN fails
Parsing -nan fails
Parsing inf yields inf
Parsing INF fails
Parsing infinity fails
It is debatable whether the default parser should support all these syntaxes, but it would be very useful to have this functionality somewhere. Links:
The floating point conversion functions convert infinity to inf or
infinity. Which one is used is implementation defined.
Not-a-number is converted to nan or nan(char_sequence). Which one is
used is implementation defined.
The conversions F, E, G, A output INF, INFINITY, NAN instead.
I'm sure I've come across -nan (possibly different case) as well.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels