0

Im trying to find a cheap solution in Solidity where a uint256 type caluclation for 1000-1001 results 0. I know that i run into overflow problems here and cant use Safemath.

2

What about this?

pragma solidity 0.4.25;

contract Subtract {

    function subtract(uint a, uint b) public pure returns(uint remainder) {
        if(b>a) return 0;
        return b-a;
    }
}

Hope it helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.