-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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 Function Math.abs
#2981
Comments
Hello @barakman and thank you for this request. I'm not puzzled about what the return type should be. On the one end returning For the record, I'm not sure you implementation would work with |
Thanks |
While it is true that abs will always return a positive value, I'm curious about actual use cases, and the fact that it might be used as part or signed arithmetic. I fear this might be seen as implicit casting and be confusing. Maybe that is just me. |
@Amxx: IMHO, function With regards to the specific example that you've given:
The correct thing to do would be:
Which will revert for TBH, for this specific example, I wouldn't even use
And you can overload that function with:
The first function will never revert, the second function will revert for |
Interresting, maybe, there is a case for adding both abs() and neg() into the Math library |
@barakman You should be able to fork the repository and open a pull request. Are you not authorized to do this? |
@frangio : That I haven't tried (not since v2.0.0 anyway). I'll give it a try... |
This should be closed PR was merged |
🧐 Motivation
A function which returns the absolute (and obviously unsigned) value of a signed value.
📝 Details
Here is the full work (as I am not authorized to post a Pull Request on your repository):
File
Math.sol
:File
MathMock.sol
:File
Math.test.js
:The text was updated successfully, but these errors were encountered: