all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Inconsistency: sometimes an integer, sometimes a float
@ 2014-01-23 10:39 djc
  2014-01-23 15:50 ` Rasmus
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: djc @ 2014-01-23 10:39 UTC (permalink / raw)
  To: help-gnu-emacs

"(/ 536870911 1000000)" is an integer.

"(/ 536870912 1000000)" is a float.

I know why, but it's still unpleasant to have to program around it.  I suppose this begs the question of when there will be a supported 64-bit release of Emacs.

GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601)

djc


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

* Re: Inconsistency: sometimes an integer, sometimes a float
  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
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Rasmus @ 2014-01-23 15:50 UTC (permalink / raw)
  To: help-gnu-emacs

djc <peter.kaiser@gmail.com> writes:

> "(/ 536870911 1000000)" is an integer.
>
> "(/ 536870912 1000000)" is a float.

I cannot reproduce with the below Emacs: 

(type-of (/ 536870911 1000000)) => integer
(type-of (/ 536870912 1000000)) => integer

(emacs-version) => 
GNU Emacs 24.3.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.10.6)
 of 2014-01-22 on localhost"

Can you reproduce from emacs -q?  Can you reproduce from the hg head?

> I know why, but it's still unpleasant to have to program around it.  I
> suppose this begs the question of when there will be a supported
> 64-bit release of Emacs. 

On Windows?  When someone supplies patches, I guess.  Meanwhile you
could try this

  http://semantic.supelec.fr/popineau/programming-emacs.html

I don't know how well it works.

–Rasmus

-- 
Enough with the bla bla!




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

* Re: Inconsistency: sometimes an integer, sometimes a float
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Nicolas Richard @ 2014-01-23 16:03 UTC (permalink / raw)
  To: djc; +Cc: help-gnu-emacs

djc <peter.kaiser@gmail.com> writes:

> "(/ 536870911 1000000)" is an integer.
>
> "(/ 536870912 1000000)" is a float.

I can reproduce this ()
-- 
Nico.



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

* Re: Inconsistency: sometimes an integer, sometimes a float
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Nicolas Richard @ 2014-01-23 16:07 UTC (permalink / raw)
  To: djc; +Cc: help-gnu-emacs

Err, sorry for previous message, it was sent by accident.

djc <peter.kaiser@gmail.com> writes:
> "(/ 536870911 1000000)" is an integer.
> "(/ 536870912 1000000)" is a float.

What I was saying is : I can reproduce this from -Q :

/tmp $ emacs -Q --batch  --eval '(message "%s" (type-of (/ 536870912 1000000)))'
float
/tmp $ emacs --version
GNU Emacs 24.3.50.2
(...)

It's because:
$ emacs -Q --batch  --eval '(message "%s" (type-of 536870912))'
float

which itself comes from:
$ emacs -Q --batch  --eval '(message "%s" (> 536870912 most-positive-fixnum))'
t

explanation at:
(info "(elisp) Integer Type")

,----
| As a special exception, if a sequence of digits specifies an integer
| too large or too small to be a valid integer object, the Lisp reader
| reads it as a floating-point number (*note Floating Point Type::).  For
| instance, if Emacs integers are 30 bits, `536870912' is read as the
| floating-point number `536870912.0'.
`----

HTH,

-- 
Nico.



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

* Re: Inconsistency: sometimes an integer, sometimes a float
  2014-01-23 10:39 Inconsistency: sometimes an integer, sometimes a float djc
                   ` (2 preceding siblings ...)
  2014-01-23 16:07 ` Nicolas Richard
@ 2014-01-23 16:33 ` Eli Zaretskii
  2014-01-23 21:42 ` Pascal J. Bourguignon
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2014-01-23 16:33 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Thu, 23 Jan 2014 02:39:07 -0800 (PST)
> From: djc <peter.kaiser@gmail.com>
> 
> I suppose this begs the question of when there will be a supported
> 64-bit release of Emacs.

AFAIK, it is supported already.



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

* Re: Inconsistency: sometimes an integer, sometimes a float
  2014-01-23 10:39 Inconsistency: sometimes an integer, sometimes a float djc
                   ` (3 preceding siblings ...)
  2014-01-23 16:33 ` Eli Zaretskii
