List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:org.processmining.analysis.performance.PerformanceAnalysisGUI.java
/** * Adds the particular time-metrics for the highlevelactivity of a * transition to the simulation model./*from w w w . j ava 2 s. c o m*/ * * @param kindTimingInfo * String <code>"waiting"</code> when the provided time-metrics * deal about waiting time. <code>execution</code> when the * provided time-metrics deal about execution time and * <code>"sojourn"</code> when the provided time-metrics deal * about sojourn time * @param activity * HLActivity the highlevelactivity of a transition * @param mean * double the mean * @param min * double the minimum * @param max * double the maximum * @param stDev * double the standard deviation * @param constVal * double the constant value * @param arrivalRate * double the arrival rate */ private void addTimingInfoForTransition(String kindTimingInfo, HLActivity activity, double mean, double min, double max, double stDev, double constVal, double arrivalRate) { // in case that NaN is provided for either mean, min, max or stDev the // default value needs to be used double constFinal = 0.0; double meanFinal = 0.0; double varianceFinal = 0.0; double minFinal = 0.0; double maxFinal = 0.0; double intensityFinal = 0.0; if (!(Double.isNaN(mean) || Double.isInfinite(mean))) { meanFinal = mean; } if (!(Double.isNaN(min) || Double.isInfinite(min))) { minFinal = min; } if (!(Double.isNaN(max) || Double.isInfinite(max))) { maxFinal = max; } if (!(Double.isNaN(stDev) || Double.isInfinite(stDev))) { varianceFinal = stDev * stDev; } if (!(Double.isNaN(constVal) || Double.isInfinite(constVal))) { constFinal = constVal; } if (!(Double.isNaN(arrivalRate) || Double.isInfinite(arrivalRate))) { intensityFinal = arrivalRate; } HLGeneralDistribution dist = new HLGeneralDistribution(constFinal, meanFinal, varianceFinal, minFinal, maxFinal, intensityFinal, HLDistribution.DistributionEnum.NORMAL_DISTRIBUTION); if (kindTimingInfo.equals("waiting")) { activity.setWaitingTime(dist); } else if (kindTimingInfo.equals("execution")) { activity.setExecutionTime(dist); } else if (kindTimingInfo.equals("sojourn")) { activity.setSojournTime(dist); } }
From source file:org.ballerinalang.bre.bvm.BVM.java
private static void execTypeConversionOpcodes(Strand ctx, StackFrame sf, int opcode, int[] operands) { int i;//from w ww .j a v a 2s .c o m int j; BRefType bRefType; String str; switch (opcode) { case InstructionCodes.I2F: i = operands[0]; j = operands[1]; sf.doubleRegs[j] = sf.longRegs[i]; break; case InstructionCodes.I2S: i = operands[0]; j = operands[1]; sf.stringRegs[j] = Long.toString(sf.longRegs[i]); break; case InstructionCodes.I2B: i = operands[0]; j = operands[1]; sf.intRegs[j] = sf.longRegs[i] != 0 ? 1 : 0; break; case InstructionCodes.I2D: i = operands[0]; j = operands[1]; sf.refRegs[j] = new BDecimal((new BigDecimal(sf.longRegs[i], MathContext.DECIMAL128)).setScale(1, BigDecimal.ROUND_HALF_EVEN)); break; case InstructionCodes.I2BI: i = operands[0]; j = operands[1]; if (!isByteLiteral(sf.longRegs[i])) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "'" + TypeConstants.INT_TNAME + "' value '" + sf.longRegs[i] + "' cannot be converted to '" + TypeConstants.BYTE_TNAME + "'")); handleError(ctx); break; } sf.longRegs[j] = sf.longRegs[i]; break; case InstructionCodes.F2BI: i = operands[0]; j = operands[1]; double floatVal = sf.doubleRegs[i]; if (Double.isNaN(floatVal) || Double.isInfinite(floatVal)) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "'" + TypeConstants.FLOAT_TNAME + "' value '" + floatVal + "' cannot be converted to '" + TypeConstants.BYTE_TNAME + "'")); handleError(ctx); break; } long floatAsIntVal = Math.round(floatVal); if (!isByteLiteral(floatAsIntVal)) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "'" + TypeConstants.FLOAT_TNAME + "' value '" + floatVal + "' cannot be converted to '" + TypeConstants.BYTE_TNAME + "'")); handleError(ctx); break; } sf.longRegs[j] = floatAsIntVal; break; case InstructionCodes.D2BI: i = operands[0]; j = operands[1]; DecimalValueKind valueKind = ((BDecimal) sf.refRegs[i]).valueKind; if (valueKind == DecimalValueKind.NOT_A_NUMBER || valueKind == DecimalValueKind.NEGATIVE_INFINITY || valueKind == DecimalValueKind.POSITIVE_INFINITY) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "'" + TypeConstants.DECIMAL_TNAME + "' value '" + sf.refRegs[i] + "' cannot be converted to '" + TypeConstants.BYTE_TNAME + "'")); handleError(ctx); break; } long doubleAsIntVal = Math.round(((BDecimal) sf.refRegs[i]).floatValue()); if (!isByteLiteral(doubleAsIntVal)) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "'" + TypeConstants.DECIMAL_TNAME + "' value '" + sf.refRegs[i] + "' cannot be converted to '" + TypeConstants.BYTE_TNAME + "'")); handleError(ctx); break; } sf.longRegs[j] = doubleAsIntVal; break; case InstructionCodes.F2I: i = operands[0]; j = operands[1]; double valueToConvert = sf.doubleRegs[i]; if (Double.isNaN(valueToConvert) || Double.isInfinite(valueToConvert)) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "'" + TypeConstants.FLOAT_TNAME + "' value '" + valueToConvert + "' cannot be converted to '" + TypeConstants.INT_TNAME + "'")); handleError(ctx); break; } if (!isFloatWithinIntRange(valueToConvert)) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "out " + "of range '" + TypeConstants.FLOAT_TNAME + "' value '" + valueToConvert + "' cannot be converted to '" + TypeConstants.INT_TNAME + "'")); handleError(ctx); break; } sf.longRegs[j] = Math.round(valueToConvert); break; case InstructionCodes.F2S: i = operands[0]; j = operands[1]; sf.stringRegs[j] = Double.toString(sf.doubleRegs[i]); break; case InstructionCodes.F2B: i = operands[0]; j = operands[1]; sf.intRegs[j] = sf.doubleRegs[i] != 0.0 ? 1 : 0; break; case InstructionCodes.F2D: i = operands[0]; j = operands[1]; sf.refRegs[j] = new BDecimal(new BigDecimal(sf.doubleRegs[i], MathContext.DECIMAL128)); break; case InstructionCodes.S2I: i = operands[0]; j = operands[1]; str = sf.stringRegs[i]; try { sf.refRegs[j] = new BInteger(Long.parseLong(str)); } catch (NumberFormatException e) { handleTypeConversionError(ctx, sf, j, TypeConstants.STRING_TNAME, TypeConstants.INT_TNAME); } break; case InstructionCodes.S2F: i = operands[0]; j = operands[1]; str = sf.stringRegs[i]; try { sf.refRegs[j] = new BFloat(Double.parseDouble(str)); } catch (NumberFormatException e) { handleTypeConversionError(ctx, sf, j, TypeConstants.STRING_TNAME, TypeConstants.FLOAT_TNAME); } break; case InstructionCodes.S2B: i = operands[0]; j = operands[1]; sf.intRegs[j] = Boolean.parseBoolean(sf.stringRegs[i]) ? 1 : 0; break; case InstructionCodes.S2D: i = operands[0]; j = operands[1]; str = sf.stringRegs[i]; try { sf.refRegs[j] = new BDecimal(new BigDecimal(str, MathContext.DECIMAL128)); } catch (NumberFormatException e) { handleTypeConversionError(ctx, sf, j, TypeConstants.STRING_TNAME, TypeConstants.DECIMAL_TNAME); } break; case InstructionCodes.B2I: i = operands[0]; j = operands[1]; sf.longRegs[j] = sf.intRegs[i]; break; case InstructionCodes.B2F: i = operands[0]; j = operands[1]; sf.doubleRegs[j] = sf.intRegs[i]; break; case InstructionCodes.B2S: i = operands[0]; j = operands[1]; sf.stringRegs[j] = sf.intRegs[i] == 1 ? "true" : "false"; break; case InstructionCodes.B2D: i = operands[0]; j = operands[1]; sf.refRegs[j] = sf.intRegs[i] == 1 ? new BDecimal(BigDecimal.ONE.setScale(1, BigDecimal.ROUND_HALF_EVEN)) : new BDecimal(BigDecimal.ZERO.setScale(1, BigDecimal.ROUND_HALF_EVEN)); break; case InstructionCodes.D2I: i = operands[0]; j = operands[1]; BDecimal decimal = (BDecimal) sf.refRegs[i]; DecimalValueKind decValueKind = decimal.valueKind; if (decValueKind == DecimalValueKind.NOT_A_NUMBER || decValueKind == DecimalValueKind.NEGATIVE_INFINITY || decValueKind == DecimalValueKind.POSITIVE_INFINITY) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "'" + TypeConstants.DECIMAL_TNAME + "' value '" + sf.refRegs[i] + "' cannot be converted to '" + TypeConstants.INT_TNAME + "'")); handleError(ctx); break; } if (!isDecimalWithinIntRange((decimal.decimalValue()))) { ctx.setError(BLangVMErrors.createError(ctx, BallerinaErrorReasons.NUMBER_CONVERSION_ERROR, "out of range '" + TypeConstants.DECIMAL_TNAME + "' value '" + decimal + "' cannot be converted to '" + TypeConstants.INT_TNAME + "'")); handleError(ctx); break; } sf.longRegs[j] = Math.round(((BDecimal) sf.refRegs[i]).decimalValue().doubleValue()); break; case InstructionCodes.D2F: i = operands[0]; j = operands[1]; sf.doubleRegs[j] = ((BDecimal) sf.refRegs[i]).floatValue(); break; case InstructionCodes.D2S: i = operands[0]; j = operands[1]; sf.stringRegs[j] = sf.refRegs[i].stringValue(); break; case InstructionCodes.D2B: i = operands[0]; j = operands[1]; sf.intRegs[j] = ((BDecimal) sf.refRegs[i]).decimalValue().compareTo(BigDecimal.ZERO) != 0 ? 1 : 0; break; case InstructionCodes.DT2XML: i = operands[0]; j = operands[1]; bRefType = sf.refRegs[i]; if (bRefType == null) { handleTypeConversionError(ctx, sf, j, BTypes.typeNull, BTypes.typeXML); break; } try { sf.refRegs[j] = XMLUtils.tableToXML((BTable) bRefType); } catch (Exception e) { sf.refRegs[j] = null; handleTypeConversionError(ctx, sf, j, TypeConstants.TABLE_TNAME, TypeConstants.XML_TNAME); } break; case InstructionCodes.DT2JSON: i = operands[0]; j = operands[1]; bRefType = sf.refRegs[i]; if (bRefType == null) { handleNullRefError(ctx); break; } try { sf.refRegs[j] = JSONUtils.toJSON((BTable) bRefType); } catch (Exception e) { handleTypeConversionError(ctx, sf, j, TypeConstants.TABLE_TNAME, TypeConstants.XML_TNAME); } break; case InstructionCodes.T2MAP: convertStructToMap(ctx, operands, sf); break; case InstructionCodes.T2JSON: convertStructToJSON(ctx, operands, sf); break; case InstructionCodes.MAP2JSON: convertMapToJSON(ctx, operands, sf); break; case InstructionCodes.JSON2MAP: convertJSONToMap(ctx, operands, sf); break; case InstructionCodes.MAP2T: convertMapToStruct(ctx, operands, sf); break; case InstructionCodes.JSON2T: convertJSONToStruct(ctx, operands, sf); break; case InstructionCodes.XMLATTRS2MAP: i = operands[0]; j = operands[1]; bRefType = sf.refRegs[i]; sf.refRegs[j] = ((BXMLAttributes) sf.refRegs[i]).value(); break; case InstructionCodes.XML2S: i = operands[0]; j = operands[1]; sf.stringRegs[j] = sf.refRegs[i].stringValue(); break; case InstructionCodes.ANY2SCONV: i = operands[0]; j = operands[1]; bRefType = sf.refRegs[i]; if (bRefType == null) { sf.stringRegs[j] = STRING_NULL_VALUE; } else { sf.stringRegs[j] = bRefType.stringValue(); } break; default: throw new UnsupportedOperationException(); } }
From source file:gda.plots.SimplePlot.java
/** * @param collection/* w ww . ja v a2 s . com*/ * @param includeInterval * @return range for the range axis Y */ public Range getRangeBounds(SimpleXYSeriesCollection collection, @SuppressWarnings("unused") boolean includeInterval) { if (!isTurboMode()) return null; Range domainBounds = null; Range rangeBounds = null; if (collection == leftSeriesCollection) { domainBounds = leftDomainBounds; rangeBounds = leftRangeBounds; } else if (collection == rightSeriesCollection) { domainBounds = rightDomainBounds; rangeBounds = rightRangeBounds; } if (rangeBounds != null) return rangeBounds; Double min = Double.POSITIVE_INFINITY; Double max = Double.NEGATIVE_INFINITY; if (isStripMode()) { synchronized (linesChanged) { if (linesChanged.size() == 0) return null; Iterator<Integer> iter = linesChanged.iterator(); while (iter.hasNext()) { SimpleXYSeries sxys = collection.find(iter.next()); // is it in this collection? if (sxys != null && sxys.isVisible()) { Double sxys_min, sxys_max; Double sxys_Xmax = sxys.getMaxX(); if (Double.isInfinite(sxys_Xmax)) return null; /* * create range in data units over which we want to get the y min and max */ SimpleValueTransformer valTrans = collection.getXValueTransformer(); Double maxXTransformed = valTrans.transformValue(sxys_Xmax); double minX = valTrans.transformValueBack(maxXTransformed - stripWidth); Double[] extents = sxys.getBounds(new Range(minX, sxys_Xmax)); sxys_min = extents[2]; sxys_max = extents[3]; if (Double.isInfinite(sxys_min) || Double.isInfinite(sxys_max)) return null; min = Math.min(min, sxys_min); max = Math.max(max, sxys_max); } } } } else { for (Object obj : collection.getSeries()) { if (obj != null && obj instanceof SimpleXYSeries) { SimpleXYSeries sxys = (SimpleXYSeries) obj; if (sxys.isVisible()) { if (domainBounds == null) { double sxys_min, sxys_max; sxys_min = sxys.getMinY(); sxys_max = sxys.getMaxY(); min = Math.min(min, sxys_min); max = Math.max(max, sxys_max); } else { double sxys_min, sxys_max; Double[] extents = sxys.getBounds(domainBounds); sxys_min = extents[2]; sxys_max = extents[3]; if (Double.isInfinite(sxys_min) || Double.isInfinite(sxys_max)) return null; min = Math.min(min, sxys_min); max = Math.max(max, sxys_max); } } } } } if (Double.isInfinite(min) || Double.isInfinite(max)) return null; Range newRange = new Range(min, max); if (collection == leftSeriesCollection) lastRangeBoundsLeft = newRange; if (collection == rightSeriesCollection) lastRangeBoundsRight = newRange; return newRange; }
From source file:gda.plots.SimplePlot.java
/** * @param collection//w ww .j a v a2 s . c om * @param includeInterval * @return range for the domain axis X */ public Range getDomainBounds(SimpleXYSeriesCollection collection, @SuppressWarnings("unused") boolean includeInterval) { Double min = Double.POSITIVE_INFINITY; Double max = Double.NEGATIVE_INFINITY; if (!isTurboMode()) return null; if (collection == leftSeriesCollection && leftDomainBounds != null) return leftDomainBounds; if (collection == rightSeriesCollection && rightDomainBounds != null) return rightDomainBounds; if (isStripMode()) { /* * In stripMode get max of changed lines - min will be the max minus the stripWidth */ synchronized (linesChanged) { if (linesChanged.size() == 0) return null; Iterator<Integer> iter = linesChanged.iterator(); while (iter.hasNext()) { SimpleXYSeries sxys = collection.find(iter.next()); // is it in this collection? if (sxys != null && sxys.isVisible()) { double sxys_max; sxys_max = sxys.getMaxX(); max = Math.max(max, sxys_max); } } min = max; //we remove the stripWidth later as stripWidth is in final units after transformation } } else { /* * go through all visible lines are get min and max */ for (Object obj : collection.getSeries()) { if (obj != null && obj instanceof SimpleXYSeries) { SimpleXYSeries sxys = (SimpleXYSeries) obj; if (sxys.isVisible()) { double sxys_min, sxys_max; sxys_min = sxys.getMinX(); sxys_max = sxys.getMaxX(); min = Math.min(min, sxys_min); max = Math.max(max, sxys_max); } } } } if (Double.isInfinite(min) || Double.isInfinite(max)) return null; SimpleValueTransformer valTrans = collection.getXValueTransformer(); Double maxTransformed = valTrans.transformValue(max); Double minTransformed = stripWidth != null ? maxTransformed - stripWidth : valTrans.transformValue(min); Range newRange = new Range(minTransformed, maxTransformed); if (collection == leftSeriesCollection) lastDomainBoundsLeft = newRange; if (collection == rightSeriesCollection) lastDomainBoundsRight = newRange; return newRange; }
From source file:com.cloud.hypervisor.xen.resource.CitrixResourceBase.java
protected double getDataAverage(Node dataNode, int col, int numRows) { double value = 0; double dummy = 0; int numRowsUsed = 0; for (int row = 0; row < numRows; row++) { Node data = dataNode.getChildNodes().item(numRows - 1 - row).getChildNodes().item(col + 1); Double currentDataAsDouble = Double.valueOf(getXMLNodeValue(data)); if (!currentDataAsDouble.equals(Double.NaN)) { numRowsUsed += 1;/*w ww .j a va 2s. c o m*/ value += currentDataAsDouble; } } if (numRowsUsed == 0) { if ((!Double.isInfinite(value)) && (!Double.isNaN(value))) { return value; } else { s_logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows=0"); return dummy; } } else { if ((!Double.isInfinite(value / numRowsUsed)) && (!Double.isNaN(value / numRowsUsed))) { return (value / numRowsUsed); } else { s_logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows>0"); return dummy; } } }
From source file:ffx.numerics.MultipoleTensor.java
public static void main(String args[]) { if (args == null || args.length < 4) { logger.info(" Usage: java ffx.numerics.MultipoleTensor order dx dy dz"); }//w w w . ja v a2 s .c om int order = Integer.parseInt(args[0]); double dx = Double.parseDouble(args[1]); double dy = Double.parseDouble(args[2]); double dz = Double.parseDouble(args[3]); double r[] = { dx, dy, dz }; double n2 = 710643; double cycles = 10; logger.info(format(" 6th Order Tensor Count: %d", tensorCount(6))); MultipoleTensor multipoleTensor = new MultipoleTensor(OPERATOR.SCREENED_COULOMB, COORDINATES.GLOBAL, order, 1e-6); double[] Fi = new double[3]; double[] Ti = new double[3]; double[] Tk = new double[3]; double[] Qi = new double[] { 0.11, 0.21, 0.31, 0.41, -0.51, -0.61, 1.12, 0.71, 0.81, 0.91 }; double[] Qk = new double[] { 0.11, 0.21, 0.31, 0.41, -0.51, -0.61, 1.12, 0.70, 0.81, 0.91 }; for (int j = 0; j < cycles; j++) { long timeGlobalT = -System.nanoTime(); for (int i = 0; i < n2; i++) { r[0] = Math.random(); r[1] = Math.random(); r[2] = Math.random(); multipoleTensor.setR(r); multipoleTensor.order6(); } timeGlobalT += System.nanoTime(); long timeGlobal = -System.nanoTime(); for (int i = 0; i < n2; i++) { r[0] = Math.random(); r[1] = Math.random(); r[2] = Math.random(); multipoleTensor.setR(r); multipoleTensor.setMultipoles(Qi, Qk); double e = multipoleTensor.multipoleEnergy(Fi, Ti, Tk); if (Double.isNaN(e) || Double.isInfinite(e)) { multipoleTensor.nanWarning(e, r, Qi, Qk, Fi, Ti, Tk); } } timeGlobal += System.nanoTime(); multipoleTensor.setCoordinateSystem(COORDINATES.QI); long timeQIT = -System.nanoTime(); for (int i = 0; i < n2; i++) { r[0] = Math.random(); r[1] = Math.random(); r[2] = Math.random(); multipoleTensor.setR_QI(r); multipoleTensor.order6QI(); } timeQIT += System.nanoTime(); long timeQI = -System.nanoTime(); for (int i = 0; i < n2; i++) { r[0] = 0.0; r[1] = 0.0; r[2] = Math.random(); multipoleTensor.setR_QI(r); multipoleTensor.setMultipoles(Qi, Qk); double e = multipoleTensor.multipoleEnergy(Fi, Ti, Tk); if (Double.isNaN(e) || Double.isInfinite(e)) { multipoleTensor.nanWarning(e, r, Qi, Qk, Fi, Ti, Tk); } } timeQI += System.nanoTime(); logger.info(String.format("\n Global Frame: %6.4f %6.4f\n QI: %6.4f %6.4f\n", timeGlobalT * 1.0e-9, timeGlobal * 1.0e-9, timeQIT * 1.0e-9, timeQI * 1.0e-9)); } /** * double tensors[] = new double[MultipoleTensor.tensorCount(order)]; * String string = multipoleTensor.codeTensorRecursion(r, tensors); * logger.info(" Java Code:\n" + string); string = * multipoleTensor.codeTensorRecursionQI(r, tensors); logger.info(" Java * Code:\n" + string); */ }
From source file:com.example.sensingapp.SensingApp.java
private void calculateAudioSoundLevel() { long nTotalVal; int nLen;//from ww w .ja va2s . c o m short shtBuffer[]; while (m_soundLevelThread != null && m_blnRecordSoundLevel == true) { if (m_nAudioReadCount != AudioRecord.ERROR_INVALID_OPERATION) { nTotalVal = 0; shtBuffer = DataUtil.Bytes2Shorts(m_btAudioBuffer, m_nAudioReadCount); nLen = shtBuffer.length; for (int i = 0; i < nLen; i++) { nTotalVal = nTotalVal + shtBuffer[i] * shtBuffer[i]; } double fMean = nTotalVal * 1.0 / nLen; if (fMean == 0) { m_fSoundLevelDb = 1000; } else { m_fSoundLevelDb = 10 * Math.log10(fMean); } if (Double.isInfinite(m_fSoundLevelDb) || Double.isNaN(m_fSoundLevelDb)) { } else { recordSoundLevel(m_fSoundLevelDb); } } // if try { Thread.sleep(100); } catch (InterruptedException e) { } } // while }
From source file:ffx.numerics.MultipoleTensor.java
private void validate(boolean print) { double[] qiVals = new double[] { qi, dxi, dyi, dzi, qxxi, qyyi, qzzi, qxyi, qxzi, qyzi }; double[] qkVals = new double[] { qk, dxk, dyk, dzk, qxxk, qyyk, qzzk, qxyk, qxzk, qyzk }; double[] exxxVals = new double[] { E000, E100, E010, E001, E200, E020, E002, E110, E101, E011 }; double[] rxxxVals = new double[] { R000, R100, R010, R001, R200, R020, R002, R110, R101, R011, R300, R120, R102, R210, R201, R111, R210, R030, R012, R120, R111, R021, R201, R021, R003, R111, R102, R012, R400, R220, R202, R310, R301, R211, R220, R040, R022, R130, R121, R031, R202, R022, R004, R112, R103, R013 };/*from w w w .j ava 2 s .com*/ double[][] all = new double[][] { qiVals, qkVals, exxxVals, rxxxVals }; if (!print) { for (int i = 0; i < all.length; i++) { for (int j = 0; j < all[i].length; j++) { if (Double.isNaN(all[i][j])) { logger.warning(format("MT::validate(): NaN @ (%d,%d)", i, j)); } if (Double.isInfinite(all[i][j])) { logger.warning(format("MT::validate(): Inf @ (%d,%d)", i, j)); } } } } else { logger.info(format("MT::ALL_VALS: %s", formArr(all))); } }
From source file:ffx.numerics.MultipoleTensor.java
private void nanWarning(double energy, double[] r, double[] Qi, double[] Qk, double[] Fi, double[] Ti, double[] Tk) { StringBuilder sb = new StringBuilder(); if (Double.isInfinite(energy)) { sb.append(format("DotK infinite: \n")); } else if (Double.isNaN(energy)) { sb.append(format("DotK was NaN: \n")); }/*from www. j av a 2 s . com*/ sb.append(format(" r: %s\n Qi: %s\n Qk: %s\n Fi: %s\n Ti: %s\n Tk: %s\n", formArr(r), formArr(Qi), formArr(Qk), formArr(Fi), formArr(Ti), formArr(Tk))); double total = qk * E000; double total2 = qxyi * E110; // sb.append(format("DotK components:" // + "\n (1) %.4f %.4f %.4f %.4f %.4f\n (2) %.4f %.4f %.4f %.4f %.4f" // + "\n (3) %.4f %.4f %.4f %.4f %.4f\n (4) %.4f %.4f %.4f %.4f %.4f" // + "\n (5) %.4f %.4f %.4f", // E000, E100, E010, E001, E200, // E020, E002, E110, E101, E011, // qi, dxi, dyi, dzi, qxxi, // qyyi, qzzi, qxyi, qxzi, qyzi, // qk, dxk, dyk, dzk, qxxk, // qyyk, qzzk, qxyi, qxzk, qyzk, // total, total2, total + 2.0*total2)); double[] Exxx = new double[] { E000, E100, E010, E001, E200, E020, E002, E110, E010, E001 }; double[] mpoleI = new double[] { qi, dxi, dyi, dzi, qxxi, qyyi, qzzi, qxyi, qxzi, qyzi }; double[] mpoleK = new double[] { qk, dxk, dyk, dzk, qxxk, qyyk, qzzk, qxyk, qxzk, qyzk }; sb.append(format("DotK components:\n Exxx: %s\n mpoleI: %s\n mpoleK: %s", formArr(Exxx), formArr(mpoleI), formArr(mpoleK))); (new ArithmeticException()).printStackTrace(); logger.warning(sb.toString()); }
From source file:geogebra.kernel.Kernel.java
/** * Formats the value of x using the currently set * NumberFormat or ScientificFormat. This method also * takes getCasPrintForm() into account. */// www. java 2s .c o m final public String formatRaw(double x) { switch (casPrintForm) { // number formatting for XML string output case ExpressionNode.STRING_TYPE_GEOGEBRA_XML: if (Math.abs(x) < Integer.MAX_VALUE && Math.floor(x) == x) return Integer.toString((int) x); else return Double.toString(x); // number formatting for CAS case ExpressionNode.STRING_TYPE_MATH_PIPER: case ExpressionNode.STRING_TYPE_JASYMCA: case ExpressionNode.STRING_TYPE_MAXIMA: case ExpressionNode.STRING_TYPE_MPREDUCE: if (Double.isNaN(x)) return " 1/0 "; else if (Double.isInfinite(x)) { if (casPrintForm == ExpressionNode.STRING_TYPE_MAXIMA) return (x < 0) ? "-inf" : "inf"; return Double.toString(x); // "Infinity" or "-Infinity" } else { double abs = Math.abs(x); // number small enough that Double.toString() won't create E notation if (abs >= 10E-3 && abs < 10E7) { long round = Math.round(x); if (x == round) { return Long.toString(round); } else { return Double.toString(x); } } // number would produce E notation with Double.toString() else { // convert scientific notation 1.0E-20 to 1*10^(-20) String scientificStr = Double.toString(x); StringBuilder sb = new StringBuilder(scientificStr.length() * 2); boolean Efound = false; for (int i = 0; i < scientificStr.length(); i++) { char ch = scientificStr.charAt(i); if (ch == 'E') { sb.append("*10^("); Efound = true; } else { sb.append(ch); } } if (Efound) sb.append(")"); return sb.toString(); } } // number formatting for screen output default: if (Double.isNaN(x)) return "?"; else if (Double.isInfinite(x)) { return (x > 0) ? "\u221e" : "-\u221e"; // infinity } else if (x == Math.PI) { return casPrintFormPI; } // ROUNDING hack // NumberFormat and SignificantFigures use ROUND_HALF_EVEN as // default which is not changeable, so we need to hack this // to get ROUND_HALF_UP like in schools: increase abs(x) slightly // x = x * ROUND_HALF_UP_FACTOR; // We don't do this for large numbers as double abs = Math.abs(x); if ((abs < 10E7 && nf.getMaximumFractionDigits() < 10) || abs < 1000) { // increase abs(x) slightly to round up x = x * ROUND_HALF_UP_FACTOR; } if (useSignificantFigures) { return formatSF(x); } else { return formatNF(x); } } }