Integer comparison bug

Q&A's, tips, howto's
Locked
genghis
Posts: 4
Joined: Thu Apr 12, 2012 3:55 pm

Integer comparison bug

Post by genghis »

Loving the language so far.

Code: Select all

(= 9223372036854775807 9223372036854775808)
The above returns true. Shouldn't it be nil instead? Where can I submit bug reports? Do we have an bug tracker?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Integer comparison bug

Post by Lutz »

Integers are limited to 63-bit plus sign bit. Bigger numbers are truncated:

Code: Select all

> 9223372036854775807
9223372036854775807
> 9223372036854775808   ; <-- will get truncated
9223372036854775807
> 
only on negative numbers you can reach the 8 at the end:

Code: Select all

> (= -9223372036854775807 -9223372036854775808)
nil 
> (bits 9223372036854775807)
"111111111111111111111111111111111111111111111111111111111111111"
> (length (bits 9223372036854775807))
63
> (bits -9223372036854775808)
"1000000000000000000000000000000000000000000000000000000000000000"
> (length (bits -9223372036854775808))
64
> 

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: Integer comparison bug

Post by xytroxon »

Yeah, this showed up on reddit/programming about a PHP "bug"...

'9223372036854775807' == '9223372036854775808' (bugs.php.net)
submitted 4 hours ago by tjansson
* 143 comments
http://www.reddit.com/r/programming/com ... 854775808/


The above link expounds on the issue...

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

Locked