dp_cmp.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* IEEE754 floating point arithmetic
  2. * double precision: common utilities
  3. */
  4. /*
  5. * MIPS floating point support
  6. * Copyright (C) 1994-2000 Algorithmics Ltd.
  7. * http://www.algor.co.uk
  8. *
  9. * ########################################################################
  10. *
  11. * This program is free software; you can distribute it and/or modify it
  12. * under the terms of the GNU General Public License (Version 2) as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. * for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  23. *
  24. * ########################################################################
  25. */
  26. #include "ieee754dp.h"
  27. int ieee754dp_cmp(ieee754dp x, ieee754dp y, int cmp, int sig)
  28. {
  29. COMPXDP;
  30. COMPYDP;
  31. EXPLODEXDP;
  32. EXPLODEYDP;
  33. FLUSHXDP;
  34. FLUSHYDP;
  35. CLEARCX; /* Even clear inexact flag here */
  36. if (ieee754dp_isnan(x) || ieee754dp_isnan(y)) {
  37. if (sig || xc == IEEE754_CLASS_SNAN || yc == IEEE754_CLASS_SNAN)
  38. SETCX(IEEE754_INVALID_OPERATION);
  39. if (cmp & IEEE754_CUN)
  40. return 1;
  41. if (cmp & (IEEE754_CLT | IEEE754_CGT)) {
  42. if (sig && SETANDTESTCX(IEEE754_INVALID_OPERATION))
  43. return ieee754si_xcpt(0, "fcmpf", x);
  44. }
  45. return 0;
  46. } else {
  47. s64 vx = x.bits;
  48. s64 vy = y.bits;
  49. if (vx < 0)
  50. vx = -vx ^ DP_SIGN_BIT;
  51. if (vy < 0)
  52. vy = -vy ^ DP_SIGN_BIT;
  53. if (vx < vy)
  54. return (cmp & IEEE754_CLT) != 0;
  55. else if (vx == vy)
  56. return (cmp & IEEE754_CEQ) != 0;
  57. else
  58. return (cmp & IEEE754_CGT) != 0;
  59. }
  60. }