fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. #include <inttypes.h>
  5.  
  6. uint32_t multiply (uint16_t a, uint16_t b)
  7. {
  8. //uint16_t mask = 0b0000000000000001;
  9.  
  10. register uint32_t result = 0;
  11.  
  12. result += (a & ( (int16_t)( ( b & (1 << 0) ) << 15 ) ) / ( 1 << 15) ) << 0;
  13.  
  14.  
  15. result += (a & ( (int16_t)( ( b & (1 << 1) ) << 14 ) ) / ( 1 << 15) ) << 1;
  16.  
  17.  
  18. result += (a & ( (int16_t)( ( b & (1 << 2) ) << 13 ) ) / ( 1 << 15) ) << 2;
  19.  
  20.  
  21. result += (a & ( (int16_t)( ( b & (1 << 3) ) << 12 ) ) / ( 1 << 15) ) << 3;
  22.  
  23.  
  24. result += (a & ( (int16_t)( ( b & (1 << 4) ) << 11 ) ) / ( 1 << 15) ) << 4;
  25.  
  26.  
  27. result += (a & ( (int16_t)( ( b & (1 << 5) ) << 10 ) ) / ( 1 << 15) ) << 5;
  28.  
  29.  
  30. result += (a & ( (int16_t)( ( b & (1 << 6) ) << 9 ) ) / ( 1 << 15) ) << 6;
  31.  
  32.  
  33. result += (a & ( (int16_t)( ( b & (1 << 7) ) << 8 ) ) / ( 1 << 15) ) << 7;
  34.  
  35.  
  36. result += (a & ( (int16_t)( ( b & (1 << 8) ) << 7 ) ) / ( 1 << 15) ) << 8;
  37.  
  38.  
  39. result += (a & ( (int16_t)( ( b & (1 << 9) ) << 6 ) ) / ( 1 << 15) ) << 9;
  40.  
  41.  
  42. result += (a & ( (int16_t)( ( b & (1 <<10) ) << 5 ) ) / ( 1 << 15) ) << 10;
  43.  
  44.  
  45. result += (a & ( (int16_t)( ( b & (1 <<11) ) << 4 ) ) / ( 1 << 15) ) << 11;
  46.  
  47.  
  48. result += (a & ( (int16_t)( ( b & (1 <<12) ) << 3 ) ) / ( 1 << 15) ) << 12;
  49.  
  50.  
  51. result += (a & ( (int16_t)( ( b & (1 <<13) ) << 2 ) ) / ( 1 << 15) ) << 13;
  52.  
  53.  
  54. result += (a & ( (int16_t)( ( b & (1 <<14) ) << 1 ) ) / ( 1 << 15) ) << 14;
  55.  
  56.  
  57. result += (a & ( (int16_t)( ( b & (1 <<15) ) << 0 ) ) / ( 1 << 15) ) << 15;
  58. return result;
  59. }
  60.  
  61. int main(void)
  62. {
  63.  
  64. uint16_t a, b;
  65. a = 0;
  66. b = 0;
  67.  
  68. do
  69. {
  70. if (multiply(a, b) != a * b)
  71.  
  72.  
  73. fprintf(stderr,
  74. "ERROR:\n"
  75. "my: %u\n"
  76. "norm: %u\n"
  77. "%hu * %hu\n"
  78. "\n",
  79. multiply(a, b), (a * b),a, b
  80. );
  81.  
  82. if (UINT16_MAX == a)
  83. {
  84. b++;
  85. }
  86. a++;
  87. //fprintf(stderr, "%hu * %hu\n", a, b);
  88. } while ( ( a != 0 ) || (b != 0) );
  89.  
  90. fprintf(stderr, "%"PRIu16"* ""%"PRIu16"\n", a, b);
  91. printf("Done!\n");
  92.  
  93. return 0;
  94. }
  95. #include <stdio.h>
  96. #include <stdlib.h>
  97. #include <limits.h>
  98. #include <inttypes.h>
  99.  
  100. uint32_t multiply (uint16_t a, uint16_t b)
  101. {
  102. //uint16_t mask = 0b0000000000000001;
  103.  
  104. register uint32_t result = 0;
  105.  
  106. result += (a & ( (int16_t)( ( b & (1 << 0) ) << 15 ) ) / ( 1 << 15) ) << 0;
  107.  
  108.  
  109. result += (a & ( (int16_t)( ( b & (1 << 1) ) << 14 ) ) / ( 1 << 15) ) << 1;
  110.  
  111.  
  112. result += (a & ( (int16_t)( ( b & (1 << 2) ) << 13 ) ) / ( 1 << 15) ) << 2;
  113.  
  114.  
  115. result += (a & ( (int16_t)( ( b & (1 << 3) ) << 12 ) ) / ( 1 << 15) ) << 3;
  116.  
  117.  
  118. result += (a & ( (int16_t)( ( b & (1 << 4) ) << 11 ) ) / ( 1 << 15) ) << 4;
  119.  
  120.  
  121. result += (a & ( (int16_t)( ( b & (1 << 5) ) << 10 ) ) / ( 1 << 15) ) << 5;
  122.  
  123.  
  124. result += (a & ( (int16_t)( ( b & (1 << 6) ) << 9 ) ) / ( 1 << 15) ) << 6;
  125.  
  126.  
  127. result += (a & ( (int16_t)( ( b & (1 << 7) ) << 8 ) ) / ( 1 << 15) ) << 7;
  128.  
  129.  
  130. result += (a & ( (int16_t)( ( b & (1 << 8) ) << 7 ) ) / ( 1 << 15) ) << 8;
  131.  
  132.  
  133. result += (a & ( (int16_t)( ( b & (1 << 9) ) << 6 ) ) / ( 1 << 15) ) << 9;
  134.  
  135.  
  136. result += (a & ( (int16_t)( ( b & (1 <<10) ) << 5 ) ) / ( 1 << 15) ) << 10;
  137.  
  138.  
  139. result += (a & ( (int16_t)( ( b & (1 <<11) ) << 4 ) ) / ( 1 << 15) ) << 11;
  140.  
  141.  
  142. result += (a & ( (int16_t)( ( b & (1 <<12) ) << 3 ) ) / ( 1 << 15) ) << 12;
  143.  
  144.  
  145. result += (a & ( (int16_t)( ( b & (1 <<13) ) << 2 ) ) / ( 1 << 15) ) << 13;
  146.  
  147.  
  148. result += (a & ( (int16_t)( ( b & (1 <<14) ) << 1 ) ) / ( 1 << 15) ) << 14;
  149.  
  150.  
  151. result += (a & ( (int16_t)( ( b & (1 <<15) ) << 0 ) ) / ( 1 << 15) ) << 15;
  152. return result;
  153. }
  154.  
  155. int main(void)
  156. {
  157.  
  158. uint16_t a, b;
  159. a = 0;
  160. b = 0;
  161.  
  162. do
  163. {
  164. if (multiply(a, b) != a * b)
  165.  
  166.  
  167. fprintf(stderr,
  168. "ERROR:\n"
  169. "my: %u\n"
  170. "norm: %u\n"
  171. "%hu * %hu\n"
  172. "\n",
  173. multiply(a, b), (a * b),a, b
  174. );
  175.  
  176. if (UINT16_MAX == a)
  177. {
  178. b++;
  179. }
  180. a++;
  181. //fprintf(stderr, "%hu * %hu\n", a, b);
  182. } while ( ( a != 0 ) || (b != 0) );
  183.  
  184. fprintf(stderr, "%"PRIu16"* ""%"PRIu16"\n", a, b);
  185. printf("Done!\n");
  186.  
  187. return 0;
  188. }
  189.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:100:10: error: redefinition of ‘multiply’
prog.c:6:10: note: previous definition of ‘multiply’ was here
prog.c:155:5: error: redefinition of ‘main’
prog.c:61:5: note: previous definition of ‘main’ was here
stdout
Standard output is empty