cfu.c 924 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. CONVERT FLOAT TO UNSIGNED (CFU m n)
  8. N.B. The caller must know what it is getting.
  9. A LONG is always returned. If it is an
  10. integer the high byte is cleared first.
  11. */
  12. #include "FP_trap.h"
  13. #include "FP_types.h"
  14. long
  15. cfu(ds,ss,src)
  16. int ds; /* destination size (2 or 4) */
  17. int ss; /* source size (4 or 8) */
  18. DOUBLE src; /* assume worst case */
  19. {
  20. EXTEND buf;
  21. long new;
  22. short newint, max_exp;
  23. extend(&src.d[0],&buf,ss); /* get extended format */
  24. if (buf.exp < 0) { /* no conversion needed */
  25. src.d[ss == 8] = 0L;
  26. return(0L);
  27. }
  28. max_exp = (ds << 3) - 1;
  29. if (buf.exp > max_exp) {
  30. trap(EIOVFL); /* integer overflow */
  31. buf.exp %= max_exp;
  32. }
  33. new = buf.m1 >> (31-buf.exp);
  34. done:
  35. src.d[ss == 8] = new;
  36. return(new);
  37. }