List of usage examples for java.lang Number floatValue
public abstract float floatValue();
From source file:org.nd4j.linalg.cpu.complex.ComplexFloat.java
@Override public IComplexNumber muli(Number v, IComplexNumber result) { return result.set(result.realComponent().floatValue() * v.floatValue(), result.imaginaryComponent().floatValue() * v.floatValue()); }
From source file:org.nd4j.linalg.cpu.complex.ComplexFloat.java
@Override public IComplexNumber divi(Number v, IComplexNumber result) { return result.set(result.realComponent().floatValue() / v.floatValue(), imaginaryComponent() / v.floatValue()); }
From source file:org.nd4j.linalg.cpu.complex.ComplexFloat.java
/** * Add a realComponent number to a complex number in-place. * * @param a// w w w. ja v a 2 s. c om * @param result */ @Override public IComplexNumber addi(Number a, IComplexNumber result) { return result.set(result.realComponent().floatValue() + a.floatValue(), result.imaginaryComponent().floatValue()); }
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatImportHelper.java
private Object convertNumberTypes(Object val, HCatFieldSchema hfs) { HCatFieldSchema.Type hfsType = hfs.getType(); if (!(val instanceof Number)) { return null; }//from ww w. j ava2 s .c om if (val instanceof BigDecimal && hfsType == HCatFieldSchema.Type.STRING || hfsType == HCatFieldSchema.Type.VARCHAR || hfsType == HCatFieldSchema.Type.CHAR) { BigDecimal bd = (BigDecimal) val; String bdStr = null; if (bigDecimalFormatString) { bdStr = bd.toPlainString(); } else { bdStr = bd.toString(); } if (hfsType == HCatFieldSchema.Type.VARCHAR) { VarcharTypeInfo vti = (VarcharTypeInfo) hfs.getTypeInfo(); HiveVarchar hvc = new HiveVarchar(bdStr, vti.getLength()); return hvc; } else if (hfsType == HCatFieldSchema.Type.VARCHAR) { CharTypeInfo cti = (CharTypeInfo) hfs.getTypeInfo(); HiveChar hChar = new HiveChar(bdStr, cti.getLength()); return hChar; } else { return bdStr; } } Number n = (Number) val; if (hfsType == HCatFieldSchema.Type.TINYINT) { return n.byteValue(); } else if (hfsType == HCatFieldSchema.Type.SMALLINT) { return n.shortValue(); } else if (hfsType == HCatFieldSchema.Type.INT) { return n.intValue(); } else if (hfsType == HCatFieldSchema.Type.BIGINT) { return n.longValue(); } else if (hfsType == HCatFieldSchema.Type.FLOAT) { return n.floatValue(); } else if (hfsType == HCatFieldSchema.Type.DOUBLE) { return n.doubleValue(); } else if (hfsType == HCatFieldSchema.Type.BOOLEAN) { return n.byteValue() == 0 ? Boolean.FALSE : Boolean.TRUE; } else if (hfsType == HCatFieldSchema.Type.STRING) { return n.toString(); } else if (hfsType == HCatFieldSchema.Type.VARCHAR) { VarcharTypeInfo vti = (VarcharTypeInfo) hfs.getTypeInfo(); HiveVarchar hvc = new HiveVarchar(val.toString(), vti.getLength()); return hvc; } else if (hfsType == HCatFieldSchema.Type.CHAR) { CharTypeInfo cti = (CharTypeInfo) hfs.getTypeInfo(); HiveChar hChar = new HiveChar(val.toString(), cti.getLength()); return hChar; } else if (hfsType == HCatFieldSchema.Type.DECIMAL) { BigDecimal bd = new BigDecimal(n.doubleValue(), MathContext.DECIMAL128); return HiveDecimal.create(bd); } return null; }
From source file:org.cloudgraph.hbase.results.ResultsAggregator.java
private void computeAverages(PlasmaDataGraph graph) { CoreNode existingNode = (CoreNode) graph.getRootObject(); int existingCount = (Integer) existingNode.getValueObject().get(PROPERTY_NAME_GROUP_HITS); for (FunctionPath funcPath : funcPaths) { if (!funcPath.getFunc().getName().isAggreate()) throw new GraphServiceException("expected aggregate function not, " + funcPath.getFunc().getName()); DataType scalarType = funcPath.getFunc().getName().getScalarDatatype(funcPath.getDataType()); switch (funcPath.getFunc().getName()) { case AVG: PlasmaDataObject existingEndpoint = null; if (funcPath.getPath().size() == 0) { existingEndpoint = (PlasmaDataObject) graph.getRootObject(); } else { existingEndpoint = (PlasmaDataObject) graph.getRootObject() .getDataObject(funcPath.getPath().toString()); }/*from w ww . ja v a 2s . com*/ Number existingFuncValue = (Number) existingEndpoint.get(funcPath.getFunc().getName(), funcPath.getProperty()); switch (scalarType) { case Double: Double doubleAvg = existingFuncValue.doubleValue() / existingCount; existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), doubleAvg); break; case Float: Float floatAvg = existingFuncValue.floatValue() / existingCount; existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), floatAvg); break; default: throw new IllegalArgumentException("illsgal datatype (" + scalarType + ") conversion for function, " + funcPath.getFunc().getName()); } default: break; } } }
From source file:com.facebook.stetho.json.ObjectMapper.java
private Object getValueForField(Field field, Object value) throws JSONException { try {/*www .j a v a 2s . c o m*/ if (value != null) { if (value == JSONObject.NULL) { return null; } if (value.getClass() == field.getType()) { return value; } if (value instanceof JSONObject) { return convertValue(value, field.getType()); } else { if (field.getType().isEnum()) { return getEnumValue((String) value, field.getType().asSubclass(Enum.class)); } else if (value instanceof JSONArray) { return convertArrayToList(field, (JSONArray) value); } else if (value instanceof Number) { // Need to convert value to Number This happens because json treats 1 as an Integer even // if the field is supposed to be a Long Number numberValue = (Number) value; Class<?> clazz = field.getType(); if (clazz == Integer.class || clazz == int.class) { return numberValue.intValue(); } else if (clazz == Long.class || clazz == long.class) { return numberValue.longValue(); } else if (clazz == Double.class || clazz == double.class) { return numberValue.doubleValue(); } else if (clazz == Float.class || clazz == float.class) { return numberValue.floatValue(); } else if (clazz == Byte.class || clazz == byte.class) { return numberValue.byteValue(); } else if (clazz == Short.class || clazz == short.class) { return numberValue.shortValue(); } else { throw new IllegalArgumentException("Not setup to handle class " + clazz.getName()); } } } } } catch (IllegalAccessException e) { throw new IllegalArgumentException("Unable to set value for field " + field.getName(), e); } return value; }
From source file:net.solarnetwork.node.power.impl.sma.sunnynet.SMASunnyNetPowerDatumDataSource.java
@Override public GeneralNodeACEnergyDatum conductConversation(ConversationalDataCollector dataCollector) { SmaPacket req = null;/*from w ww. j a v a2s. c o m*/ SmaPacket resp = null; if (this.smaAddress < 0 || this.channelMap == null) { // Issue NetStart command to find SMA address req = writeCommand(dataCollector, SmaCommand.NetStart, 0, 0, SmaControl.RequestGroup, SmaPacket.EMPTY_DATA); resp = decodeResponse(dataCollector, req); if (log.isTraceEnabled()) { log.trace("Got decoded NetStart response: " + resp); } if (!resp.isValid()) { log.warn("Invalid response to NetStart command, cannot continue: " + resp); return null; } // TODO handle multiple device responses, for now we only accept one // Issue GetChannelInfo command, to get full list of available channels // This returns a lot of data... so we just do it once and cache the // results for subsequent use this.smaAddress = resp.getSrcAddress(); req = writeCommand(dataCollector, SmaCommand.GetChannelInfo, this.smaAddress, 0, SmaControl.RequestSingle, SmaPacket.EMPTY_DATA); resp = decodeResponse(dataCollector, req); if (!resp.isValid()) { log.warn("Invalid response to GetChannelInfo command, cannot continue: " + resp); return null; } Map<String, SmaChannel> channels = getSmaChannelMap(resp); if (log.isTraceEnabled()) { log.trace("Got decoded GetChannelInfo response: " + resp + ", with " + channels.size() + " channels decoded"); } this.channelMap = channels; } // Issue SynOnline command int pollTime = (int) Math.ceil(System.currentTimeMillis() / 1000.0); req = writeProclamation(dataCollector, SmaCommand.SynOnline, 0, 0, SmaControl.RequestGroup, SmaUtils.littleEndianBytes(pollTime)); // pause for a few secs, as first channel may not respond otherwise try { Thread.sleep(this.synOnlineWaitMs); } catch (InterruptedException e) { // ignore this one } GeneralNodeACEnergyDatum datum = new GeneralNodeACEnergyDatum(); datum.setSourceId(this.sourceId); // Issue GetData command for each channel we're interested in Number pvVolts = getNumericDataValue(dataCollector, this.pvVoltsChannelName, Float.class); Number pvAmps = getNumericDataValue(dataCollector, this.pvAmpsChannelName, Float.class); if (pvVolts != null && pvAmps != null) { datum.setWatts(Math.round(pvVolts.floatValue() * pvAmps.floatValue())); } Number wh = getNumericDataValue(dataCollector, this.kWhChannelName, Double.class); if (wh != null) { datum.setWattHourReading(wh.longValue()); } return datum; }
From source file:org.appcelerator.titanium.TiBlob.java
@Kroll.method public TiBlob imageAsThumbnail(Number size, @Kroll.argument(optional = true) Number borderSize, @Kroll.argument(optional = true) Number cornerRadius) { Bitmap img = getImage();//from w ww . j a v a 2 s.c o m if (img == null) { return null; } int thumbnailSize = size.intValue(); Bitmap imageThumbnail = ThumbnailUtils.extractThumbnail(img, thumbnailSize, thumbnailSize); float border = 1f; if (borderSize != null) { border = borderSize.floatValue(); } float radius = 0f; if (cornerRadius != null) { radius = cornerRadius.floatValue(); } if (border == 0 && radius == 0) { return blobFromImage(imageThumbnail); } Bitmap imageThumbnailBorder = TiImageHelper.imageWithRoundedCorner(imageThumbnail, radius, border); return blobFromImage(imageThumbnailBorder); }
From source file:IntRange.java
/** * <p>Tests whether the specified <code>Number</code> occurs within * this range using <code>float</code> comparison.</p> * //from w w w . jav a 2 s.c o m * <p><code>null</code> is handled and returns <code>false</code>.</p> * * <p>This implementation forwards to the {@link #containsFloat(float)} method.</p> * * @param value the float to test, may be <code>null</code> * @return <code>true</code> if the specified number occurs within this * range by <code>float</code> comparison */ public boolean containsFloat(Number value) { if (value == null) { return false; } return containsFloat(value.floatValue()); }
From source file:com.tibbo.linkserver.plugin.device.file.item.NumericItem.java
public short[] valueToShorts(Number value) { if (dataType == 2 || dataType == 3) { return (new short[] { toShort(value) }); }//from w w w .j a v a 2s .c o m if (dataType == 16) { short s = toShort(value); return (new short[] { (short) ((s / 1000) % 10 << 12 | (s / 100) % 10 << 8 | (s / 10) % 10 << 4 | s % 10) }); } if (dataType == 4 || dataType == 5) { int i = toInt(value); return (new short[] { (short) (i >> 16), (short) i }); } if (dataType == 6 || dataType == 7) { int i = toInt(value); return (new short[] { (short) i, (short) (i >> 16) }); } if (dataType == 8) { int i = Float.floatToIntBits(value.floatValue()); return (new short[] { (short) (i >> 16), (short) i }); } if (dataType == 9) { int i = Float.floatToIntBits(value.floatValue()); return (new short[] { (short) i, (short) (i >> 16) }); } if (dataType == 17) { int i = toInt(value); return (new short[] { (short) ((i / 0x989680) % 10 << 12 | (i / 0xf4240) % 10 << 8 | (i / 0x186a0) % 10 << 4 | (i / 10000) % 10), (short) ((i / 1000) % 10 << 12 | (i / 100) % 10 << 8 | (i / 10) % 10 << 4 | i % 10) }); } if (dataType == 10 || dataType == 11) { long l = value.longValue(); return (new short[] { (short) (int) (l >> 48), (short) (int) (l >> 32), (short) (int) (l >> 16), (short) (int) l }); } if (dataType == 12 || dataType == 13) { long l = value.longValue(); return (new short[] { (short) (int) l, (short) (int) (l >> 16), (short) (int) (l >> 32), (short) (int) (l >> 48) }); } if (dataType == 14) { long l = Double.doubleToLongBits(value.doubleValue()); return (new short[] { (short) (int) (l >> 48), (short) (int) (l >> 32), (short) (int) (l >> 16), (short) (int) l }); } if (dataType == 15) { long l = Double.doubleToLongBits(value.doubleValue()); return (new short[] { (short) (int) l, (short) (int) (l >> 16), (short) (int) (l >> 32), (short) (int) (l >> 48) }); } else { throw new RuntimeException( (new StringBuilder()).append("Unsupported data type: ").append(dataType).toString()); } }