math.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2008 by the Free Pascal development team.
  4. Implementation of mathematical Routines (only for real)
  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. {$ifndef FPC_SYSTEM_HAS_INT}
  12. {$define FPC_SYSTEM_HAS_INT}
  13. function fpc_int_real(d : ValReal) : ValReal;assembler;nostackframe;compilerproc;
  14. asm
  15. movfcsr2gr $t0, $r3
  16. li.d $t1, 0x100
  17. movgr2fcsr $r3, $t1
  18. frint.d $fa0, $fa0
  19. movgr2fcsr $r3, $t0
  20. end;
  21. {$endif ndef FPC_SYSTEM_HAS_INT}
  22. {$ifndef FPC_SYSTEM_HAS_FRAC}
  23. {$define FPC_SYSTEM_HAS_FRAC}
  24. function fpc_frac_real(d : ValReal) : ValReal;assembler;nostackframe;compilerproc;
  25. asm
  26. movfr2gr.d $t0, $fa0
  27. li.d $t1, 0x7ff0000000000000
  28. and $t0, $t0, $t1
  29. beq $t0, $t1, .LNaN
  30. movfcsr2gr $t0, $r3
  31. li.d $t1, 0x100
  32. movgr2fcsr $r3, $t1
  33. frint.d $fa1, $fa0
  34. movgr2fcsr $r3, $t0
  35. fsub.d $fa0, $fa0, $fa1
  36. jr $ra
  37. .LNaN:
  38. fsub.d $fa0, $fa0, $fa0
  39. movgr2fr.d $fa1, $zero
  40. fdiv.d $fa0, $fa0, $fa1
  41. // jr $ra
  42. end;
  43. {$endif ndef FPC_SYSTEM_HAS_FRAC}