gencurr.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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; {$ifdef systeminline} inline; {$endif}
  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; {$ifdef systeminline} inline; {$endif}
  19. {$else not cpujvm}
  20. function trunc_comp(c : comp) : int64; {$ifdef systeminline} inline; {$endif}
  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. result := int64(c);
  31. rem := c - currency(result);
  32. case softfloat_rounding_mode of
  33. rmNearest:
  34. begin
  35. absrem := abs(rem);
  36. if (absrem > 0.5) or
  37. ((absrem = 0.5) and
  38. odd(result)) then
  39. if (rem > 0) then
  40. inc(result)
  41. else
  42. dec(result)
  43. end;
  44. rmDown:
  45. begin
  46. if rem < 0 then
  47. dec(result);
  48. end;
  49. rmUp:
  50. begin
  51. if rem > 0 then
  52. inc(result);
  53. end;
  54. rmTruncate:
  55. begin
  56. // result is already ok
  57. end;
  58. end;
  59. end;
  60. {$endif FPUNONE}
  61. {$ifndef cpujvm}
  62. function round(c : comp) : int64; {$ifdef systeminline} inline; {$endif}
  63. {$else not cpujvm}
  64. function round_comp(c : comp) : int64; {$ifdef systeminline} inline; {$endif}
  65. {$endif cpujvm}
  66. begin
  67. result := c
  68. end;
  69. {$endif FPC_CURRENCY_IS_INT64}