2 * $RCSfile: VecMathUtil.java,v $
4 * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
28 * $Date: 2008/02/28 20:18:51 $
32 package javax.vecmath;
35 * Utility vecmath class used when computing the hash code for vecmath
36 * objects containing float or double values. This fixes Issue 36.
40 * Returns the representation of the specified floating-point
41 * value according to the IEEE 754 floating-point "single format"
42 * bit layout, after first mapping -0.0 to 0.0. This method is
43 * identical to Float.floatToIntBits(float) except that an integer
44 * value of 0 is returned for a floating-point value of
45 * -0.0f. This is done for the purpose of computing a hash code
46 * that satisfies the contract of hashCode() and equals(). The
47 * equals() method in each vecmath class does a pair-wise "=="
48 * test on each floating-point field in the class (e.g., x, y, and
49 * z for a Tuple3f). Since 0.0f == -0.0f returns true,
50 * we must also return the same hash code for two objects, one of
51 * which has a field with a value of -0.0f and the other of which
52 * has a cooresponding field with a value of 0.0f.
54 * @param f an input floating-point number
55 * @return the integer bits representing that floating-point
56 * number, after first mapping -0.0f to 0.0f
58 static int floatToIntBits(float f) {
64 return Float.floatToIntBits(f);
69 * Returns the representation of the specified floating-point
70 * value according to the IEEE 754 floating-point "double format"
71 * bit layout, after first mapping -0.0 to 0.0. This method is
72 * identical to Double.doubleToLongBits(double) except that an
73 * integer value of 0L is returned for a floating-point value of
74 * -0.0. This is done for the purpose of computing a hash code
75 * that satisfies the contract of hashCode() and equals(). The
76 * equals() method in each vecmath class does a pair-wise "=="
77 * test on each floating-point field in the class (e.g., x, y, and
78 * z for a Tuple3d). Since 0.0 == -0.0 returns true, we
79 * must also return the same hash code for two objects, one of
80 * which has a field with a value of -0.0 and the other of which
81 * has a cooresponding field with a value of 0.0.
83 * @param d an input double precision floating-point number
84 * @return the integer bits representing that floating-point
85 * number, after first mapping -0.0f to 0.0f
87 static long doubleToLongBits(double d) {
93 return Double.doubleToLongBits(d);
99 * Do not construct an instance of this class.
101 private VecMathUtil() {