diff options
author | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 2001-09-22 21:39:42 +0000 |
---|---|---|
committer | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 2001-09-22 21:39:42 +0000 |
commit | 5437598b36938332d3a0813b4311ec7f700a8db7 (patch) | |
tree | d63d0ad85beb0a87403a40cc7035e946200dfffa /libguile/num2float.i.c | |
parent | b21cccf315b4a20d19ac064d5b4b98921e57f108 (diff) | |
download | guile-5437598b36938332d3a0813b4311ec7f700a8db7.tar.gz |
* Makefile.am: Distribute num2float.i.c.
* num2float.i.c: New file, multiply included by numbers.c, used
to "templatize" the float <-> num conversion routines.
* numbers.c: New functions: scm_num2float, scm_float2num,
scm_num2double, scm_double2num.
Diffstat (limited to 'libguile/num2float.i.c')
-rw-r--r-- | libguile/num2float.i.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libguile/num2float.i.c b/libguile/num2float.i.c new file mode 100644 index 000000000..22efffb1d --- /dev/null +++ b/libguile/num2float.i.c @@ -0,0 +1,50 @@ +/* this file is #include'd (several times) by numbers.c */ + +FTYPE +NUM2FLOAT (SCM num, unsigned long int pos, const char *s_caller) +{ + if (SCM_INUMP (num)) + return SCM_INUM (num); + else if (SCM_BIGP (num)) + { /* bignum */ + + FTYPE res = 0.0; + size_t l; + + for (l = SCM_NUMDIGS (num); l--;) + res = SCM_BIGRAD * res + SCM_BDIGITS (num)[l]; + + if (SCM_BIGSIGN (num)) + res = -res; + + if (isfinite (res)) + return res; + else + scm_out_of_range (s_caller, num); + } + else if (SCM_REALP (num)) + return SCM_REAL_VALUE (num); + else + scm_wrong_type_arg (s_caller, pos, num); +} + +SCM +FLOAT2NUM (FTYPE n) +{ + SCM z; + SCM_NEWCELL2 (z); + SCM_SET_CELL_TYPE (z, scm_tc16_real); + SCM_REAL_VALUE (z) = n; + return z; +} + +/* clean up */ +#undef FLOAT2NUM +#undef NUM2FLOAT +#undef FTYPE + +/* + Local Variables: + c-file-style: "gnu" + End: +*/ |