D. Ataro D. Ataro -5 years ago 236
Java Question

Value out of range for int in Clojure

Normally whilst programming in LibGDX, passing the Color class an integer of a hex value works just fine:

new Color(0xeaeaeaff);

But doing this from Clojure...

(Color. 0xeaeaeaff)

... generates the error java.lang.IllegalArgumentException: Value out of range for int: 3,941,264,128. Sure that value does look out of range, very much so. But when I normally do it from Java, there is no problem at all?

The Clojure value is defined like so:

(def color 0xff00ffff)

Does anybody have an answer as to why this happens?

Answer Source

0xeaeaeaff in Java represents a negative number: -353703169. Clojure has a different number literal for different bases <radix>r<value>.

In your case 0xeaeaeaff in Java is equal to -353703169 in base 10. You can write it just as -353703169 in Clojure, or in base 16 as -16r15151501.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download