Re: [PATCH]: Bug with expt
Dirk Herrmann <[EMAIL PROTECTED]> writes: > -> exponent is a negative integer --> result could be a rational if those >were supported. This could be handled nicely: > >cond ((and (integer? z2) (< z2 0)) (/ 1 (integer-expt z1 (- z2 > >Shall I add this special case to expt? Yes. It doesn't make much sense now, but can serve as a reminder. (Actually, it *does* make sense for those trying to plug in a rational module via GOOPS.) > -> exponent is a negative rational --> result will be a real, except for >the rare cases that the square root (or whatever root) can be solved >exactly. I don't know how to handle this nicely. I don't think we should care too much about this one. Best, /mdj
Re: [PATCH]: Bug with expt
On 12 Jul 2000, Mikael Djurfeldt wrote: > > The test for exactness if wrong here: Rationals (if supported) could > > fulfill that predicate as well. I will apply the following patch: > > > > diff -u -r1.208 boot-9.scm > > --- boot-9.scm 2000/07/01 17:01:22 1.208 > > +++ boot-9.scm 2000/07/12 07:23:07 > > @@ -793,7 +793,7 @@ > > (define expt > >(let ((integer-expt integer-expt)) > > (lambda (z1 z2) > > - (cond ((exact? z2) > > + (cond ((and (integer? z2) (>= z2 0)) > > (integer-expt z1 z2)) > > ((and (real? z2) (real? z1) (>= z1 0)) > > ($expt z1 z2)) > > Did you check with R5RS that it is OK to return an inexact in the case > of exact negative exponent? (I presume it ius.) I did not think about that. However: In which cases of exact negative exponents can the result be an exact value at all? -> exponent is a negative integer --> result could be a rational if those were supported. This could be handled nicely: cond ((and (integer? z2) (< z2 0)) (/ 1 (integer-expt z1 (- z2 Shall I add this special case to expt? -> exponent is a negative rational --> result will be a real, except for the rare cases that the square root (or whatever root) can be solved exactly. I don't know how to handle this nicely. In any case, this example makes it clear that there can not be a demand for an exact result, even if the exponent is exact. Best regards Dirk
Re: [PATCH]: Bug with expt
Dirk Herrmann <[EMAIL PROTECTED]> writes: > The test for exactness if wrong here: Rationals (if supported) could > fulfill that predicate as well. I will apply the following patch: > > diff -u -r1.208 boot-9.scm > --- boot-9.scm 2000/07/01 17:01:22 1.208 > +++ boot-9.scm 2000/07/12 07:23:07 > @@ -793,7 +793,7 @@ > (define expt >(let ((integer-expt integer-expt)) > (lambda (z1 z2) > - (cond ((exact? z2) > + (cond ((and (integer? z2) (>= z2 0)) > (integer-expt z1 z2)) > ((and (real? z2) (real? z1) (>= z1 0)) > ($expt z1 z2)) Did you check with R5RS that it is OK to return an inexact in the case of exact negative exponent? (I presume it ius.) > > I noticed also that list-tail does no longer accept a second negative > > argument. R5RS say it is an error if the list length is shorter > > than the second argument, but is silent for the negative case. > > But the example implementation given in R5RS relies on the fact that the > parameter is positive or zero. Further, I can not think of any reasonable > behaviour for the case of negative indexes. Thus, IMO it is a bug fix > rather than a bug that negative indexes are not accepted. Indeed.
[PATCH]: Bug with expt
On 11 Jul 2000, bernard URBAN wrote: > # guile > guile> (version) > "1.4" > guile> (expt 2 -1) > ERROR: In procedure integer-expt: > ERROR: Argument out of range: -1 > ABORT: (out-of-range) > guile> ($expt 2 -1) > 0.5 > guile> > > >From boot-9.scm: > (define expt > (let ((integer-expt integer-expt)) > (lambda (z1 z2) > (cond ((exact? z2) >(integer-expt z1 z2)) > ((and (real? z2) (real? z1) (>= z1 0)) >($expt z1 z2)) > (else >(exp (* z2 (log z1 The test for exactness if wrong here: Rationals (if supported) could fulfill that predicate as well. I will apply the following patch: diff -u -r1.208 boot-9.scm --- boot-9.scm 2000/07/01 17:01:22 1.208 +++ boot-9.scm 2000/07/12 07:23:07 @@ -793,7 +793,7 @@ (define expt (let ((integer-expt integer-expt)) (lambda (z1 z2) - (cond ((exact? z2) + (cond ((and (integer? z2) (>= z2 0)) (integer-expt z1 z2)) ((and (real? z2) (real? z1) (>= z1 0)) ($expt z1 z2)) > I noticed also that list-tail does no longer accept a second negative > argument. R5RS say it is an error if the list length is shorter > than the second argument, but is silent for the negative case. But the example implementation given in R5RS relies on the fact that the parameter is positive or zero. Further, I can not think of any reasonable behaviour for the case of negative indexes. Thus, IMO it is a bug fix rather than a bug that negative indexes are not accepted. Best regards Dirk