gencurr.inc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2007 by Several contributors
  4. Generic mathematical routines (on type currency)
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. }
  11. {$ifdef FPC_CURRENCY_IS_INT64}
  12. function trunc(c : currency) : int64;
  13. type
  14. tmyrec = record
  15. i: int64;
  16. end;
  17. begin
  18. result := int64(tmyrec(c)) div 10000
  19. end;
  20. function trunc(c : comp) : int64;
  21. begin
  22. result := c
  23. end;
  24. function round(c : currency) : int64;
  25. type
  26. tmyrec = record
  27. i: int64;
  28. end;
  29. var
  30. rem, absrem: longint;
  31. begin
  32. { (int64(tmyrec(c))(+/-)5000) div 10000 can overflow }
  33. result := int64(tmyrec(c)) div 10000;
  34. rem := int64(tmyrec(c)) - result * 10000;
  35. absrem := abs(rem);
  36. if (absrem > 5000) or
  37. ((absrem = 5000) and
  38. (rem > 0)) then
  39. if (rem > 0) then
  40. inc(result)
  41. else
  42. dec(result);
  43. end;
  44. function round(c : comp) : int64;
  45. begin
  46. result := c
  47. end;
  48. {$endif FPC_CURRENCY_IS_INT64}