SignedSafeMath.sol 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. /**
  4. * @dev Wrappers over Solidity's arithmetic operations.
  5. *
  6. * NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler
  7. * now has built in overflow checking.
  8. */
  9. library SignedSafeMath {
  10. /**
  11. * @dev Returns the multiplication of two signed integers, reverting on
  12. * overflow.
  13. *
  14. * Counterpart to Solidity's `*` operator.
  15. *
  16. * Requirements:
  17. *
  18. * - Multiplication cannot overflow.
  19. */
  20. function mul(int256 a, int256 b) internal pure returns (int256) {
  21. return a * b;
  22. }
  23. /**
  24. * @dev Returns the integer division of two signed integers. Reverts on
  25. * division by zero. The result is rounded towards zero.
  26. *
  27. * Counterpart to Solidity's `/` operator.
  28. *
  29. * Requirements:
  30. *
  31. * - The divisor cannot be zero.
  32. */
  33. function div(int256 a, int256 b) internal pure returns (int256) {
  34. return a / b;
  35. }
  36. /**
  37. * @dev Returns the subtraction of two signed integers, reverting on
  38. * overflow.
  39. *
  40. * Counterpart to Solidity's `-` operator.
  41. *
  42. * Requirements:
  43. *
  44. * - Subtraction cannot overflow.
  45. */
  46. function sub(int256 a, int256 b) internal pure returns (int256) {
  47. return a - b;
  48. }
  49. /**
  50. * @dev Returns the addition of two signed integers, reverting on
  51. * overflow.
  52. *
  53. * Counterpart to Solidity's `+` operator.
  54. *
  55. * Requirements:
  56. *
  57. * - Addition cannot overflow.
  58. */
  59. function add(int256 a, int256 b) internal pure returns (int256) {
  60. return a + b;
  61. }
  62. }