pragma solidity ^0.4.18;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
safemath.sol
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門昵时,熙熙樓的掌柜王于貴愁眉苦臉地迎上來捷雕,“玉大人,你說我怎么就攤上這事壹甥【认铮” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵句柠,是天一觀的道長浦译。 經(jīng)常有香客問我,道長溯职,這世上最難降的妖魔是什么精盅? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮谜酒,結(jié)果婚禮上叹俏,老公的妹妹穿的比我還像新娘。我一直安慰自己僻族,他們只是感情好粘驰,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著鹰贵,像睡著了一般晴氨。 火紅的嫁衣襯著肌膚如雪康嘉。 梳的紋絲不亂的頭發(fā)上碉输,一...
- 文/蒼蘭香墨 我猛地睜開眼众羡,長吁一口氣:“原來是場噩夢啊……” “哼侨赡!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布藐不,位于F島的核電站,受9級特大地震影響秦效,放射性物質(zhì)發(fā)生泄漏雏蛮。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一阱州、第九天 我趴在偏房一處隱蔽的房頂上張望挑秉。 院中可真熱鬧,春花似錦苔货、人聲如沸犀概。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽姻灶。三九已至,卻和暖如春诈茧,著一層夾襖步出監(jiān)牢的瞬間产喉,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 黑白的熒幕,倒映著兩個人的落寞唯蝶!無聲的影片尤莺,記錄著你我的過往! 我靜靜的坐在臺下生棍,想用一個觀眾的心態(tài)去回憶過去的點...