unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* expt weirdness in floatfns.c
@ 2005-08-05 22:59 D Goel
  2005-08-06 14:12 ` Thien-Thi Nguyen
  2005-08-06 18:35 ` Richard M. Stallman
  0 siblings, 2 replies; 11+ messages in thread
From: D Goel @ 2005-08-05 22:59 UTC (permalink / raw)



(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 */

 
(if 
 (and (integerp a)
      (integerp b))
 
  (leave-them-be))

Perhaps it should add  this condition to the above:

 
(if 
 (and (integerp a)
      (integerp b)
      (plusp b)) 
  (leave-them-be))

.
.
.

 ====================================================

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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-08-08 18:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-05 22:59 expt weirdness in floatfns.c D Goel
2005-08-06 14:12 ` Thien-Thi Nguyen
2005-08-06 18:35 ` Richard M. Stallman
2005-08-06 22:36   ` Thien-Thi Nguyen
2005-08-06 23:55     ` Luc Teirlinck
2005-08-07  0:49       ` Thien-Thi Nguyen
2005-08-07  0:10     ` Luc Teirlinck
2005-08-07 13:02       ` Thien-Thi Nguyen
2005-08-08 12:08     ` Richard M. Stallman
2005-08-08 18:32       ` Thien-Thi Nguyen
2005-08-06 23:43   ` Luc Teirlinck

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).