4 ms·
Are there other weird number hacks like this one?
by boroadlkjq 13y ago
Are there other weird number hacks like this one?
- matwood 13y agoLook at the hashCode() implementations in http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/java/util/Arrays.java http://grepcode.com/file/repository.grepcode.com/java/root/j... For example: public static int hashCode(double a[]) { if (a == null) return 0; int result = 1; for (double element : a) { long bits = Double.doubleToLongBits(element); result = 31 * result + (int)(bits ^ (bits >>> 32)); } return result; }
- snotrockets 13y agoWhy is this weird? It's the textbook method for doing hashes.
- matwood 13y agoIt is textbook, but the poster asked for seemingly random numbers in code. Based on all the places the invsqrt method has popped up, it also was a textbook method for doing it quickly.