cuf4.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 INTEGER TO SINGLE (CUF n 4)
  8. THIS ROUTINE WORKS BY FILLING AN EXTENDED
  9. WITH THE INTEGER VALUE IN EXTENDED FORMAT
  10. AND USES COMPACT() TO PUT IT INTO THE PROPER
  11. FLOATING POINT PRECISION.
  12. */
  13. #include "FP_types.h"
  14. void
  15. cuf4(ss,src)
  16. int ss; /* source size */
  17. long src; /* largest possible integer to convert */
  18. {
  19. EXTEND buf;
  20. short *ipt;
  21. SINGLE *result;
  22. long i_src;
  23. zrf_ext(&buf);
  24. if (ss == sizeof(long)) {
  25. buf.exp = 31;
  26. i_src = src;
  27. result = (SINGLE *) &src;
  28. }
  29. else {
  30. ipt = (short *) &src;
  31. i_src = (long) *ipt;
  32. buf.exp = 15;
  33. result = (SINGLE *) ((void *) &ss);
  34. }
  35. if (i_src == 0) {
  36. *result = (SINGLE) 0L;
  37. return;
  38. }
  39. /* ESTABLISHED THAT src != 0 */
  40. /* adjust exponent field */
  41. if (ss != sizeof(long))
  42. i_src <<= 16;
  43. /* move to mantissa field */
  44. buf.m1 = i_src;
  45. /* adjust mantissa field */
  46. nrm_ext(&buf);
  47. compact(&buf,result,4);
  48. }