SignedSafeMath.sol 1.7 KB

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