Skip to content

float::from_str and NaN/inf/-inf #2165

Closed

Description

@grahame

Should float::from_str do the following conversions?
"NaN" -> float::NaN
"inf" -> float::infinity
"-inf" -> float::neg_infinity

That'd match what float::to_str does (if my pull request #2164 is merged.)

If this sounds good I'll chuck a patch in.

Activity

  1. boggle commented on Apr 8, 2012

    @boggle
    Contributor

    It will be very good when this will be fixed. There are some additional points to be considered:

    If I remember correctly, the floating point standard allows for both short ("inf") and long ("infinity") syntax.

    Are you aware of the other float formatting related issues? I think there used to be a floating point literal parsing problem in rustc for very large literals (not fitting into 32 bits) that is related (can't find the issue right now).

    Besides adding support for NaN and inf in from_str/to_str, I personally think rust should define a literal syntax for these, i.e. the compiler should support them directly.

  2. brson commented on Apr 9, 2012

    @brson
    Contributor

    If this is standard behavior for converting from strings than I say go for it.

  3. boggle commented on Apr 9, 2012

    @boggle
    Contributor

    More things to check

    • proper handling of +0.0 vs -0.0 vs 0.0
    • hexadecimal notation for the mantissa for the lossless exchange of values
  4. boggle commented on Apr 10, 2012

    @boggle
    Contributor

    The last one is discusses in #1433. The real kicker would be if all this were supposed by the parser as literal syntax.

  5. ghost assigned on Apr 12, 2012
  6. brson commented on Apr 14, 2012

    @brson
    Contributor

    Fixed by 6b5731e

  7. added a commit that references this issue on Sep 22, 2022
  8. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: An issue proposing an enhancement or a PR with one.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions