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. register uint32_t result = 0;
  9. char n = 0, n2 = 15;
  10.  
  11. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  12. n++; n2--;
  13.  
  14. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  15. n++; n2--;
  16.  
  17. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  18. n++; n2--;
  19.  
  20. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  21. n++; n2--;
  22.  
  23. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  24. n++; n2--;
  25.  
  26. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  27. n++; n2--;
  28.  
  29. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  30. n++; n2--;
  31.  
  32. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  33. n++; n2--;
  34.  
  35. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  36. n++; n2--;
  37.  
  38. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  39. n++; n2--;
  40.  
  41. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  42. n++; n2--;
  43.  
  44. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  45. n++; n2--;
  46.  
  47. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  48. n++; n2--;
  49.  
  50. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  51. n++; n2--;
  52.  
  53. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  54. n++; n2--;
  55.  
  56. result += (a & ( (int16_t)( ( b & (1 << n) ) << n2 ) ) / ( 1 << 15) ) << n;
  57. return result;
  58. }
  59.  
  60. int main(void)
  61. {
  62.  
  63. uint16_t a, b;
  64. a = 0;
  65. b = 0;
  66.  
  67. do
  68. {
  69. if (multiply(a, b) != a * b)
  70.  
  71.  
  72. fprintf(stderr,
  73. "ERROR:\n"
  74. "my: %u\n"
  75. "norm: %u\n"
  76. "%hu * %hu\n"
  77. "\n",
  78. multiply(a, b), (a * b),a, b
  79. );
  80.  
  81. if (UINT16_MAX == a)
  82. {
  83. b++;
  84. }
  85. a++;
  86. //fprintf(stderr, "%hu * %hu\n", a, b);
  87. } while ( ( a != 0 ) || (b != 0) );
  88.  
  89. fprintf(stderr, "%"PRIu16"* ""%"PRIu16"\n", a, b);
  90. printf("Done!\n");
  91.  
  92. return 0;
  93. }
Time limit exceeded #stdin #stdout 5s 1784KB
stdin
Standard input is empty
stdout
Standard output is empty