tw39646.pp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. { %OPT=-O2 }
  2. program tw39646;
  3. function NestedDivWithAnd(const num: UInt64): Integer;
  4. begin
  5. NestedDivWithAnd := (num div 100000000) and $FF;
  6. end;
  7. function NestedModWithAnd(const num: UInt64): Integer;
  8. begin
  9. NestedModWithAnd := (num mod 100000000) and $FF;
  10. end;
  11. const
  12. Input: array[0..5] of UInt64 = (0, 1, 100000001, 4000000385, 5000000006, 25700000385);
  13. ExpectedD: array[0..5] of Integer = (0, 0, 1, 40, 50, 1);
  14. ExpectedM: array[0..5] of Integer = (0, 1, 1, 129, 6, 129);
  15. var
  16. Failed: Boolean;
  17. X, Output: Integer;
  18. begin
  19. WriteLn('Testing "(UInt64 div 100000000) and $FF" with implicit typecast to Integer:');
  20. Failed := False;
  21. for X := Low(Input) to High(Input) do
  22. begin
  23. Write('- Input = ', Input[X], ' ... ');
  24. Output := NestedDivWithAnd(Input[X]);
  25. if Output = ExpectedD[X] then
  26. WriteLn('Passed')
  27. else
  28. begin
  29. WriteLn('FAILED! Got ', Output, ', expected ', ExpectedD[X]);
  30. Failed := True;
  31. end;
  32. end;
  33. WriteLn(#10'Testing "(UInt64 mod 100000000) and $FF" with implicit typecast to Integer:');
  34. for X := Low(Input) to High(Input) do
  35. begin
  36. Write('- Input = ', Input[X], ' ... ');
  37. Output := NestedModWithAnd(Input[X]);
  38. if Output = ExpectedM[X] then
  39. WriteLn('Passed')
  40. else
  41. begin
  42. WriteLn('FAILED! Got ', Output, ', expected ', ExpectedM[X]);
  43. Failed := True;
  44. end;
  45. end;
  46. if Failed then
  47. Halt(1)
  48. else
  49. WriteLn('ok');
  50. end.