/** * to byte array. * * @param v value. * @param b byte array. * @param off array offset. */ public static void float2bytes(float v, byte[] b, int off) { int i = Float.floatToIntBits(v); b[off + 3] = (byte) i; b[off + 2] = (byte) (i >>> 8); b[off + 1] = (byte) (i >>> 16); b[off + 0] = (byte) (i >>> 24); }
/** * to byte array. * * @param v value. * @param b byte array. * @param off array offset. */ public static void float2bytes(float v, byte[] b, int off) { int i = Float.floatToIntBits(v); b[off + 3] = (byte) i; b[off + 2] = (byte) (i >>> 8); b[off + 1] = (byte) (i >>> 16); b[off + 0] = (byte) (i >>> 24); }
public int hashCode () { int h = 1; for (int i = 0, n = size; i < n; i++) h = h * 31 + Float.floatToIntBits(nodes[i].value); return h; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Float.floatToIntBits(x); result = prime * result + Float.floatToIntBits(y); result = prime * result + Float.floatToIntBits(z); return result; }
/** * @see java.lang.Object#hashCode() */ @Override public int hashCode() { // automatically generated by Eclipse final int prime = 31; int result = 1; result = prime * result + Float.floatToIntBits(x); result = prime * result + Float.floatToIntBits(y); return result; }
public int hashCode () { int h = 1; for (int i = 0, n = size; i < n; i++) h = h * 31 + Float.floatToIntBits(nodes[i].value); return h; }
/** * {@inheritDoc} */ @Override public int hashCode() { return Float.floatToIntBits(width) ^ Float.floatToIntBits(height); } }
public static int floatToIntBits (float value) { return Float.floatToIntBits(value); }
public static int floatToIntBits (float value) { return Float.floatToIntBits(value); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Vec3 other = (Vec3) obj; if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) return false; if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) return false; if (Float.floatToIntBits(z) != Float.floatToIntBits(other.z)) return false; return true; }
/** * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { // automatically generated by Eclipse if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Vec2 other = (Vec2) obj; if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) return false; if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) return false; return true; } }
public int hashCode () { if (!ordered) return super.hashCode(); float[] items = this.items; int h = 1; for (int i = 0, n = size; i < n; i++) h = h * 31 + Float.floatToIntBits(items[i]); return h; }
public int hashCode () { if (!ordered) return super.hashCode(); float[] items = this.items; int h = 1; for (int i = 0, n = size; i < n; i++) h = h * 31 + Float.floatToIntBits(items[i]); return h; }
public int hashCode () { int h = 0; K[] keyTable = this.keyTable; float[] valueTable = this.valueTable; for (int i = 0, n = capacity + stashSize; i < n; i++) { K key = keyTable[i]; if (key != null) { h += key.hashCode() * 31; float value = valueTable[i]; h += Float.floatToIntBits(value); } } return h; }
/** * Writes a {@code float} as specified by {@link DataOutputStream#writeFloat(float)}, except using * little-endian byte order. * * @throws IOException if an I/O error occurs */ @Override public void writeFloat(float v) throws IOException { writeInt(Float.floatToIntBits(v)); }
/** * Converts a "float" value between endian systems. * @param value value to convert * @return the converted value */ public static float swapFloat(final float value) { return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) ); }
/** * Writes a "float" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedFloat(final byte[] data, final int offset, final float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedFloat(final OutputStream output, final float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
@Test public void nullSafeHashCodeWithFloatArray() { int expected = 31 * 7 + Float.floatToIntBits(9.6f); expected = 31 * expected + Float.floatToIntBits(7.4f); float[] array = {9.6f, 7.4f}; int actual = ObjectUtils.nullSafeHashCode(array); assertEquals(expected, actual); }
@Test public void testFloatArrayAsObject() { final float[] obj = new float[2]; assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = 5.4f; final int h1 = Float.floatToIntBits(5.4f); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = 6.3f; final int h2 = Float.floatToIntBits(6.3f); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); }