You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No idea, parsing floats is non-trivial. considering Java, PHP &c. have had severe DOS issues related to parsing floats, I think we should just borrow known-good code.
Yeah the current implementation just uses an very naive approach for float parsing and emitting.
The problem is that doing it proper is both hard and slow. To get an optimum result for parsing/printing a float from/to a base-n string representation requires bignum fractionals. (where optimum == "shortest unambigious string representation in base n" in a roundtrip float -> string -> float)
There exist algorithms specifically tailored to base 10 that can get around that by only requiring bignum ints, or even regular fixed sized integers, and working with bases 2, 4, 8, 16 and 32 is trivial, so I guess we'd ultimately want to incorporate all those techniqes by having different code paths to take, depending on input and base.
It would be nice to fix this. I haven't looked at the rust implementation in strconv.rs yet. But I believe that Will Clinger's paper from PLDI 1990 is a pretty common reference for this, see
Activity
SimonSapin commentedon Jul 8, 2013
As jensnockert points out on IRC,
0.67e3should parse to an integer float, so29e.00000000002is definitely wrong.auroranockert commentedon Jul 8, 2013
It should be exactly equal, since 670.0 is exactly representable in IEEE 754. #7030 is probably the same issue.
Ps. Even with a float RHS, Python gives the correct answer
krdln commentedon Jul 8, 2013
This line is responsible, I think.
https://github.com/mozilla/rust/blob/master/src/libstd/num/strconv.rs#L588
Maybe calculation of exponential part should be before fraction calculation?
auroranockert commentedon Jul 8, 2013
No idea, parsing floats is non-trivial. considering Java, PHP &c. have had severe DOS issues related to parsing floats, I think we should just borrow known-good code.
Kimundi commentedon Jul 8, 2013
Yeah the current implementation just uses an very naive approach for float parsing and emitting.
The problem is that doing it proper is both hard and slow. To get an optimum result for parsing/printing a float from/to a base-n string representation requires bignum fractionals. (where optimum == "shortest unambigious string representation in base n" in a roundtrip float -> string -> float)
There exist algorithms specifically tailored to base 10 that can get around that by only requiring bignum ints, or even regular fixed sized integers, and working with bases 2, 4, 8, 16 and 32 is trivial, so I guess we'd ultimately want to incorporate all those techniqes by having different code paths to take, depending on input and base.
pnkfelix commentedon Aug 29, 2013
visiting for bug triage, email from 2013-08-26.
It would be nice to fix this. I haven't looked at the rust implementation in
strconv.rsyet. But I believe that Will Clinger's paper from PLDI 1990 is a pretty common reference for this, seeAnd yes, I think these algorithms are specially tailored to base 10, as Kimundi noted.
emberian commentedon Jan 1, 2014
Triage. This is still a problem. The papers pnkfelix links look really nice.
huonw commentedon Jan 1, 2014
cc #6220
pnkfelix commentedon Oct 28, 2014
This needs to be properly triaged.
Nominating (I suspect it will be flagged as merely P-high, as that was what was done with #7030).
pnkfelix commentedon Nov 6, 2014
Assigning P-high, not 1.0.
IvanUkhov commentedon Nov 12, 2014
Hello,
From a discussion on the
#rustIRC channel today:So, the implementations of string parsing in the compiler and in
from_strdiffer. It seems many people find this inconsistency rather confusing.Regards,
Ivan
huonw commentedon May 31, 2015
Closing as a forward-dupe of #24557, since that issue has more info.
Merge rust-lang#7638 rust-lang#7648