1 | /*
|
---|
2 | * $RCSfile$
|
---|
3 | *
|
---|
4 | * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
|
---|
5 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
---|
6 | *
|
---|
7 | * This code is free software; you can redistribute it and/or modify it
|
---|
8 | * under the terms of the GNU General Public License version 2 only, as
|
---|
9 | * published by the Free Software Foundation. Sun designates this
|
---|
10 | * particular file as subject to the "Classpath" exception as provided
|
---|
11 | * by Sun in the LICENSE file that accompanied this code.
|
---|
12 | *
|
---|
13 | * This code is distributed in the hope that it will be useful, but WITHOUT
|
---|
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
---|
16 | * version 2 for more details (a copy is included in the LICENSE file that
|
---|
17 | * accompanied this code).
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License version
|
---|
20 | * 2 along with this work; if not, write to the Free Software Foundation,
|
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
22 | *
|
---|
23 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
---|
24 | * CA 95054 USA or visit www.sun.com if you need additional information or
|
---|
25 | * have any questions.
|
---|
26 | *
|
---|
27 | * $Revision: 127 $
|
---|
28 | * $Date: 2008-02-28 21:18:51 +0100 (jeu., 28 févr. 2008) $
|
---|
29 | * $State$
|
---|
30 | */
|
---|
31 |
|
---|
32 | package javax.vecmath;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Utility vecmath class used when computing the hash code for vecmath
|
---|
36 | * objects containing float or double values. This fixes Issue 36.
|
---|
37 | */
|
---|
38 | class VecMathUtil {
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Returns the representation of the specified floating-point
|
---|
42 | * value according to the IEEE 754 floating-point "double format"
|
---|
43 | * bit layout, after first mapping -0.0 to 0.0. This method is
|
---|
44 | * identical to Double.doubleToLongBits(double) except that an
|
---|
45 | * integer value of 0L is returned for a floating-point value of
|
---|
46 | * -0.0. This is done for the purpose of computing a hash code
|
---|
47 | * that satisfies the contract of hashCode() and equals(). The
|
---|
48 | * equals() method in each vecmath class does a pair-wise "=="
|
---|
49 | * test on each floating-point field in the class (e.g., x, y, and
|
---|
50 | * z for a Tuple3d). Since 0.0 == -0.0 returns true, we
|
---|
51 | * must also return the same hash code for two objects, one of
|
---|
52 | * which has a field with a value of -0.0 and the other of which
|
---|
53 | * has a cooresponding field with a value of 0.0.
|
---|
54 | *
|
---|
55 | * @param d an input double precision floating-point number
|
---|
56 | * @return the integer bits representing that floating-point
|
---|
57 | * number, after first mapping -0.0f to 0.0f
|
---|
58 | */
|
---|
59 | static long doubleToLongBits(double d) {
|
---|
60 | // Check for +0 or -0
|
---|
61 | if (d == 0.0) {
|
---|
62 | return 0L;
|
---|
63 | }
|
---|
64 | else {
|
---|
65 | return Double.doubleToLongBits(d);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Do not construct an instance of this class.
|
---|
72 | */
|
---|
73 | private VecMathUtil() {
|
---|
74 | }
|
---|
75 | }
|
---|