Double#doubleToLongBits

86 views
Skip to first unread message

qpid

unread,
Jun 26, 2007, 5:08:15 PM6/26/07
to Google Web Toolkit
Hi,

I need to override the hashcode method for a class to get it hashmap
save.
In my case I have a class with double values. Normally i use the
algorithm from "Effectiv Java: override equals and hashCode". For
double it is to get a long with Double#doubleToLongBits(double) and
than add it to the result with "int c = (int)(f ^ (f >>> 32));"

Trying it out in HostMode results in an error: "The method
doubleToLongBits(double) is undefined for the type Double".

Do somebody knows a workaround or an alternative solution?

Thanks ahead!

best regards
qpid

Sandy McArthur

unread,
Jun 26, 2007, 5:14:30 PM6/26/07
to Google-We...@googlegroups.com
JavaScript doesn't really support longs or doubles, they get treated
like ints and floats. I'd probably just convert the Double to a string
and hash that.


--
Sandy McArthur

"He who dares not offend cannot be honest."
- Thomas Paine

Ian Petersen

unread,
Jun 26, 2007, 5:31:36 PM6/26/07
to Google-We...@googlegroups.com
On 6/26/07, Sandy McArthur <sand...@gmail.com> wrote:
> JavaScript doesn't really support longs or doubles, they get treated
> like ints and floats. I'd probably just convert the Double to a string
> and hash that.

Just want to clarify that in Javascript all numbers are doubles, which
gives you perfect emulation of all of Java's primitive types except
long, which has holes beyond 53-bit integers.

Sandy's suggestion to convert to a string and then hashing is a pretty
good one, though.

Ian

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

qpid

unread,
Jun 27, 2007, 9:13:48 AM6/27/07
to Google Web Toolkit
Thank you both!
Sounds really nice and simple. Maybe if I would be a little bit more
skilled in such deep informatics I get such a solution by myself.

best regards
qpid

On 26 Jun., 23:31, "Ian Petersen" <ispet...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages