arithmetic.carbon 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. package Core library "prelude/operators/arithmetic";
  5. // Addition: `a + b`.
  6. interface Add {
  7. fn Op[self: Self](other: Self) -> Self;
  8. }
  9. // Addition with assignment: `a += b`.
  10. interface AddAssign {
  11. fn Op[addr self: Self*](other: Self);
  12. }
  13. // Increment: `++a`.
  14. interface Inc {
  15. fn Op[addr self: Self*]();
  16. }
  17. // Negation: `-a`.
  18. interface Negate {
  19. fn Op[self: Self]() -> Self;
  20. }
  21. // Subtraction: `a - b`.
  22. interface Sub {
  23. fn Op[self: Self](other: Self) -> Self;
  24. }
  25. // Subtraction with assignment: `a -= b`.
  26. interface SubAssign {
  27. fn Op[addr self: Self*](other: Self);
  28. }
  29. // Decrement: `--a`.
  30. interface Dec {
  31. fn Op[addr self: Self*]();
  32. }
  33. // Multiplication: `a * b`.
  34. interface Mul {
  35. fn Op[self: Self](other: Self) -> Self;
  36. }
  37. // Multiplication with assignment: `a *= b`.
  38. interface MulAssign {
  39. fn Op[addr self: Self*](other: Self);
  40. }
  41. // Division: `a / b`.
  42. interface Div {
  43. fn Op[self: Self](other: Self) -> Self;
  44. }
  45. // Division with assignment: `a /= b`.
  46. interface DivAssign {
  47. fn Op[addr self: Self*](other: Self);
  48. }
  49. // Modulo: `a % b`.
  50. interface Mod {
  51. fn Op[self: Self](other: Self) -> Self;
  52. }
  53. // Modulo with assignment: `a %= b`.
  54. interface ModAssign {
  55. fn Op[addr self: Self*](other: Self);
  56. }