@Override public float convertToFloat(CharSequence value) { if (value instanceof AsciiString) { return ((AsciiString) value).parseFloat(); } return Float.parseFloat(value.toString()); }
@Override protected Float doForward(String value) { return Float.valueOf(value); }
private Object toObject (String key, String value) { if (key.endsWith("b")) return new Boolean(Boolean.parseBoolean(value)); if (key.endsWith("i")) return new Integer(Integer.parseInt(value)); if (key.endsWith("l")) return new Long(Long.parseLong(value)); if (key.endsWith("f")) return new Float(Float.parseFloat(value)); return value; }
/** True if the vector represents a pair of valid, non-infinite floating point numbers. */ public final boolean isValid() { return !Float.isNaN(x) && !Float.isInfinite(x) && !Float.isNaN(y) && !Float.isInfinite(y); }
/** * 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 ) ) ); }
public static float unboxed(Float v) { return v == null ? 0 : v.floatValue(); }
@Override public Object decode(Object jv) { if (jv instanceof Number) { return new Float(((Number) jv).floatValue()); } return (Float) null; } };
/** * 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); }
@Override protected String doBackward(Float value) { return value.toString(); }
@Test public void testNanHash() { int[] nanRepresentations = {floatToIntBits(Float.NaN), 0xffc00000, 0x7fc00000, 0x7fc01234, 0xffc01234}; for (int nanRepresentation : nanRepresentations) { assertTrue(isNaN(intBitsToFloat(nanRepresentation))); assertEquals(RealOperators.hashCode(nanRepresentation), RealOperators.hashCode(nanRepresentations[0])); } } }
public Object addOne(ProceedingJoinPoint pjp, Float value) throws Throwable { float fv = value.floatValue(); return pjp.proceed(new Object[] {new Float(fv + 1.0F)}); }
/** * to int. * * @param b byte array. * @param off offset. * @return int. */ public static float bytes2float(byte[] b, int off) { int i = ((b[off + 3] & 0xFF) << 0) + ((b[off + 2] & 0xFF) << 8) + ((b[off + 1] & 0xFF) << 16) + ((b[off + 0]) << 24); return Float.intBitsToFloat(i); }
@Test public void withUncheckedObjectValue() throws Exception { Float value = new Float("99.45"); this.tag.setPath("myFloat"); this.tag.setValue(value); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "name", "myFloat"); assertContainsAttribute(output, "type", "radio"); assertContainsAttribute(output, "value", value.toString()); assertAttributeNotPresent(output, "checked"); }
/** * Checks whether the float value is the special NaN value. * * @return true if NaN */ public boolean isNaN() { return Float.isNaN(value); }
public static float unboxed(Float v) { return v == null ? 0 : v.floatValue(); }
@Override public Object decode(Object jv) { if (jv instanceof Number) { return new Float(((Number) jv).floatValue()); } return (Float) null; } };
/** * 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); }