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 | |
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.
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | libguile/ChangeLog | 10 | ||||
-rw-r--r-- | libguile/Makefile.am | 3 | ||||
-rw-r--r-- | libguile/num2float.i.c | 50 | ||||
-rw-r--r-- | libguile/numbers.c | 10 |
5 files changed, 78 insertions, 1 deletions
@@ -1208,6 +1208,12 @@ These are conversion functions between the various ANSI C integral types and Scheme numbers. NOTE: The scm_num2xxx functions don't accept an inexact argument. +** New functions: scm_float2num, scm_double2num, + scm_num2float, scm_num2double. + +These are conversion functions between the two ANSI C float types and +Scheme numbers. + ** New number validation macros: SCM_NUM2{SIZE,PTRDIFF,SHORT,USHORT,INT,UINT}[_DEF] diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 75e2c56d9..a7530216b 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,13 @@ +2001-09-22 Mikael Djurfeldt <mdj@linnaeus> + + * 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. + 2001-09-21 Rob Browning <rlb@defaultvalue.org> * .cvsignore: really add version.h diff --git a/libguile/Makefile.am b/libguile/Makefile.am index 09fa64ae5..9ead1f8a6 100644 --- a/libguile/Makefile.am +++ b/libguile/Makefile.am @@ -111,7 +111,8 @@ install-exec-hook: ## compile, since they are #included. So instead we list them here. ## Perhaps we can deal with them normally once the merge seems to be ## working. -noinst_HEADERS = coop-threads.c coop-threads.h coop.c num2integral.i.c +noinst_HEADERS = coop-threads.c coop-threads.h coop.c \ + num2integral.i.c num2float.i.c libguile_la_DEPENDENCIES = @LIBLOBJS@ libguile_la_LIBADD = @LIBLOBJS@ $(LIBLTDL) 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: +*/ diff --git a/libguile/numbers.c b/libguile/numbers.c index 1c26b91be..596bacb33 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -4365,6 +4365,16 @@ scm_i_big2dbl (SCM b) #endif /* HAVE_LONG_LONGS */ +#define NUM2FLOAT scm_num2float +#define FLOAT2NUM scm_float2num +#define FTYPE float +#include "libguile/num2float.i.c" + +#define NUM2FLOAT scm_num2double +#define FLOAT2NUM scm_double2num +#define FTYPE double +#include "libguile/num2float.i.c" + #ifdef GUILE_DEBUG #define CHECK(type, v) \ |