Clojure

Integer autopromotion error

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None

Description

From this thread:
http://groups.google.com/group/clojure/browse_thread/thread/db1ffbb36c7d6f48

user=>(def imax (Integer/MAX_VALUE))
user=>(+ imax imax)
4294967294

user=>(+ (Integer/MAX_VALUE) (Integer/MAX_VALUE))
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

Also:
user=>(+ Integer/MAX_VALUE Integer/MAX_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

user=> (+ (Integer/MAX_VALUE) imax)
4294967294

user=> (+ imax (Integer/MAX_VALUE))
4294967294

user=> (+ Integer/MAX_VALUE Integer/MAX_VALUE Integer/MAX_VALUE)
6442450941

Possibly a bug with inlining?

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/339
Hide
Assembla Importer added a comment -

devlinsf said: Also, some more cases

user=> (- Integer/MAX_VALUE Integer/MAX_VALUE Integer/MAX_VALUE)
-2147483647

user=> (- Integer/MIN_VALUE Integer/MIN_VALUE)
0
user=> (- Integer/MAX_VALUE Integer/MIN_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

user=> (- Integer/MAX_VALUE Integer/MIN_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

user=> (- Integer/MIN_VALUE Integer/MAX_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

user=> (* Integer/MIN_VALUE Integer/MAX_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

user=> (* Integer/MAX_VALUE Integer/MAX_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

user=> (* Integer/MAX_VALUE Integer/MAX_VALUE Integer/MAX_VALUE)
9903520300447984150353281023

Show
Assembla Importer added a comment - devlinsf said: Also, some more cases user=> (- Integer/MAX_VALUE Integer/MAX_VALUE Integer/MAX_VALUE) -2147483647 user=> (- Integer/MIN_VALUE Integer/MIN_VALUE) 0 user=> (- Integer/MAX_VALUE Integer/MIN_VALUE) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0) user=> (- Integer/MAX_VALUE Integer/MIN_VALUE) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0) user=> (- Integer/MIN_VALUE Integer/MAX_VALUE) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0) user=> (* Integer/MIN_VALUE Integer/MAX_VALUE) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0) user=> (* Integer/MAX_VALUE Integer/MAX_VALUE) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0) user=> (* Integer/MAX_VALUE Integer/MAX_VALUE Integer/MAX_VALUE) 9903520300447984150353281023
Hide
Assembla Importer added a comment -

aredington said: When testing with ints, this behavior no longer happens as all arithmetic happens in longs.

When testing with longs, the overflow behavior occurs consistently, regardless of the involvement of vars or let bindings.

Show
Assembla Importer added a comment - aredington said: When testing with ints, this behavior no longer happens as all arithmetic happens in longs. When testing with longs, the overflow behavior occurs consistently, regardless of the involvement of vars or let bindings.

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: