gencurr.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. {$ifndef FPUNONE}
  26. function round(c : currency) : int64;
  27. var
  28. rem, absrem: currency;
  29. begin
  30. { (int64(tmyrec(c))(+/-)5000) div 10000 can overflow }
  31. result := int64(c);
  32. rem := c - currency(result);
  33. absrem := rem;
  34. if absrem < 0 then
  35. absrem := -absrem;
  36. if (absrem > 0.5) or
  37. ((absrem = 0.5) and
  38. (rem > 0)) then
  39. if (rem > 0) then
  40. inc(result)
  41. else
  42. dec(result);
  43. end;
  44. {$endif FPUNONE}
  45. {$ifndef cpujvm}
  46. function round(c : comp) : int64;
  47. {$else not cpujvm}
  48. function round_comp(c : comp) : int64;
  49. {$endif cpujvm}
  50. begin
  51. result := c
  52. end;
  53. {$endif FPC_CURRENCY_IS_INT64}