flt_flt2ar.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "flt_misc.h"
  7. #include <em_arith.h>
  8. arith
  9. flt_flt2arith(e, uns)
  10. register flt_arith *e;
  11. {
  12. /* Convert the flt_arith "n" to an arith.
  13. */
  14. arith n;
  15. struct flt_mantissa a;
  16. if (uns) uns = 1;
  17. flt_status = 0;
  18. if (e->flt_sign && uns) {
  19. flt_status = FLT_UNFL;
  20. return 0;
  21. }
  22. if (e->flt_exp < 0) {
  23. /* absolute value of result < 1.
  24. Return value only depends on sign:
  25. */
  26. return -e->flt_sign;
  27. }
  28. if (e->flt_exp > 8*sizeof(arith)-2 + uns) {
  29. /* probably overflow, but there is one exception:
  30. */
  31. if (e->flt_sign &&
  32. e->flt_exp == 8*sizeof(arith)-1 &&
  33. e->m2 == 0 &&
  34. e->m1 == 0x80000000) {
  35. /* No overflow in this case */
  36. flt_status = 0;
  37. }
  38. else {
  39. flt_status = FLT_OVFL;
  40. e->flt_exp = 8*sizeof(arith)-2 + uns + e->flt_sign;
  41. if (e->flt_sign) {
  42. e->m1 = 0x80000000;
  43. e->m2 = 0;
  44. }
  45. else {
  46. e->m1 = 0xFFFFFFFF;
  47. e->m2 = 0xFFFFFFFF;
  48. }
  49. }
  50. }
  51. a = e->flt_mantissa;
  52. flt_b64_sft(&a, 63-e->flt_exp);
  53. n = a.flt_l_32 | ((a.flt_h_32 << 16) << 16);
  54. /* not << 32; this could be an undefined operation */
  55. return e->flt_sign ? -n : n;
  56. }