guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Integer conversion proposal


From: Mikael Djurfeldt
Subject: Integer conversion proposal
Date: Fri, 21 Sep 2001 15:54:36 +0200

Originally we had three SCM --> C integer conversion functions in the
scm_ interface:

  scm_num2int
  scm_num2long
  scm_num2ulong

These functions existed in the last release of Guile.

Recently, this set was extended with further conversions into further
C integral types.

Even more recently, the behavior of these functions was adjusted not
to accept inexact integers.

Many things have changed in Guile since the last release.  The new
release will be a "cleanup" release where we have sacrificed some
backward compatibility.  Therefore any application which wants to
support the new release of Guile needs revision.  In this context, the
changes to the three conversion functions above might not be such a
big issue.

However, we might be able to preserve backward compatibility while at
the same time introducing a more precise naming scheme for the
conversion functions.

Proposal:

* Name the conversion functions:

  scm_exact_integer2int
  scm_exact_integer2long
  etc

* Introduce new conversion functions for floats and doubles:

  scm_real2float
  scm_real2double

* Introduce a macro SCM_COERCE_EXACT(N) which returns its argument
  verbatim for all types except inexact numbers for which an exact
  value is returned if possible.  (Note that this macro can be made
  very efficient.)

* For backward compatibility, implement scm_num2int, scm_num2long
  scm_num2ulong as:

  int
  scm_num2int (SCM num)
  {
    return scm_exact_integer2int (SCM_COERCE_EXACT (num));
  }

  etc

Comments?

(Are there reasonable shorter prefixes instead of
"scm_exact_integer2"?)

Mikael



reply via email to

[Prev in Thread] Current Thread [Next in Thread]