merkaliser / scilla-vanilla

MIT License
20 stars 6 forks source link

math contract more functions #9

Closed iamjaspreetsingh closed 6 years ago

iamjaspreetsingh commented 6 years ago

A few more transitions like max, min and average needs to be added in maths contract.

https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/Math.sol

vaibhavchellani commented 6 years ago

@iamjaspreetsingh can we close this or are there more functions to be made ?

iamjaspreetsingh commented 6 years ago

@vaibhavchellani the functions are completed but I am getting doubt in one of the function i.e. Average. In reference to https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/Math.sol#L18

I need to use the formula (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2) to avoid overflow. Using this generates a runtime error. I can't use mod function directly. Can it be the reason? (At present for mod I replace and calculate it by divide, multiply and subtract.)

vaibhavchellani commented 6 years ago

as per suggestions from gitter group , we should remove integer operations as those can be handled safely by scilla , we should however implement functions like average , GCD , LCD etc as a library like this .