60-math.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <limits.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <mes/lib.h>
  24. int
  25. add (int a, int b)
  26. {
  27. return a + b;
  28. }
  29. int
  30. inc (int i)
  31. {
  32. return i + 1;
  33. }
  34. int
  35. main ()
  36. {
  37. int i;
  38. oputs ("\n");
  39. oputs ("t: 0 < 0\n");
  40. if (0 < 0)
  41. return 1;
  42. oputs ("t: 2 < 1\n");
  43. if (2 < 1)
  44. return 2;
  45. oputs ("t: -1 < -2\n");
  46. if (-1 < -2)
  47. return 3;
  48. oputs ("t: 0 < -1\n");
  49. if (0 < -1)
  50. return 4;
  51. oputs ("t: 0 > 0\n");
  52. if (0 > 0)
  53. return 5;
  54. oputs ("t: 1 > 2\n");
  55. if (1 > 2)
  56. return 6;
  57. oputs ("t: -2 > -1\n");
  58. if (-2 > -1)
  59. return 7;
  60. oputs ("t: -1 > 0\n");
  61. if (-1 > 0)
  62. return 9;
  63. oputs ("t: 1 == inc (0)\n");
  64. if (1 == inc (0))
  65. goto ok0;
  66. return 10;
  67. ok0:
  68. oputs ("t: 0 < inc (0)\n");
  69. if (0 < inc (0))
  70. goto ok1;
  71. return 11;
  72. ok1:
  73. oputs ("t: inc (0) + 2 != 3\n");
  74. if (inc (0) + inc (1) != 3)
  75. return 12;
  76. oputs ("t: 4/2=");
  77. i = 4 / 2;
  78. if (i != 2)
  79. return 13;
  80. i += 48;
  81. putchar (i);
  82. oputs ("\n");
  83. oputs ("t: 3*4=\n");
  84. i = 3 * 4;
  85. if (i != 12)
  86. return 14;
  87. oputs ("t: i /= 4\n");
  88. i /= 4;
  89. if (i != 3)
  90. return 15;
  91. oputs ("t: i *= 4\n");
  92. i *= 4;
  93. if (i != 12)
  94. return 16;
  95. oputs ("t: 1 << 3\n");
  96. if (1 << 3 != 8)
  97. return 1 << 3;
  98. oputs ("t: 3 << 4\n");
  99. if (3 << 4 != 48)
  100. return 3 << 4;
  101. oputs ("t: 48 >> 3\n");
  102. if (48 >> 4 != 3)
  103. return 48 >> 4;
  104. oputs ("t: 10 >> 1\n");
  105. if (10 >> 1 != 5)
  106. return 10 >> 1;
  107. oputs ("t: 1 | 4\n");
  108. if ((1 | 4) != 5)
  109. return 1 | 4;
  110. i = -3;
  111. oputs ("t: -i\n");
  112. if (-i != 3)
  113. return 22;
  114. oputs ("t: -1 + 2\n");
  115. if (-1 + 2 != 1)
  116. return 23;
  117. oputs ("t: 1 & 3\n");
  118. if ((1 & 3) != 1)
  119. return 24;
  120. oputs ("t: ~0\n");
  121. if (~0 != -1)
  122. return 25;
  123. oputs ("t: 1 | 3\n");
  124. if ((1 | 2) != 3)
  125. return 26;
  126. oputs ("t: ^ 1 \n");
  127. if ((1 ^ 3) != 2)
  128. return 27;
  129. oputs ("t: 3 == 3\n");
  130. if ((3 == 3) != 1)
  131. return 28;
  132. oputs ("t: 3 != 3\n");
  133. if ((3 != 3) != 0)
  134. return 29;
  135. oputs ("t: 011 == 15\n");
  136. if (011 != 9)
  137. return 30;
  138. oputs ("t: 0b11 == 3\n");
  139. if (0b11 != 3)
  140. return 31;
  141. oputs ("t: 0x11 == 3\n");
  142. if (0x11 != 17)
  143. return 32;
  144. oputs ("t: i = INT_MAX\n");
  145. i = INT_MAX;
  146. oputs ("t: i = 2147483646\n");
  147. i = 2147483646;
  148. oputs ("t: i++\n");
  149. i++;
  150. oputs ("t: i = INT_MIN\n");
  151. i = INT_MIN;
  152. oputs ("t: i = -2147483647\n");
  153. i = -2147483647;
  154. oputs ("t: i--\n");
  155. i--;
  156. return 0;
  157. }