Skip to content
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

Feature: Allow scientific notation for literals #1721

Merged
merged 7 commits into from Dec 6, 2019

Conversation

fubuloubu
Copy link
Member

@fubuloubu fubuloubu commented Nov 12, 2019

What I did

Actual solution to #1680, allowing scientific notation literals (e.g. 3e6, 1e-10) to be used in vyper programs.
See: https://python-reference.readthedocs.io/en/latest/docs/float/scientific.html

Work remaining

  • Need to work out semantics. Does a positive exponent get translated to an integer literal, or remain a decimal? Should it always be parsed a decimal? Parsing as a decimal always works
  • Needs significant test cases to prove equivalency of constant expressions to their runtime equivalent (avoid issues like #1693) Increased precision in fde6d2b avoids floating point issues

Description for the changelog

Added support for decimal literals using scientific notation

Cute Animal Picture

Hamster

@fubuloubu fubuloubu added the work in progress label Nov 12, 2019
@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch 3 times, most recently from b4b35b1 to f5473ad Compare Nov 12, 2019
@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch 3 times, most recently from 9376f9b to 94b01e3 Compare Nov 21, 2019
@fubuloubu
Copy link
Member Author

@fubuloubu fubuloubu commented Nov 21, 2019

Note: 3 of the failures are from #1681, looks like a few others are falling out due to something about using Decimal. The raw conversion cases look problematic however.

@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch from 98925b7 to 7a15883 Compare Nov 21, 2019
vyper/parser/parser_utils.py Outdated Show resolved Hide resolved
@charles-cooper
Copy link
Collaborator

@charles-cooper charles-cooper commented Nov 27, 2019

So I took a look at the failing tests and it looks like this PR is somehow picking up bad literals that were previously passing. Which I think is a good thing. I want to look at each one of them in more detail though.

@fubuloubu
Copy link
Member Author

@fubuloubu fubuloubu commented Nov 27, 2019

Yeah, my thoughts exactly. It seems like there was some fallout of this change, which is good we're catching it now. I'll fix the lint issue.

@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch 3 times, most recently from 216d6bb to 602e949 Compare Nov 29, 2019
@fubuloubu
Copy link
Member Author

@fubuloubu fubuloubu commented Nov 29, 2019

I think I'm getting this tracked down... looks like the following phrase could be the cause?

"Substituting negative values for unary subtractions"

Perhaps on this substitution, there is something about constants where the unary substraction isn't being respected, ergo constant folding ignores the negative sign.

@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch from 602e949 to 1e35e6f Compare Nov 29, 2019
@fubuloubu fubuloubu mentioned this pull request Nov 29, 2019
@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch 2 times, most recently from 2fa2bfe to 03bf59c Compare Nov 29, 2019
@fubuloubu
Copy link
Member Author

@fubuloubu fubuloubu commented Nov 29, 2019

G2G once #1741 is merged (will rebase then)

@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch from 03bf59c to 91c3a15 Compare Nov 29, 2019
@fubuloubu
Copy link
Member Author

@fubuloubu fubuloubu commented Nov 29, 2019

Actually, scratch that... missing test cases!

@fubuloubu
Copy link
Member Author

@fubuloubu fubuloubu commented Dec 2, 2019

Waiting for 2 reviews

fubuloubu added 4 commits Dec 4, 2019
Note: when using literals, it used to be acceptable to have >10
      decimal places, giving the false impression that you could
      specify a decimal literal as having >10 decimal places. It
      would silently drop the extra digits in that case.

Note: changed test case to gwei from szabo to "fix" the new
      conversion error
@fubuloubu fubuloubu force-pushed the feat-scientific-notation branch from 623e2dd to 96ef9f9 Compare Dec 4, 2019
@fubuloubu fubuloubu removed the work in progress label Dec 4, 2019
@fubuloubu
Copy link
Member Author

@fubuloubu fubuloubu commented Dec 4, 2019

Whoops, forgot to remove the WIP label. Ready for review!

Copy link
Collaborator

@charles-cooper charles-cooper left a comment

I'm pretty happy with this. Thanks!

Copy link
Contributor

@jacqueswww jacqueswww left a comment

LGTM

@fubuloubu fubuloubu merged commit 609c339 into vyperlang:master Dec 6, 2019
5 checks passed
@fubuloubu fubuloubu deleted the feat-scientific-notation branch Dec 6, 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.

None yet

3 participants