reason for java.lang.Long special handling?

31 views
Skip to first unread message

Henri Dubois-Ferriere

unread,
Nov 23, 2015, 8:25:42 PM11/23/15
to node-java
I'm trying to understand the reason for the special treatment of longs. 

The Readme motivates this special handling by  "JavaScript only supports 32-bit integers". 

Yet from skimming the EcmaScript doc, the only thing I see related to 32-bit integers is that certain operators (e.g. bitwise ops) work over 32-bit values. But they still take Numbers as operands (and they convert them to 32 bit values, see last paragraph of http://www.ecma-international.org/ecma-262/5.1/#sec-8.5). 

So it seems like it should be fine to convert longs to plain old js Numbers rather than NumberObjects. Does this make sense or am I missing something?

(I started looking into this because I'm finding it cumbersome to have to convert the NumbersObjects back to numbers in an array of Java.lang.Object).

Henri



Jim Lloyd

unread,
Nov 23, 2015, 8:31:49 PM11/23/15
to Henri Dubois-Ferriere, node-java
Javascript doesn't have support for 64-bit integers. The only 64-bit numeric type is Number, which is a floating point type, with 53 bits of mantissa. Integers up to 53 bits may be stored in a Number, but larger integers cannot without loss of precision.

--
You received this message because you are subscribed to the Google Groups "node-java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-java+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Henri Dubois-Ferriere

unread,
Nov 23, 2015, 8:43:47 PM11/23/15
to Jim Lloyd, node-java
Understood (duh!), thanks...
Reply all
Reply to author
Forward
0 new messages