guile-devel
[Top][All Lists]
Advanced

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

Re: scm_num2int change


From: Mikael Djurfeldt
Subject: Re: scm_num2int change
Date: 20 Sep 2001 19:21:11 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Bill Schottstaedt <address@hidden> writes:

> >     * num2integral.i.c (NUM2INTEGRAL): Report an error when these
> >     routines are passed an inexact.  This change in behavior is
> >     motivated by concordance with R5RS: It is more common that a
> >     primitive doesn't want to accept an inexact for an exact.
> 
> This is an inconvenient change.

There might be special situations where it would be convenient to
accept inexact integer values for conversion into C integers, but it
seems like the common situation is where we don't accept inexacts.
This is true for most procedures in R5RS, and it is the common
situation in applications as well.

It is important that we provide functions which are suitable building
blocks.  For these functions to accept reals as well would be too
generic, since, in the common case, one would have to implement most
of the inner machinery of these functions in duplicate.

> scm_integer_p 1.0 returns #t, but I can't use num2int to turn it
> into 1 anymore.  Where in "num" does it say "exact num"?  Now before
> any call I have to check for both exact and integer.

Yes, in that special case.

> It also breaks existing Scheme code.  For example, I have
> 
>     (let ((mult (expt 2.0 (/ semitones 12.0))))
> 
> This now dies if semitones is 12:
> 
> wrong-type-arg: (integer-expt Wrong type argument in position ~A: ~S (2 1.0) 
> #f)
> Backtrace:
> In /home/bil/cl/snd-test.scm:
> [edited]
>  172: 7* [expt 2.0 1.0]
>    ?: 8  (cond ((integer? z2) (if # # #)) ((and # # #) ($expt z1 z2)) (#t 
> (exp #)))
>    ?: 9  [integer-expt 2.0 1.0]
> 
> >(expt 2.0 1.0)
> integer-expt: Wrong type argument in position 2: 1.0

I should have gone through the existing code using scm_num2long and
scm_num2ulong before comitting the fix.  Sorry.

Best,
Mikael



reply via email to

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