Skip to content

Inexact results from str::float::from_str #7648

@SimonSapin

Description

@SimonSapin

Some inputs to std::float::from_str give a value that prints as an integer, but does not compare equal to it:

rusti> std::float::from_str("0.67e3").get()
670
rusti> std::float::from_str("0.67e3").get() == 670f
false
rusti> std::float::to_str_hex(670f)
~"29e"
rusti> std::float::to_str_hex(std::float::from_str("0.67e3").get())
~"29e.00000000002"

For comparison, Python does not have this issue:

>>> float('.67e3') == 670
True

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions