Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.69 KB | None | 0 0
  1. import std.stdio;
  2.  
  3. int[512] tab;
  4. int mul (byte a, byte b)
  5. {
  6.     ushort x = cast(ushort)(a + b)&511;
  7.     ushort y = cast(ushort)(a - b)&511;
  8.     return tab[x] - tab[y];
  9. }
  10. void main (string[] args)
  11. {
  12.     int failed = 0;
  13.     for (auto i = 0; i < 512; i++)
  14.     {
  15.         int a = i < 256 ? i : i - 512;
  16.         tab[i] = a*a/4;
  17.     }
  18.     for (auto x = -128; x < 128; x++)
  19.     {
  20.         for (auto y = -128; y < 128; y++)
  21.         {
  22.             if (mul (cast (byte)x, cast (byte)y) != x*y)
  23.             {
  24.                 writefln ("failed %s %s", x, y);
  25.                 failed++;
  26.                 goto end;
  27.             }
  28.         }
  29.     }
  30. end:
  31.     if (0 == failed) writeln ("passed!");
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement