Skip to content

Support float(<str>) and float(<bytes>) #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2019

Conversation

OddCoincidence
Copy link
Contributor

NOTE: instead of using rust's f64::from_str, I used the lexical crate, whose flexibility more closely matches Python's float parsing (e.g. it correctly supports all the variations in the test case of this PR, while the former does not). As a nice bonus, it's 4000x faster. You can read more about it here.

@windelbouwman
Copy link
Contributor

Very cool! Maybe another idea, instead of lexical, use the rustpython_parser.lexer to lex the float. Then the behavior is the same between floating point literals and the float function. This also makes the binary smaller since we use only one lexical scanner. What do you think?

@OddCoincidence
Copy link
Contributor Author

Yeah, increasing the binary size would be unfortunate - I'd just like to see the float parsing performance be competitive with cpython and I'm not sure reusing the lexer/parser will allow that. 🤔

@windelbouwman
Copy link
Contributor

I would not worry too much about performance right now, but should the behavior be actually the same? Anyways, the work looks good! I will merge it.

@windelbouwman windelbouwman merged commit de98ac6 into RustPython:master Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants