Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add sqrt for math #3242
Add sqrt for math #3242
Changes from 13 commits
8050d7d
74076e3
98e1358
25950fa
8d5d2d2
55a870d
270e8fc
71ac6df
fa2b258
27d025e
5dde1b8
1a5aee1
0218d35
c940f21
0b157fa
6e1ce42
6c138b2
beaf866
455fcea
abe47be
361fe6b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only the case for perfect squares, we should document the behavior for the other numbers. I suppose it rounds down.
Does it make sense (is it possible?) to provide a version with a
Rounding
argument?Do you think we can document some aspect of the efficiency of this function? It's O(1) but can we say anything stronger in terms of the constants involved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a version with Rounding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could provide an upper bound on the gas cost, I'm not sure what else we can say
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is clear or accurate.
What does it mean that we "use the log2"? I read this like saying that our guess is
log2(sqrt(a))
, but I don't think this is true.I also find the part about shifting
a
confusing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write this like this, otherwise we basically need to count
F
s to know if the code is right.The compiler seems to optimize this expression to a constant, even when optimizations are disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then what about doing
x >= 1 << 128
. Would that also get optimized? to the same bytecode. Because there is nogte
opcode I'm worried it would be compiled tonot(lt(..., ...))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I found an even better rewording.