@ 2014-01-23 21:42 ` Pascal J. Bourguignon
  2014-01-24 14:39 ` Doug Lewan
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Pascal J. Bourguignon @ 2014-01-23 21:42 UTC (permalink / raw)
  To: help-gnu-emacs

djc <peter.kaiser@gmail.com> writes:

> "(/ 536870911 1000000)" is an integer.
>
> "(/ 536870912 1000000)" is a float.
>
> I know why, but it's still unpleasant to have to program around it.  I suppose this begs the question of when there will be a supported 64-bit release of Emacs.
>
> GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601)

A 64-bit emacs wouldn't be a solution, you'd just increase the number of
cases where (/ (1+ n) p) is not of the same type as (/ n p).n

Instead, write:

    (defun float/ (dividend divisor &rest divisors)
      (apply (function /) (float dividend) divisor divisors))

and use it instead of /.


    (float/ 536870911  1000000)  --> 536.870911
    (float/ 536870912  1000000)  --> 536.870912
    (float/ 536870.912 1000.000) --> 536.870912


-- 
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ?  C'est le moment d'acheter !"




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

* RE: Inconsistency: sometimes an integer, sometimes a float
  2014-01-23 10:39 Inconsistency: sometimes an integer, sometimes a float djc
                   ` (4 preceding siblings ...)
  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>
       [not found] ` <mailman.12661.1390513424.10748.help-gnu-emacs@gnu.org>
  7 siblings, 0 replies; 10+ messages in thread
From: Doug Lewan @ 2014-01-24 14:39 UTC (permalink / raw)
  To: djc, help-gnu-emacs@gnu.org

Cool bug! How in the world did you find it?

FYI emacs 24.3.1 on AIX 6.1, power pc architecture has this bug, but not on CYGWIN.

,Douglas
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224

Of course, shells have one feature that no other language has: subshells.

> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
> Behalf Of djc
> Sent: Thursday, 2014 January 23 05:39
> To: help-gnu-emacs@gnu.org
> Subject: Inconsistency: sometimes an integer, sometimes a float
> 
> "(/ 536870911 1000000)" is an integer.
> 
> "(/ 536870912 1000000)" is a float.
> 
> I know why, but it's still unpleasant to have to program around it.  I
> suppose this begs the question of when there will be a supported 64-bit
> release of Emacs.
> 
> GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601)
> 
> djc



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

* Re: Inconsistency: sometimes an integer, sometimes a float
       [not found] ` <mailman.12685.1390574401.10748.help-gnu-emacs@gnu.org>
@ 2014-01-24 19:28   ` Pascal J. Bourguignon
  2014-01-25  1:18     ` Drew Adams
  0 siblings, 1 reply; 10+ messages in thread
From: Pascal J. Bourguignon @ 2014-01-24 19:28 UTC (permalink / raw)
  To: help-gnu-emacs

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 !"


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

* Re: Inconsistency: sometimes an integer, sometimes a float
       [not found] ` <mailman.12661.1390513424.10748.help-gnu-emacs@gnu.org>
@ 2014-01-24 22:25   ` djc
  0 siblings, 0 replies; 10+ messages in thread
From: djc @ 2014-01-24 22:25 UTC (permalink / raw)
  To: help-gnu-emacs

> Instead, write:
>     (defun float/ (dividend divisor &rest divisors)
>       (apply (function /) (float dividend) divisor divisors))

That's indeed consistent, but wouldn't work for my purposes, since what I really want is the millions group as an integer.  (And later perhaps also the billions... groups.)  Problem simplified, solved and generalized in the actual code in question at a slight decrease in speed that has no consequences in the context of its use.

djc


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

* RE: Inconsistency: sometimes an integer, sometimes a float
  2014-01-24 19:28   ` Pascal J. Bourguignon
@ 2014-01-25  1:18     ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2014-01-25  1:18 UTC (permalink / raw)
  To: Pascal J. Bourguignon, help-gnu-emacs

> Namely, emacs numeric datatypes are limited to fixnums and floats.

But see this emacs-devel discussion about bignums a few years back:
http://lists.gnu.org/archive/html/emacs-devel/2010-03/msg00190.html

So far, that hasn't gone anywhere.  But perhaps someone here
will volunteer...



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

end of thread, other threads:[~2014-01-25  1:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-01-25  1:18     ` Drew Adams
     [not found] ` <mailman.12661.1390513424.10748.help-gnu-emacs@gnu.org>
2014-01-24 22:25   ` djc

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.