You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
535 B
29 lines
535 B
pragma solidity ^0.4.4;
|
|
|
|
|
|
/**
|
|
* Math operations with safety checks
|
|
*/
|
|
contract SafeMath {
|
|
function safeMul(uint a, uint b) internal returns (uint) {
|
|
uint c = a * b;
|
|
assert(a == 0 || c / a == b);
|
|
return c;
|
|
}
|
|
|
|
function safeSub(uint a, uint b) internal returns (uint) {
|
|
assert(b <= a);
|
|
return a - b;
|
|
}
|
|
|
|
function safeAdd(uint a, uint b) internal returns (uint) {
|
|
uint c = a + b;
|
|
assert(c>=a && c>=b);
|
|
return c;
|
|
}
|
|
|
|
function assert(bool assertion) internal {
|
|
if (!assertion) throw;
|
|
}
|
|
}
|
|
|
|
|