ClojureScript

Numerical inconsistency between Clojure and ClojureScript (running in Rhino)

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Environment:
    Clojure (1.5.1) on JVM vs. ClojureScript (cloned from GitHub today) in Rhino on JVM

Description

In Clojure, the maximum long value throws an ArithmeticException when incremented with + and rolls over to a BigInt when incremented with +'

user=> (+ 9223372036854775807 1)
ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow (Numbers.java:1388)
user=> (+' 9223372036854775807 1)
9223372036854775808N

But ClojureScript rolls over to BigInt with + and does not have a +' function

ClojureScript:cljs.user> (+ 9223372036854775807 1)
9223372036854776000N
ClojureScript:cljs.user> (+' 9223372036854775807 1)
WARNING: Use of undeclared Var cljs.user/+' at line 1 
"Error evaluating:" (+' 9223372036854775807 1) :as "cljs.user._PLUS__SINGLEQUOTE_.call(null,9223372036854775807,1)"
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "call" of undefined (<cljs repl>#1)
        at <cljs repl>:1 (anonymous)
        at <cljs repl>:1

In fact, the inexactness of 9223372036854776000N suggests the reason: it's actually a double, presented as though it were a BigInt. (Perhaps that's a limitation of JavaScript? If so, at least it should be presented as a double, as very large numbers are: e.g. (* 9223372036854775807 9223372036854775807) --> 8.507059173023462E37.) From http://stackoverflow.com/questions/8664093/not-getting-integer-overflow-in-clojure , it is my understanding that this behavior was defined in Clojure version 1.3--- is ClojureScript a few versions behind in that it attempts roll-over and does not have a +' function?

Activity

David Nolen made changes -
Field Original Value New Value
Resolution Declined [ 2 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: