unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Inconsistency: sometimes an integer, sometimes a float
Date: Fri, 24 Jan 2014 20:28:32 +0100	[thread overview]
Message-ID: <878uu5ji1r.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.12685.1390574401.10748.help-gnu-emacs@gnu.org

Doug Lewan <dougl@shubertticketing.com> 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 !"


  parent reply	other threads:[~2014-01-24 19:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-23 10:39 Inconsistency: sometimes an integer, sometimes a float djc
2014-01-23 15:50 ` Rasmus
2014-01-23 16:03 ` Nicolas Richard
2014-01-23 16:07 ` Nicolas Richard
2014-01-23 16:33 ` Eli Zaretskii
2014-01-23 21:42 ` Pascal J. Bourguignon
2014-01-24 14:39 ` Doug Lewan
     [not found] ` <mailman.12685.1390574401.10748.help-gnu-emacs@gnu.org>
2014-01-24 19:28   ` Pascal J. Bourguignon [this message]
2014-01-25  1:18     ` Drew Adams
     [not found] ` <mailman.12661.1390513424.10748.help-gnu-emacs@gnu.org>
2014-01-24 22:25   ` djc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878uu5ji1r.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).