operators.cnj 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* More operators tests */
  2. /* Conjure >=3 only!!! */
  3. // assign ops
  4. int aplus(x, y)
  5. {
  6. int t = x;
  7. t += y;
  8. return t;
  9. }
  10. int aminus(x, y)
  11. {
  12. int t = x;
  13. t -= y;
  14. return t;
  15. }
  16. int ashl(x, y)
  17. {
  18. int t = x;
  19. t <<= y;
  20. return t;
  21. }
  22. int adiv(x, y)
  23. {
  24. int t = x;
  25. t /= y;
  26. return t;
  27. }
  28. int amult(x, y)
  29. {
  30. int t = x;
  31. t *= y;
  32. return t;
  33. }
  34. int amod(x, y)
  35. {
  36. int t = x;
  37. t %= y;
  38. return t;
  39. }
  40. int aor(x, y)
  41. {
  42. int t = x;
  43. t |= y;
  44. return t;
  45. }
  46. int aand(x, y)
  47. {
  48. int t = x;
  49. t &= y;
  50. return t;
  51. }
  52. int axor(x, y)
  53. {
  54. int t = x;
  55. t ^= y;
  56. return t;
  57. }
  58. int ashr(x, y)
  59. {
  60. int t = x;
  61. t >>= y;
  62. return t;
  63. }
  64. // binary ops
  65. int plus(x, y) { return x + y; }
  66. int minus(x, y) { return x - y; }
  67. int shl(x, y) { return x << y; }
  68. int div(x, y) { return x / y; }
  69. int mult(x, y) { return x * y; }
  70. int mod(x, y) { return x % y; }
  71. int or(x, y) { return x | y; }
  72. int and(x, y) { return x & y; }
  73. int xor(x, y) { return x ^ y; }
  74. int shr(x, y) { return x >> y; }
  75. int assign()
  76. {
  77. int a = aplus(2, 3); // 5
  78. int b = ashl(a, 2); // 20
  79. int c = aminus(b, 2); // 18
  80. int d = adiv(c, 2); // 9
  81. int e = amult(d, c); // 162
  82. int f = amod(e, 10); // 2
  83. int g = aor(f, 45); // 47
  84. int h = aand(g, 48); // 32
  85. int j = axor(h, h); // 0
  86. int k = aor(j, 65535); // 65535
  87. int l = ashr(k, 3); // 8191
  88. return l;
  89. }
  90. int binary()
  91. {
  92. int a = plus(2, 3); // 5
  93. int b = shl(a, 2); // 20
  94. int c = minus(b, 2); // 18
  95. int d = div(c, 2); // 9
  96. int e = mult(d, c); // 162
  97. int f = mod(e, 10); // 2
  98. int g = or(f, 45); // 47
  99. int h = and(g, 48); // 32
  100. int j = xor(h, h); // 0
  101. int k = or(j, 65535); // 65535
  102. int l = shr(k, 3); // 8191
  103. return l;
  104. }
  105. int zero() { return 0; }
  106. int unary()
  107. {
  108. int i = ~zero(); // -1
  109. int j = -i; // 1
  110. ++j; // 2
  111. ++++j; // 4
  112. --j; // 3
  113. return j;
  114. }
  115. int main()
  116. {
  117. return assign() + binary() + unary(); // 16385
  118. }