1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

* 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.
This commit is contained in:
Mikael Djurfeldt 2001-09-22 21:39:42 +00:00
parent b21cccf315
commit 5437598b36
5 changed files with 78 additions and 1 deletions

6
NEWS
View file

@ -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]

View file

@ -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

View file

@ -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)

50
libguile/num2float.i.c Normal file
View file

@ -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:
*/

View file

@ -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) \