-
Notifications
You must be signed in to change notification settings - Fork 393
solidity: std math library #50
base: master
Are you sure you want to change the base?
Conversation
Can you combine than with the other math library? And perhaps we could use this sqrt function:
|
I can absolutely change the sqrt function, but what do you mean by combine with the other math library? |
@@ -8,4 +9,167 @@ library Math { | |||
x = mulmod(x, x, m); | |||
} | |||
} | |||
|
|||
/// @dev unsigned constant infinity (largest number possible) | |||
function Infinity() constant returns (uint inf) { |
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 does not really behave as "infinity". What about uint_max
? (also applies to the others)
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.
After taking some time to understand how Infinity works in other languages, I think I'd agree here. Perhaps this fits better trying to make a global object in Solidity itself? Just shooting out ideas. Either way, point taken and I will update accordingly.
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.
Right, we might allow access to constant public variables at some point.
I would like to include an example on the homestead site that uses a square root and to do it properly I'd love to include it as an example of importing a library. Can we merge and deploy this to the live net? |
Also I'm curious about how this can calculate a square root, it's fascinating..
edit: Found it. This is awesome! |
function sqrt(uint256 x) public pure returns (uint256 y) {
uint256 z = (x + 1) / 2;
y = x;
while (z < y) {
y = z;
z = (x / z + z) / 2;
}
return y;
} |
I've included a lot of basic functions...binomial is one that I'm currently trying to figure out but not being able to utilize a 2D array makes this more difficult.