add_ext.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. ADD TWO EXTENDED FORMAT NUMBERS
  8. */
  9. #include "FP_types.h"
  10. void
  11. add_ext(e1,e2)
  12. register 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. return;
  20. }
  21. sft_ext(e1, e2); /* adjust mantissas to equal powers */
  22. if (e1->sign != e2->sign) {
  23. /* e1 + e2 = e1 - (-e2) */
  24. if (e2->m1 > e1->m1 ||
  25. (e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
  26. /* abs(e2) > abs(e1) */
  27. EXTEND x;
  28. x = *e1;
  29. *e1 = *e2;
  30. if (x.m2 > e1->m2) {
  31. e1->m1 -= 1; /* carry in */
  32. }
  33. e1->m1 -= x.m1;
  34. e1->m2 -= x.m2;
  35. }
  36. else {
  37. if (e2->m2 > e1->m2)
  38. e1->m1 -= 1; /* carry in */
  39. e1->m1 -= e2->m1;
  40. e1->m2 -= e2->m2;
  41. }
  42. }
  43. else {
  44. if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
  45. b64_rsft(&e1->mantissa); /* shift mantissa one bit RIGHT */
  46. e1->m1 |= 0x80000000L; /* set max bit */
  47. e1->exp++; /* increase the exponent */
  48. }
  49. }
  50. nrm_ext(e1);
  51. }