cmf8.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /*
  7. COMPARE DOUBLES (CMF 8)
  8. */
  9. #include "FP_types.h"
  10. #include "get_put.h"
  11. int
  12. cmf8(d1,d2)
  13. DOUBLE d1,d2;
  14. {
  15. #define SIGN(x) (((x) < 0) ? -1 : 1)
  16. /*
  17. * return ((d1 < d2) ? 1 : (d1 > d2) ? -1 : 0))
  18. */
  19. long l1,l2;
  20. int sign1,sign2;
  21. int rv;
  22. #if FL_MSL_AT_LOW_ADDRESS
  23. l1 = get4((char *)&d1);
  24. l2 = get4((char *)&d2);
  25. #else
  26. l1 = get4(((char *)&d1+4));
  27. l2 = get4(((char *)&d2+4));
  28. #endif
  29. sign1 = SIGN(l1);
  30. sign2 = SIGN(l2);
  31. if (sign1 != sign2) {
  32. l1 &= 0x7fffffff;
  33. l2 &= 0x7fffffff;
  34. if (l1 != 0 || l2 != 0) {
  35. return ((sign1 > 0) ? -1 : 1);
  36. }
  37. }
  38. if (l1 != l2) { /* we can decide here */
  39. rv = l1 < l2 ? 1 : -1;
  40. }
  41. else { /* decide in 2nd half */
  42. unsigned long u1, u2;
  43. #if FL_MSL_AT_LOW_ADDRESS
  44. u1 = get4(((char *)&d1 + 4));
  45. u2 = get4(((char *)&d2 + 4));
  46. #else
  47. u1 = get4((char *)&d1);
  48. u2 = get4((char *)&d2);
  49. #endif
  50. if (u1 == u2)
  51. return(0);
  52. if (u1 < u2) rv = 1;
  53. else rv = -1;
  54. }
  55. return sign1 * rv;
  56. }