num2float.i.c 878 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* this file is #include'd (several times) by numbers.c */
  2. FTYPE
  3. NUM2FLOAT (SCM num, unsigned long int pos, const char *s_caller)
  4. {
  5. if (SCM_INUMP (num))
  6. return SCM_INUM (num);
  7. else if (SCM_BIGP (num))
  8. { /* bignum */
  9. FTYPE res = 0.0;
  10. size_t l;
  11. for (l = SCM_NUMDIGS (num); l--;)
  12. res = SCM_BIGRAD * res + SCM_BDIGITS (num)[l];
  13. if (SCM_BIGSIGN (num))
  14. res = -res;
  15. if (isfinite (res))
  16. return res;
  17. else
  18. scm_out_of_range (s_caller, num);
  19. }
  20. else if (SCM_REALP (num))
  21. return SCM_REAL_VALUE (num);
  22. else
  23. scm_wrong_type_arg (s_caller, pos, num);
  24. }
  25. SCM
  26. FLOAT2NUM (FTYPE n)
  27. {
  28. SCM z;
  29. SCM_NEWCELL2 (z);
  30. SCM_SET_CELL_TYPE (z, scm_tc16_real);
  31. SCM_REAL_VALUE (z) = n;
  32. return z;
  33. }
  34. /* clean up */
  35. #undef FLOAT2NUM
  36. #undef NUM2FLOAT
  37. #undef FTYPE
  38. /*
  39. Local Variables:
  40. c-file-style: "gnu"
  41. End:
  42. */