Support for java long data type

9 views
Skip to first unread message

Jon Ruiz

unread,
Feb 5, 2008, 4:53:07 PM2/5/08
to Google Web Toolkit
I have some legacy parsing code I'm using in a GWT project. The
parsing code makes heavy use of bit arithmetic against several
constants. One constant is defined as such (all the bits are
important):
long l = 0x8fffffffffff60fL
The problem is the parser only works in hosted mode, not browser mode.

So i figured out the problem from another post. It's that java longs
(64-bit integral types) are treated as javascript numbers (64 bit
floating types) and any long bigger than 2^53 will be rounded:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/f5c6c192271486da?hl=en

I have access to the source, but it's baroque and I'm not much of a
parser & bit-shifting type of programmer. Are there plans to really
support longs in GWT? Does anyone know of any tricks I might try short
of re-writing the parser logic?

Thanks,
Jon

Charlie Collins

unread,
Feb 5, 2008, 5:46:07 PM2/5/08
to Google Web Toolkit
I don't think there are plans to really support longs, because as that
other thread notes, it's not a GWT problem, it's a JavaScript problem.
But, in that thread Mp notes that there are various hacks to get
around the JS issue. I am not sure if these are planned for GWT or
not (didn't see anything in the tracker), and I don't personally know
exactly what said hacks involve, but presumably you might be able to
find out those methods and put something together for your purposes.

On Feb 5, 4:53 pm, Jon Ruiz <jon.r...@ca.com> wrote:
> I have some legacy parsing code I'm using in a GWT project. The
> parsing code makes heavy use of bit arithmetic against several
> constants. One constant is defined as such (all the bits are
> important):
> long l =  0x8fffffffffff60fL
> The problem is the parser only works in hosted mode, not browser mode.
>
> So i figured out the problem from another post. It's that java longs
> (64-bit integral types) are treated as javascript numbers (64 bit
> floating types) and any long bigger than 2^53 will be rounded:http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...

Ian Petersen

unread,
Feb 5, 2008, 5:53:17 PM2/5/08
to Google-We...@googlegroups.com
On Feb 5, 2008 4:53 PM, Jon Ruiz <jon....@ca.com> wrote:
> I have access to the source, but it's baroque and I'm not much of a
> parser & bit-shifting type of programmer. Are there plans to really
> support longs in GWT? Does anyone know of any tricks I might try short
> of re-writing the parser logic?

I'm not a GWT developer, so I can't say for sure, but I'd bet that GWT
won't support longs for a long time, if ever. One of GWT's primary
goals is to improve user experience, at the expense of developer
experience if necessary. Supporting longs "for real" would be
_really_ slow (you'd have to emulate a long as two ints and do a bunch
of magic to handle bit transitions between the upper and lower words,
and bitwise operators in Javascript are rumoured to be slow because
the interpreter has to cast from double to int, do the op, then cast
back to double). If you have a particular use case, it might be worth
it to create a special-purpose emulation library and port your code to
use it, but I'd bet that it would be easier to port the code to work
on 32-bit ints than it would be to write a 64-bit integer emulator.

Ian

--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com

Jon Ruiz

unread,
Feb 6, 2008, 6:00:43 PM2/6/08
to Google Web Toolkit
As always, I appreciate the help. I'm curious if anyone knows of any
hacks I could use that are out there? I turns out the parsing code was
generated by javacc (the java compiler compiler), and that explains
why the parsing code is hard to read - it's generated by another
program. So, I'm playing with it, but right now there's nothing
obvious/straightforward about how to get the code to use ints instead.

-Jon

On Feb 5, 4:53 pm, "Ian Petersen" <ispet...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages