From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Inconsistency: sometimes an integer, sometimes a float Date: Fri, 24 Jan 2014 20:28:32 +0100 Organization: Informatimago Message-ID: <878uu5ji1r.fsf@kuiper.lan.informatimago.com> References: <4ce73e74-a069-4e8d-b606-5aa76b848940@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1390591812 15910 80.91.229.3 (24 Jan 2014 19:30:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jan 2014 19:30:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 24 20:30:21 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W6mSK-0005yD-B3 for geh-help-gnu-emacs@m.gmane.org; Fri, 24 Jan 2014 20:30:20 +0100 Original-Received: from localhost ([::1]:48642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6mSJ-0000Le-TK for geh-help-gnu-emacs@m.gmane.org; Fri, 24 Jan 2014 14:30:19 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 61 Original-X-Trace: individual.net cjzwff08we5fzAmDz7orNgVod65QBc52hOBBlWsjONUQtuNqGN Cancel-Lock: sha1:MjEwMTRlNWM5YTE3MTg2MDRiYWQ4MWYzOWZiNmFkNmViMjBmNDhhMA== sha1:k3F4w7bo6yuAnkWyxuXChMO7FgE= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:203362 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:95630 Archived-At: Doug Lewan writes: > Cool bug! How in the world did you find it? It is not a bug, it is a design of the language. Yes, emacs lisp is ill-designed. If you want a better designed lisp, consider Common Lisp. Namely, emacs numeric datatypes are limited to fixnums and floats. see: most-positive-fixnum On 32-bit systems, fixnums are limited to 29 bits. most-positive-fixnum --> 536870911 (format "%o " 536870911) --> "3777777777" (integer-length 536870911) --> 29 On 64-bit systems, fixnums are limited to 61 bits. most-positive-fixnum --> 2305843009213693951 (/ 2305843009213693951 1000000) --> 2305843009213 (/ (1+ 2305843009213693951) 1000000) --> -2305843009213 (/ 2305843009213693952 1000000) --> 2305843009213.694 In emacs lisp, / is very wrong, since (/ 2 3) --> 0 For floating point numbers it is ok: (/ 2.0 3.0) --> 0.6666666666666666 but of course, people often have very wrong expectations about floating point numbers, I can't fathom why. Notice that 1+ (like +, -, *, etc) is also very wrong, on emacs lisp fixnums, since (minusp (1+ most-positive-fixnum)). On the other hand, reading 536870912 on a 32-bit emacs, or 2305843009213693952 on a 64-bit emacs, reads a floating point number (since there is no such fixnum). This is clearly ludicrously insane! If you want to compute, better use Common Lisp: cl-user> (/ most-positive-fixnum 1000000) 46116860184273879/40000 cl-user> (/ (1+ most-positive-fixnum) 1000000) 18014398509481984/15625 cl-user> (/ (float (1+ most-positive-fixnum)) 1000000) 1.1529215E+12 cl-user> (/ (complex most-positive-fixnum most-positive-double-float) 1000000) #C(1.152921504606847D+12 1.797693134862316D+302) -- __Pascal Bourguignon__ http://www.informatimago.com/ "Le mercure monte ? C'est le moment d'acheter !"