trndcurr.pp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. uses
  2. Math;
  3. const
  4. failure_count : longint = 0;
  5. first_error : longint = 0;
  6. {$ifndef SKIP_CURRENCY_TEST}
  7. procedure testround(const c, expected: currency; error: longint);
  8. begin
  9. if round(c)<>expected then
  10. begin
  11. writeln('round(',c,') = ',round(c),' instead of ', expected);
  12. inc(failure_count);
  13. if first_error=0 then
  14. first_error:=error;
  15. end;
  16. end;
  17. {$endif}
  18. begin
  19. {$ifndef SKIP_CURRENCY_TEST}
  20. writeln('Rounding mode: rmNearest (even)');
  21. testround(0.5,0.0,1);
  22. testround(1.5,2.0,2);
  23. testround(-0.5,0.0,3);
  24. testround(-1.5,-2.0,4);
  25. testround(0.6,1.0,101);
  26. testround(1.6,2.0,102);
  27. testround(-0.6,-1.0,103);
  28. testround(-1.6,-2.0,104);
  29. testround(0.4,0.0,151);
  30. testround(1.4,1.0,152);
  31. testround(-0.4,-0.0,153);
  32. testround(-1.4,-1.0,154);
  33. writeln('Rounding mode: rmUp');
  34. if SetRoundMode(rmUp)<>rmNearest then
  35. writeln('Warning: previous mode was not rmNearest');
  36. if GetRoundMode <> rmUp then
  37. begin
  38. end;
  39. testround(0.5,1.0,5);
  40. testround(1.5,2.0,6);
  41. testround(-0.5,0.0,7);
  42. testround(-1.5,-1.0,8);
  43. testround(0.6,1.0,105);
  44. testround(1.6,2.0,106);
  45. testround(-0.6,0.0,107);
  46. testround(-1.6,-1.0,108);
  47. testround(0.4,1.0,155);
  48. testround(1.4,2.0,156);
  49. testround(-0.4,0.0,157);
  50. testround(-1.4,-1.0,158);
  51. writeln('Rounding mode: rmDown');
  52. SetRoundMode(rmDown);
  53. testround(0.5,0.0,9);
  54. testround(1.5,1.0,10);
  55. testround(-0.5,-1.0,11);
  56. testround(-1.5,-2.0,12);
  57. testround(0.6,0.0,109);
  58. testround(1.6,1.0,110);
  59. testround(-0.6,-1.0,111);
  60. testround(-1.6,-2.0,112);
  61. testround(0.4,0.0,159);
  62. testround(1.4,1.0,160);
  63. testround(-0.4,-1.0,161);
  64. testround(-1.4,-2.0,162);
  65. writeln('Rounding mode: rmTruncate');
  66. SetRoundMode(rmTruncate);
  67. testround(0.5,0.0,13);
  68. testround(1.5,1.0,14);
  69. testround(-0.5,0.0,15);
  70. testround(-1.5,-1.0,16);
  71. testround(0.6,0.0,113);
  72. testround(1.6,1.0,114);
  73. testround(-0.6,0.0,115);
  74. testround(-1.6,-1.0,116);
  75. testround(0.4,0.0,163);
  76. testround(1.4,1.0,164);
  77. testround(-0.4,0.0,165);
  78. testround(-1.4,-1.0,166);
  79. {$endif}
  80. if failure_count>0 then
  81. halt(first_error);
  82. end.