[Top][All Lists]

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

expt weirdness in floatfns.c

From: D Goel
Subject: expt weirdness in floatfns.c
Date: Fri, 05 Aug 2005 18:59:03 -0400
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

(expt 3 3) tries to return 27 instead of 27.0
That is good

However, this has an unexpected outcome:

(expt 2 -2) returns 0 instead of 0.25

I couldn,t understand the c code, but it seems to do this: 

 /* don't promote to floats, if both are ints */

 (and (integerp a)
      (integerp b))

Perhaps it should add  this condition to the above:

 (and (integerp a)
      (integerp b)
      (plusp b)) 



One might try to argue this to explain away the present behavior: the
user shoud expect an integer if both inputs were integers.

But if that were so, then conversely,  (log 2 8) should return 0 and
not .33333


i think that both should return the proper values instead of truncated
integers., truncating to integers only has precedent when it comes to
division (and even there, elisp differs from most other langages,
including CL)


In the case of expt, it looks like (?) the author never intended to
return a truncated answer, he was just trying to be nice and return an
integer for things line 3^3, and just overlooked the possibility of b
being negative at this stage.

reply via email to

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