rust-lang / rust-lang/rfcs

Parsing of floats should be more permissive with regards to NaN and +/- inf syntax

Open
#854 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Issue by dhardy
Monday Jan 26, 2015 at 11:04 GMT

For earlier discussion, see https://github.com/rust-lang/rust/issues/21652

This issue was labelled with: A-libs in the Rust repository


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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the earlier discussion in rust-lang/rust#21652 and the examples using text.parse::() as the starting point. Determine which NaN and infinity spellings are in scope, then use the listed sample inputs as the completion check; the issue names no implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.