@SuppressWarnings("unchecked") public <V extends BValue> V getZeroValue() { return (V) new BFloat(0); }
private Object castFloat(BFloat jValue, Class<?> targetType) { if ((targetType == Float.class || targetType == float.class)) { return (float) jValue.floatValue(); } return jValue.floatValue(); }
/** * Convert JSON to decimal. * * @param json JSON to be converted * @return BDecimal value of the JSON, if it's a valid convertible JSON node. Error, otherwise. */ private static BDecimal jsonNodeToDecimal(BValue json) { if (json == null || (json.getType().getTag() != TypeTags.INT_TAG && json.getType().getTag() != TypeTags.FLOAT_TAG && json.getType().getTag() != TypeTags.DECIMAL_TAG)) { throw BLangExceptionHelper.getRuntimeException(RuntimeErrors.INCOMPATIBLE_TYPE_FOR_CASTING_JSON, BTypes.typeDecimal, getTypeName(json)); } if (json.getType().getTag() == TypeTags.INT_TAG) { return new BDecimal(((BInteger) json).decimalValue()); } else if (json.getType().getTag() == TypeTags.FLOAT_TAG) { return new BDecimal(((BFloat) json).decimalValue()); } return (BDecimal) json; }
floatValues = (double[]) newArrayInstance(Double.TYPE); for (int i = 0; i < this.size(); i++) { floatValues[i] = ((BFloat) arrayValues[i]).value();
@Override public <V extends BValue> V getEmptyValue() { return (V) new BFloat(0); }
@Override public double getFloatField(String fieldName) { return ((BFloat) value.get(fieldName)).floatValue(); }
public void execute(Context ctx) { ctx.setReturnValues(new BFloat(Math.random())); } }
private static void setParam(PreparedStatement stmt, BValue value, BType bType, int index, boolean isKey) throws SQLException { int type = bType.getTag(); switch (type) { case TypeTags.INT_TAG: stmt.setLong(index, ((BInteger) value).intValue()); break; case TypeTags.STRING_TAG: stmt.setString(index, value.stringValue()); break; case TypeTags.FLOAT_TAG: stmt.setDouble(index, ((BFloat) value).floatValue()); break; case TypeTags.BOOLEAN_TAG: stmt.setBoolean(index, ((BBoolean) value).booleanValue()); break; case TypeTags.BYTE_TAG: stmt.setByte(index, ((BByte) value).byteValue()); break; default: if (isKey && value instanceof BMap) { stmt.setString(index, sortBMap(((BMap) value).getMap())); } else { stmt.setString(index, value.toString()); } } }
public void execute(Context ctx) { double value = ctx.getFloatArgument(0); ctx.setReturnValues(new BFloat(Math.sqrt(value))); } }
private static BValueArray jsonArrayToBFloatArray(BValueArray arrayNode) { BValueArray floatArray = new BValueArray(BTypes.typeFloat); for (int i = 0; i < arrayNode.size(); i++) { BRefType<?> jsonValue = arrayNode.getRefValue(i); floatArray.add(i, ((BFloat) convertJSON(jsonValue, BTypes.typeFloat)).floatValue()); } return floatArray; }
public void execute(Context ctx) { double value = ctx.getFloatArgument(0); ctx.setReturnValues(new BFloat(Math.atan(value))); } }
break; case TypeTags.FLOAT_TAG: stmt.setDouble(index, ((BFloat) constrainedType.get(fieldName)).floatValue()); break; case TypeTags.BOOLEAN_TAG:
public void execute(Context ctx) { double value = ctx.getFloatArgument(0); ctx.setReturnValues(new BFloat(Math.cos(value))); } }
public static void copyArgValueForWorkerReceive(StackFrame currentSF, int regIndex, BType paramType, BRefType passedInValue) { switch (paramType.getTag()) { case TypeTags.INT_TAG: currentSF.longRegs[regIndex] = ((BInteger) passedInValue).intValue(); break; case TypeTags.BYTE_TAG: currentSF.intRegs[regIndex] = ((BByte) passedInValue).byteValue(); break; case TypeTags.FLOAT_TAG: currentSF.doubleRegs[regIndex] = ((BFloat) passedInValue).floatValue(); break; case TypeTags.STRING_TAG: currentSF.stringRegs[regIndex] = (passedInValue).stringValue(); break; case TypeTags.BOOLEAN_TAG: currentSF.intRegs[regIndex] = (((BBoolean) passedInValue).booleanValue()) ? 1 : 0; break; default: currentSF.refRegs[regIndex] = passedInValue; } }
public void execute(Context ctx) { double value = ctx.getFloatArgument(0); ctx.setReturnValues(new BFloat(Math.abs(value))); } }
private Object[] createEvent(BMap<String, BValue> data) { BStructureType streamType = (BStructureType) data.getType(); Object[] event = new Object[streamType.getFields().size()]; int index = 0; for (Map.Entry<String, BField> fieldEntry : streamType.getFields().entrySet()) { BField field = fieldEntry.getValue(); switch (field.getFieldType().getTag()) { case TypeTags.INT_TAG: event[index++] = ((BInteger) data.get(field.fieldName)).intValue(); break; case TypeTags.FLOAT_TAG: event[index++] = ((BFloat) data.get(field.fieldName)).floatValue(); break; case TypeTags.BOOLEAN_TAG: event[index++] = ((BBoolean) data.get(field.fieldName)).booleanValue(); break; case TypeTags.STRING_TAG: event[index++] = data.get(field.fieldName).stringValue(); break; default: throw new BallerinaException("Fields in streams do not support data types other than int, " + "float, boolean and string"); } } return event; }
public void execute(Context ctx) { double value = ctx.getFloatArgument(0); ctx.setReturnValues(new BFloat(Math.rint(value))); } }
break; case TypeTags.FLOAT_TAG: structData[i] = ((BFloat) bValue).floatValue(); break; case TypeTags.STRING_TAG:
public void execute(Context ctx) { double value = ctx.getFloatArgument(0); ctx.setReturnValues(new BFloat(Math.log10(value))); } }