[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua5 / poor performance
- From: "Peter S. Housel" <housel@...>
- Date: Thu, 20 Mar 2003 12:40:27 -0800
"Roberto Ierusalimschy" <roberto@inf.puc-rio.br> wrote:
> Any solution to this problem must change the way Lua hashes non-integer
> numbers. One particular solution is this:
>
[solution using type punning]
>
> This code is not very "religious", but it does the trick. (The
> performance for integer keys is not affected by this change.)
A more portable, and very fast, method of hashing floating-point numbers
might be:
1) Extract the manitssa and exponent using frexp() function.
2) Multiply the mantissa by (double) 2^(bits in a long - 1)
3) Truncate the multiplication result to a long
4) Hash this result with together with the exponent
-Peter-