List of usage examples for java.lang Float floatToIntBits
@HotSpotIntrinsicCandidate public static int floatToIntBits(float value)
From source file:us.parr.animl.data.DataTable.java
protected static int getValue(VariableType colType, String v) { switch (colType) { case NUMERICAL_FLOAT: return Float.floatToIntBits(FloatingDecimal.parseFloat(v)); // System.out.print(Float.intBitsToFloat(row[col])); case NUMERICAL_INT: case TARGET_CATEGORICAL_INT: return Integer.valueOf(v); // System.out.print(row[col]); default:/*from ww w .j a v a 2 s .com*/ throw new UnsupportedOperationException("can't handle strings yet"); } }
From source file:haven.Utils.java
public static void float32e(float num, byte[] buf, int off) { int32e(Float.floatToIntBits(num), buf, off); }
From source file:org.openhab.io.transport.modbus.ModbusBitUtilities.java
/** * Convert command to array of registers using a specific value type * * @param command command to be converted * @param type value type to use in conversion * @return array of registers// w w w . jav a 2s .com * @throws NotImplementedException in cases where implementation is lacking for the type. This is thrown with 1-bit * and 8-bit value types */ public static ModbusRegisterArray commandToRegisters(Command command, ModbusConstants.ValueType type) { DecimalType numericCommand; if (command instanceof OnOffType || command instanceof OpenClosedType) { numericCommand = translateCommand2Boolean(command).get() ? new DecimalType(BigDecimal.ONE) : DecimalType.ZERO; } else if (command instanceof DecimalType) { numericCommand = (DecimalType) command; } else { throw new NotImplementedException(String.format( "Command '%s' of class '%s' cannot be converted to registers. Please use OnOffType, OpenClosedType, or DecimalType commands.", command, command.getClass().getName())); } if (type.getBits() != 16 && type.getBits() != 32 && type.getBits() != 64) { throw new IllegalArgumentException(String.format( "Illegal type=%s (bits=%d). Only 16bit and 32bit types are supported", type, type.getBits())); } switch (type) { case INT16: case UINT16: { short shortValue = numericCommand.shortValue(); // big endian byte ordering byte b1 = (byte) (shortValue >> 8); byte b2 = (byte) shortValue; ModbusRegister register = new BasicModbusRegister(b1, b2); return new BasicModbusRegisterArray(new ModbusRegister[] { register }); } case INT32: case UINT32: { int intValue = numericCommand.intValue(); // big endian byte ordering byte b1 = (byte) (intValue >> 24); byte b2 = (byte) (intValue >> 16); byte b3 = (byte) (intValue >> 8); byte b4 = (byte) intValue; ModbusRegister register = new BasicModbusRegister(b1, b2); ModbusRegister register2 = new BasicModbusRegister(b3, b4); return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 }); } case INT32_SWAP: case UINT32_SWAP: { int intValue = numericCommand.intValue(); // big endian byte ordering byte b1 = (byte) (intValue >> 24); byte b2 = (byte) (intValue >> 16); byte b3 = (byte) (intValue >> 8); byte b4 = (byte) intValue; ModbusRegister register = new BasicModbusRegister(b3, b4); ModbusRegister register2 = new BasicModbusRegister(b1, b2); return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 }); } case FLOAT32: { float floatValue = numericCommand.floatValue(); int intBits = Float.floatToIntBits(floatValue); // big endian byte ordering byte b1 = (byte) (intBits >> 24); byte b2 = (byte) (intBits >> 16); byte b3 = (byte) (intBits >> 8); byte b4 = (byte) intBits; ModbusRegister register = new BasicModbusRegister(b1, b2); ModbusRegister register2 = new BasicModbusRegister(b3, b4); return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 }); } case FLOAT32_SWAP: { float floatValue = numericCommand.floatValue(); int intBits = Float.floatToIntBits(floatValue); // big endian byte ordering byte b1 = (byte) (intBits >> 24); byte b2 = (byte) (intBits >> 16); byte b3 = (byte) (intBits >> 8); byte b4 = (byte) intBits; ModbusRegister register = new BasicModbusRegister(b3, b4); ModbusRegister register2 = new BasicModbusRegister(b1, b2); return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 }); } case INT64: case UINT64: { long longValue = numericCommand.longValue(); // big endian byte ordering byte b1 = (byte) (longValue >> 56); byte b2 = (byte) (longValue >> 48); byte b3 = (byte) (longValue >> 40); byte b4 = (byte) (longValue >> 32); byte b5 = (byte) (longValue >> 24); byte b6 = (byte) (longValue >> 16); byte b7 = (byte) (longValue >> 8); byte b8 = (byte) longValue; return new BasicModbusRegisterArray( new ModbusRegister[] { new BasicModbusRegister(b1, b2), new BasicModbusRegister(b3, b4), new BasicModbusRegister(b5, b6), new BasicModbusRegister(b7, b8) }); } case INT64_SWAP: case UINT64_SWAP: { long longValue = numericCommand.longValue(); // big endian byte ordering byte b1 = (byte) (longValue >> 56); byte b2 = (byte) (longValue >> 48); byte b3 = (byte) (longValue >> 40); byte b4 = (byte) (longValue >> 32); byte b5 = (byte) (longValue >> 24); byte b6 = (byte) (longValue >> 16); byte b7 = (byte) (longValue >> 8); byte b8 = (byte) longValue; return new BasicModbusRegisterArray( new ModbusRegister[] { new BasicModbusRegister(b7, b8), new BasicModbusRegister(b5, b6), new BasicModbusRegister(b3, b4), new BasicModbusRegister(b1, b2) }); } default: throw new NotImplementedException( String.format("Illegal type=%s. Missing implementation for this type", type)); } }
From source file:tds.assessment.Assessment.java
@Override public int hashCode() { int result = key.hashCode(); result = 31 * result + (assessmentId != null ? assessmentId.hashCode() : 0); result = 31 * result + (label != null ? label.hashCode() : 0); result = 31 * result + (selectionAlgorithm != null ? selectionAlgorithm.hashCode() : 0); result = 31 * result + (startAbility != +0.0f ? Float.floatToIntBits(startAbility) : 0); result = 31 * result + (subject != null ? subject.hashCode() : 0); result = 31 * result + prefetch;/* w w w . j a v a 2 s . c o m*/ result = 31 * result + (abilitySlope != +0.0f ? Float.floatToIntBits(abilitySlope) : 0); result = 31 * result + (abilityIntercept != +0.0f ? Float.floatToIntBits(abilityIntercept) : 0); result = 31 * result + (accommodationFamily != null ? accommodationFamily.hashCode() : 0); result = 31 * result + maxOpportunities; result = 31 * result + (fieldTestStartDate != null ? fieldTestStartDate.hashCode() : 0); result = 31 * result + (fieldTestEndDate != null ? fieldTestEndDate.hashCode() : 0); result = 31 * result + (initialAbilityBySubject ? 1 : 0); result = 31 * result + (accommodationDependencies != null ? accommodationDependencies.hashCode() : 0); result = 31 * result + (itemConstraints != null ? itemConstraints.hashCode() : 0); result = 31 * result + (segments != null ? segments.hashCode() : 0); result = 31 * result + (strands != null ? strands.hashCode() : 0); result = 31 * result + (languageCodes != null ? languageCodes.hashCode() : 0); result = 31 * result + (validateCompleteness ? 1 : 0); result = 31 * result + (deleteUnansweredItems ? 1 : 0); result = 31 * result + (multiStageBraille ? 1 : 0); result = 31 * result + (grades != null ? grades.hashCode() : 0); result = 31 * result + (handScoreProjectId != null ? handScoreProjectId.hashCode() : 0); result = 31 * result + (contract != null ? contract.hashCode() : 0); result = 31 * result + (type != null ? type.hashCode() : 0); result = 31 * result + (academicYear != null ? academicYear.hashCode() : 0); result = 31 * result + (loadVersion != null ? loadVersion.hashCode() : 0); result = 31 * result + (updateVersion != null ? updateVersion.hashCode() : 0); return result; }
From source file:org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe.java
/** * A recursive function that serialize an object to a byte buffer based on its * object inspector.//from ww w.j av a 2 s. co m * * @param byteStream * the byte stream storing the serialization data * @param obj * the object to serialize * @param objInspector * the object inspector * @param skipLengthPrefix a boolean indicating whether length prefix is * needed for list/map/struct * @param warnedOnceNullMapKey a boolean indicating whether a warning * has been issued once already when encountering null map keys */ public static void serialize(RandomAccessOutput byteStream, Object obj, ObjectInspector objInspector, boolean skipLengthPrefix, BooleanRef warnedOnceNullMapKey) throws SerDeException { // do nothing for null object if (null == obj) { return; } switch (objInspector.getCategory()) { case PRIMITIVE: { PrimitiveObjectInspector poi = (PrimitiveObjectInspector) objInspector; switch (poi.getPrimitiveCategory()) { case VOID: { return; } case BOOLEAN: { boolean v = ((BooleanObjectInspector) poi).get(obj); byteStream.write((byte) (v ? 1 : 0)); return; } case BYTE: { ByteObjectInspector boi = (ByteObjectInspector) poi; byte v = boi.get(obj); byteStream.write(v); return; } case SHORT: { ShortObjectInspector spoi = (ShortObjectInspector) poi; short v = spoi.get(obj); byteStream.write((byte) (v >> 8)); byteStream.write((byte) (v)); return; } case INT: { IntObjectInspector ioi = (IntObjectInspector) poi; int v = ioi.get(obj); LazyBinaryUtils.writeVInt(byteStream, v); return; } case LONG: { LongObjectInspector loi = (LongObjectInspector) poi; long v = loi.get(obj); LazyBinaryUtils.writeVLong(byteStream, v); return; } case FLOAT: { FloatObjectInspector foi = (FloatObjectInspector) poi; int v = Float.floatToIntBits(foi.get(obj)); byteStream.write((byte) (v >> 24)); byteStream.write((byte) (v >> 16)); byteStream.write((byte) (v >> 8)); byteStream.write((byte) (v)); return; } case DOUBLE: { DoubleObjectInspector doi = (DoubleObjectInspector) poi; LazyBinaryUtils.writeDouble(byteStream, doi.get(obj)); return; } case STRING: { StringObjectInspector soi = (StringObjectInspector) poi; Text t = soi.getPrimitiveWritableObject(obj); serializeText(byteStream, t, skipLengthPrefix); return; } case CHAR: { HiveCharObjectInspector hcoi = (HiveCharObjectInspector) poi; Text t = hcoi.getPrimitiveWritableObject(obj).getTextValue(); serializeText(byteStream, t, skipLengthPrefix); return; } case VARCHAR: { HiveVarcharObjectInspector hcoi = (HiveVarcharObjectInspector) poi; Text t = hcoi.getPrimitiveWritableObject(obj).getTextValue(); serializeText(byteStream, t, skipLengthPrefix); return; } case BINARY: { BinaryObjectInspector baoi = (BinaryObjectInspector) poi; BytesWritable bw = baoi.getPrimitiveWritableObject(obj); int length = bw.getLength(); if (!skipLengthPrefix) { LazyBinaryUtils.writeVInt(byteStream, length); } else { if (length == 0) { throw new RuntimeException("LazyBinaryColumnarSerde cannot serialize a non-null zero " + "length binary field. Consider using either LazyBinarySerde or ColumnarSerde."); } } byteStream.write(bw.getBytes(), 0, length); return; } case DATE: { DateWritable d = ((DateObjectInspector) poi).getPrimitiveWritableObject(obj); writeDateToByteStream(byteStream, d); return; } case TIMESTAMP: { TimestampObjectInspector toi = (TimestampObjectInspector) poi; TimestampWritable t = toi.getPrimitiveWritableObject(obj); t.writeToByteStream(byteStream); return; } case INTERVAL_YEAR_MONTH: { HiveIntervalYearMonthWritable intervalYearMonth = ((HiveIntervalYearMonthObjectInspector) poi) .getPrimitiveWritableObject(obj); intervalYearMonth.writeToByteStream(byteStream); return; } case INTERVAL_DAY_TIME: { HiveIntervalDayTimeWritable intervalDayTime = ((HiveIntervalDayTimeObjectInspector) poi) .getPrimitiveWritableObject(obj); intervalDayTime.writeToByteStream(byteStream); return; } case DECIMAL: { HiveDecimalObjectInspector bdoi = (HiveDecimalObjectInspector) poi; HiveDecimalWritable t = bdoi.getPrimitiveWritableObject(obj); if (t == null) { return; } writeToByteStream(byteStream, t); return; } default: { throw new RuntimeException("Unrecognized type: " + poi.getPrimitiveCategory()); } } } case LIST: { ListObjectInspector loi = (ListObjectInspector) objInspector; ObjectInspector eoi = loi.getListElementObjectInspector(); int byteSizeStart = 0; int listStart = 0; if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the list // which is a integer and takes four bytes byteSizeStart = byteStream.getLength(); byteStream.reserve(4); listStart = byteStream.getLength(); } // 2/ write the size of the list as a VInt int size = loi.getListLength(obj); LazyBinaryUtils.writeVInt(byteStream, size); // 3/ write the null bytes byte nullByte = 0; for (int eid = 0; eid < size; eid++) { // set the bit to 1 if an element is not null if (null != loi.getListElement(obj, eid)) { nullByte |= 1 << (eid % 8); } // store the byte every eight elements or // if this is the last element if (7 == eid % 8 || eid == size - 1) { byteStream.write(nullByte); nullByte = 0; } } // 4/ write element by element from the list for (int eid = 0; eid < size; eid++) { serialize(byteStream, loi.getListElement(obj, eid), eoi, false, warnedOnceNullMapKey); } if (!skipLengthPrefix) { // 5/ update the list byte size int listEnd = byteStream.getLength(); int listSize = listEnd - listStart; writeSizeAtOffset(byteStream, byteSizeStart, listSize); } return; } case MAP: { MapObjectInspector moi = (MapObjectInspector) objInspector; ObjectInspector koi = moi.getMapKeyObjectInspector(); ObjectInspector voi = moi.getMapValueObjectInspector(); Map<?, ?> map = moi.getMap(obj); int byteSizeStart = 0; int mapStart = 0; if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the map // which is a integer and takes four bytes byteSizeStart = byteStream.getLength(); byteStream.reserve(4); mapStart = byteStream.getLength(); } // 2/ write the size of the map which is a VInt int size = map.size(); LazyBinaryUtils.writeVInt(byteStream, size); // 3/ write the null bytes int b = 0; byte nullByte = 0; for (Map.Entry<?, ?> entry : map.entrySet()) { // set the bit to 1 if a key is not null if (null != entry.getKey()) { nullByte |= 1 << (b % 8); } else if (warnedOnceNullMapKey != null) { if (!warnedOnceNullMapKey.value) { LOG.warn("Null map key encountered! Ignoring similar problems."); } warnedOnceNullMapKey.value = true; } b++; // set the bit to 1 if a value is not null if (null != entry.getValue()) { nullByte |= 1 << (b % 8); } b++; // write the byte to stream every 4 key-value pairs // or if this is the last key-value pair if (0 == b % 8 || b == size * 2) { byteStream.write(nullByte); nullByte = 0; } } // 4/ write key-value pairs one by one for (Map.Entry<?, ?> entry : map.entrySet()) { serialize(byteStream, entry.getKey(), koi, false, warnedOnceNullMapKey); serialize(byteStream, entry.getValue(), voi, false, warnedOnceNullMapKey); } if (!skipLengthPrefix) { // 5/ update the byte size of the map int mapEnd = byteStream.getLength(); int mapSize = mapEnd - mapStart; writeSizeAtOffset(byteStream, byteSizeStart, mapSize); } return; } case STRUCT: case UNION: { int byteSizeStart = 0; int typeStart = 0; if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the struct // which is a integer and takes four bytes byteSizeStart = byteStream.getLength(); byteStream.reserve(4); typeStart = byteStream.getLength(); } if (ObjectInspector.Category.STRUCT.equals(objInspector.getCategory())) { // 2/ serialize the struct serializeStruct(byteStream, obj, (StructObjectInspector) objInspector, warnedOnceNullMapKey); } else { // 2/ serialize the union serializeUnion(byteStream, obj, (UnionObjectInspector) objInspector, warnedOnceNullMapKey); } if (!skipLengthPrefix) { // 3/ update the byte size of the struct int typeEnd = byteStream.getLength(); int typeSize = typeEnd - typeStart; writeSizeAtOffset(byteStream, byteSizeStart, typeSize); } return; } default: { throw new RuntimeException("Unrecognized type: " + objInspector.getCategory()); } } }
From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java
@Override public int hashCode() { int result = (real != +0.0f ? Float.floatToIntBits(real) : 0); result = 31 * result + (imag != +0.0f ? Float.floatToIntBits(imag) : 0); return result; }
From source file:org.apache.pig.data.SchemaTuple.java
protected int hashCodePiece(int hash, float v, boolean isNull) { return isNull ? hash : 31 * hash + Float.floatToIntBits(v); }
From source file:haven.Utils.java
public static short hfenc(float f) { int b = Float.floatToIntBits(f); int e = (b & 0x7f800000) >> 23; int m = b & 0x007fffff; int ee;/*from w w w . j a va2 s . c om*/ if (e == 0) { ee = 0; m = 0; } else if (e == 0xff) { ee = 0x1f; } else if (e < 113) { ee = 0; m = (m | 0x00800000) >> (113 - e); } else if (e > 142) { return (((b & 0x80000000) == 0) ? ((short) 0x7c00) : ((short) 0xfc00)); } else { ee = e - 127 + 15; } int f16 = ((b >> 16) & 0x8000) | (ee << 10) | (m >> 13); return ((short) f16); }
From source file:BlendCompositeDemo.java
/** * {@inheritDoc} */ @Override public int hashCode() { return Float.floatToIntBits(alpha) * 31 + mode.ordinal(); }
From source file:org.cellprofiler.subimager.ImageWriterHandler.java
private byte[] convertImage(NDImage ndimage, PixelType pixelType, boolean toBigEndian) { double[] inputDouble = ndimage.getBuffer(); switch (pixelType) { case INT8://w ww.ja v a 2s . c o m return convertToIntegerType(inputDouble, Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.SIZE / 8, toBigEndian); case UINT8: return convertToIntegerType(inputDouble, 0, (1L << Byte.SIZE) - 1, Byte.SIZE / 8, toBigEndian); case INT16: return convertToIntegerType(inputDouble, Short.MIN_VALUE, Short.MAX_VALUE, Short.SIZE / 8, toBigEndian); case UINT16: return convertToIntegerType(inputDouble, 0, (1L << Short.SIZE) - 1, Short.SIZE / 8, toBigEndian); case INT32: return convertToIntegerType(inputDouble, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.SIZE / 8, toBigEndian); case UINT32: return convertToIntegerType(inputDouble, 0, (1L << Integer.SIZE) - 1, Integer.SIZE / 8, toBigEndian); case FLOAT: { int bpp = Float.SIZE / 8; byte[] buffer = new byte[inputDouble.length * bpp]; for (int i = 0; i < inputDouble.length; i++) { DataTools.unpackBytes(Float.floatToIntBits((float) inputDouble[i]), buffer, i * bpp, bpp, !toBigEndian); } return buffer; } case DOUBLE: { int bpp = Double.SIZE / 8; byte[] buffer = new byte[inputDouble.length * bpp]; for (int i = 0; i < inputDouble.length; i++) { DataTools.unpackBytes(Double.doubleToLongBits(inputDouble[i]), buffer, i * bpp, bpp, !toBigEndian); } return buffer; } default: throw new UnsupportedOperationException("The pixel type, " + pixelType.getValue() + ", should have been explicitly handled by the caller and an error should have been reported to the web client."); } }