sub_ext.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. SUBTRACT 2 EXTENDED FORMAT NUMBERS
  8. */
  9. #include "FP_types.h"
  10. void
  11. sub_ext(e1,e2)
  12. EXTEND *e1,*e2;
  13. {
  14. if ((e2->m1 | e2->m2) == 0L) {
  15. return;
  16. }
  17. if ((e1->m1 | e1->m2) == 0L) {
  18. *e1 = *e2;
  19. e1->sign = e2->sign ? 0 : 1;
  20. return;
  21. }
  22. sft_ext(e1, e2);
  23. if (e1->sign != e2->sign) {
  24. /* e1 - e2 = e1 + (-e2) */
  25. if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
  26. b64_rsft(&e1->mantissa); /* shift mantissa one bit RIGHT */
  27. e1->m1 |= 0x80000000L; /* set max bit */
  28. e1->exp++; /* increase the exponent */
  29. }
  30. }
  31. else if (e2->m1 > e1->m1 ||
  32. (e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
  33. /* abs(e2) > abs(e1) */
  34. if (e1->m2 > e2->m2) {
  35. e2->m1 -= 1; /* carry in */
  36. }
  37. e2->m1 -= e1->m1;
  38. e2->m2 -= e1->m2;
  39. *e1 = *e2;
  40. e1->sign = e2->sign ? 0 : 1;
  41. }
  42. else {
  43. if (e2->m2 > e1->m2)
  44. e1->m1 -= 1; /* carry in */
  45. e1->m1 -= e2->m1;
  46. e1->m2 -= e2->m2;
  47. }
  48. nrm_ext(e1);
  49. }