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. begin
  14. { the type conversion includes dividing by 10000 }
  15. result := int64(c)
  16. end;
  17. {$ifndef cpujvm}
  18. function trunc(c : comp) : int64;
  19. {$else not cpujvm}
  20. function trunc_comp(c : comp) : int64;
  21. {$endif cpujvm}
  22. begin
  23. result := c
  24. end;
  25. function round(c : currency) : int64;
  26. var
  27. rem, absrem: currency;
  28. begin
  29. { (int64(tmyrec(c))(+/-)5000) div 10000 can overflow }
  30. result := int64(c);
  31. rem := c - currency(result);
  32. absrem := abs(rem);
  33. if (absrem > 0.5) or
  34. ((absrem = 0.5) and
  35. (rem > 0)) then
  36. if (rem > 0) then
  37. inc(result)
  38. else
  39. dec(result);
  40. end;
  41. {$ifndef cpujvm}
  42. function round(c : comp) : int64;
  43. {$else not cpujvm}
  44. function round_comp(c : comp) : int64;
  45. {$endif cpujvm}
  46. begin
  47. result := c
  48. end;
  49. {$endif FPC_CURRENCY_IS_INT64}