List of usage examples for java.lang Double NaN
double NaN
To view the source code for java.lang Double NaN.
Click Source Link
From source file:ly.count.android.api.EventTests.java
public void testToJSON_sumNaNCausesJSONException() throws JSONException { final Event event = new Event(); event.key = "eventKey"; event.timestamp = 1234;/*from ww w .ja v a2s . c o m*/ event.count = 42; event.sum = Double.NaN; event.segmentation = new HashMap<String, String>(); event.segmentation.put("segkey", "segvalue"); final JSONObject jsonObj = event.toJSON(); assertEquals(4, jsonObj.length()); assertEquals(event.key, jsonObj.getString("key")); assertEquals(event.timestamp, jsonObj.getInt("timestamp")); assertEquals(event.count, jsonObj.getInt("count")); assertEquals(1, jsonObj.getJSONObject("segmentation").length()); assertEquals(event.segmentation.get("segkey"), jsonObj.getJSONObject("segmentation").getString("segkey")); }
From source file:com.esri.ArcGISController.java
@RequestMapping(value = "/rest/services/InfoUSA/MapServer/export", method = { RequestMethod.GET, RequestMethod.POST })/*from w ww . j a va 2 s . co m*/ public void doExport(@RequestParam("bbox") final String bbox, @RequestParam(value = "size", required = false) final String size, @RequestParam(value = "layerDefs", required = false) final String layerDefs, @RequestParam(value = "transparent", required = false) final String transparent, final HttpServletResponse response) throws IOException { double xmin = -1.0, ymin = -1.0, xmax = 1.0, ymax = 1.0; if (bbox != null && bbox.length() > 0) { final String[] tokens = m_patternComma.split(bbox); if (tokens.length == 4) { xmin = Double.parseDouble(tokens[0]); ymin = Double.parseDouble(tokens[1]); xmax = Double.parseDouble(tokens[2]); ymax = Double.parseDouble(tokens[3]); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "bbox is not in the form xmin,ymin,xmax,ymax"); return; } } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "bbox is null or empty"); return; } final double xdel = xmax - xmin; final double ydel = ymax - ymin; int imageWidth = 400; int imageHeight = 400; if (size != null && size.length() > 0) { final String[] tokens = m_patternComma.split(size); if (tokens.length == 2) { imageWidth = Integer.parseInt(tokens[0], 10); imageHeight = Integer.parseInt(tokens[1], 10); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "size is not in the form width,height"); return; } } String where = null; double lo = Double.NaN; double hi = Double.NaN; int[] ramp = null; if (layerDefs != null) { final String[] tokens = m_patternSemiColon.split(layerDefs); for (final String token : tokens) { final String[] keyval = m_patternEqual.split(token.substring(2)); if (keyval.length == 2) { final String key = keyval[0]; final String val = keyval[1]; if ("lo".equalsIgnoreCase(key)) { lo = "NaN".equalsIgnoreCase(val) ? Double.NaN : Double.parseDouble(val); } else if ("hi".equalsIgnoreCase(key)) { hi = "NaN".equalsIgnoreCase(val) ? Double.NaN : Double.parseDouble(val); } else if ("ramp".equalsIgnoreCase(key)) { ramp = parseRamp(val); } else if ("where".equalsIgnoreCase(key)) { where = val; } } } } if (ramp == null) { ramp = new int[] { 0xFFFFFF, 0x000000 }; } final Range range = new Range(); final Map<Long, Double> map = query(where, xmin, ymin, xmax, ymax, range); if (!Double.isNaN(lo)) { range.lo = lo; } if (!Double.isNaN(hi)) { range.hi = hi; } range.dd = range.hi - range.lo; final int typeIntRgb = "true".equalsIgnoreCase(transparent) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; BufferedImage bufferedImage = new BufferedImage(imageWidth, imageHeight, typeIntRgb); final Graphics2D graphics = bufferedImage.createGraphics(); try { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setBackground(new Color(0, 0, 0, 0)); drawCells(graphics, imageWidth, imageHeight, xmin, ymin, xdel, ydel, range, ramp, map.entrySet()); } finally { graphics.dispose(); } // bufferedImage = m_op.filter(bufferedImage, null); final ByteArrayOutputStream baos = new ByteArrayOutputStream(10 * 1024); ImageIO.write(bufferedImage, "PNG", baos); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("image/png"); response.setContentLength(baos.size()); baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); }
From source file:com.github.joulupunikki.math.random.BitsStreamGenerator64.java
/** * Attention: subclassing generators need to call this when re-seeding to * properly reset the generator, calling reset will zero the storage of the * next gaussian and next integer./*ww w . ja v a 2 s . c om*/ */ @Override public void clear() { nextGaussian = Double.NaN; isIntLeft = false; }
From source file:it.unibo.alchemist.model.SAPEREIncarnation.java
private double sapereProperty(final ILsaNode node, final ILsaMolecule molecule, final String prop, final boolean cacheUpdated) { if (cacheUpdated) { saperePropertyNumber = -1;//from w w w . j a va 2s . c o m for (int i = 0; i < molecule.argsNumber() && saperePropertyNumber == -1; i++) { final IExpression arg = molecule.getArg(i); switch (arg.getRootNodeType()) { case COMPARATOR: if (arg.getLeftChildren().toString().equals(prop)) { saperePropertyNumber = i; } break; case VAR: if (arg.getRootNode().toString().equals(prop)) { saperePropertyNumber = i; } break; default: break; } } } if (saperePropertyNumber >= 0) { final ILsaNode inode = (ILsaNode) node; final List<ILsaMolecule> concentration = inode.getConcentration(molecule); /* * Potential concurrency issue: a size check is mandatory */ if (!concentration.isEmpty()) { final IExpression arg = concentration.get(0).getArg(saperePropertyNumber); if (arg.getRootNodeType().equals(Type.NUM)) { return (double) arg.getRootNodeData(); } } } return Double.NaN; }
From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java
private static double calculateSum(double[] values, final int begin, final int length) { if (values == null || length == 0) { return Double.NaN; }//www . j a v a 2 s . c o m double sum = 0.0; for (int i = begin; i < begin + length; i++) { sum += values[i]; } return sum; }
From source file:Float11.java
static public double pow(double x, double y) { if (y == 0.)/*from w w w . j a v a 2 s . c o m*/ return 1.; if (y == 1.) return x; if (x == 0.) return 0.; if (x == 1.) return 1.; // long l = (long) Math.floor(y); boolean integerValue = (y == (double) l); // if (integerValue) { boolean neg = false; if (y < 0.) neg = true; // double result = x; for (long i = 1; i < (neg ? -l : l); i++) result = result * x; // if (neg) return 1. / result; else return result; } else { if (x > 0.) return exp(y * log(x)); else return Double.NaN; } }
From source file:ml.shifu.shifu.util.BinUtils.java
/** * Avoid parsing times, failed parsing is set to NaN * // ww w . ja v a 2 s. c o m * @param valStr * param string * @return double after parsing */ public static double parseNumber(Object valStr) { if (valStr == null) { return Double.NaN; } if (valStr instanceof Double) { return (Double) valStr; } else if (valStr instanceof Integer) { return ((Integer) valStr).doubleValue(); } else { try { return Double.parseDouble((String) valStr); } catch (NumberFormatException e) { return Double.NaN; } } }
From source file:gedi.util.math.stat.counting.RollingStatistics.java
/** * Always includes the first and last halfwindow and all windows that fit in between and are step entries apart from each other * It also takes care of ties in the covariate by always including adding all values for all ties within range * @param halfBinsize/*from w w w .ja va2 s . c om*/ * @param step * @return */ public ExtendedIterator<RollingBin> iterateEquiSize(int halfBinsize, int step) { if (size() == 0) return EI.empty(); cov.parallelSort(val); if (size() < halfBinsize + 1) { NumericArraySlice slice = NumericArray.wrap(val.getRaw(), 0, val.size()); if (size() == 1) return EI.wrap(new RollingBin(cov.getDouble(0), slice)); return EI.wrap(new RollingBin(cov.getDouble(0), slice), new RollingBin(cov.getDouble(size() - 1), slice)); } if (size() < halfBinsize * 2 + 1) { return EI.wrap(new RollingBin(cov.getDouble(0), NumericArray.wrap(val.getRaw(), 0, halfBinsize + 1)), new RollingBin(cov.getDouble(size() - 1), NumericArray.wrap(val.getRaw(), size() - 1 - halfBinsize, size()))); } IntArrayList ties = new IntArrayList(); ties.add(0); for (int i = 1; i < size(); i++) if (cov.getDouble(i - 1) != cov.getDouble(i)) ties.add(i); ties.add(size()); ExtendedIterator<RollingBin> ei = new ExtendedIterator<RollingBin>() { private int i = halfBinsize - step; private RollingBin rb; private NumericArraySlice slice; private boolean dirty = false; private boolean lastDone = false; { int start = 0; int end = ties.binarySearch(halfBinsize + 1); if (end < 0) end = -end - 1; slice = NumericArray.wrap(val.getRaw(), ties.getInt(start), ties.getInt(end)); rb = new RollingBin(cov.getDouble(0), slice); } @Override public boolean hasNext() { computeIfNecessary(); return !Double.isNaN(rb.covariate); } @Override public RollingBin next() { computeIfNecessary(); dirty = true; return rb; } private void computeIfNecessary() { if (dirty && !Double.isNaN(rb.covariate)) { i += step; if (i < size() - halfBinsize) { int start = bin(i - halfBinsize, 0); int end = bin(i + halfBinsize, 1) + 1; slice.setSlice(ties.getInt(start), ties.getInt(end)); rb.covariate = cov.getDouble(i); } else if (!lastDone) { int start = ties.binarySearch(size() - 1 - halfBinsize); if (start < 0) start = -start - 2; int end = size(); slice.setSlice(ties.getInt(start), end); rb.covariate = cov.getDouble(size() - 1); lastDone = true; } else { rb.covariate = Double.NaN; } dirty = false; } } private int[][] fastBin = new int[2][]; private int bin(int s, int which) { if (fastBin[which] == null) { fastBin[which] = new int[2]; } else if (cov.getDouble(fastBin[which][0]) == cov.getDouble(s)) { return fastBin[which][1]; } fastBin[which][0] = s; fastBin[which][1] = ties.binarySearch(s); if (fastBin[which][1] < 0) fastBin[which][1] = -fastBin[which][1] - 2; return fastBin[which][1]; } }; int count = (int) Math.ceil((size() - halfBinsize * 2) / (double) step) + 2; if (progress != null) ei = ei.progress(progress, count, rb -> String.format("%.2f: [%.2f,%.2f]", rb.covariate, rb.values.getDouble(0), rb.values.getDouble(rb.getValues().length() - 1))); return ei; }
From source file:jasima.core.statistics.SummaryStat.java
/** * Returns the population variance of the values. * /*from w w w . j a v a 2 s . c o m*/ * @return The (sample) variance of all values given to * {@link #value(double)}. Returns NaN, if no values were added yet. */ public double variancePopulation() { if (numObs < 1) return Double.NaN; if (numObs == 1) return 0.0; return varEst / weightSum; }
From source file:cz.paulrz.montecarlo.random.Sobol.java
@Override public double nextGaussian() { final double random; if (Double.isNaN(nextGaussian)) { // generate a new pair of gaussian numbers final double[] xs = nextPoint(); final double x = xs[0]; final double y = xs[1]; final double alpha = 2 * FastMath.PI * x; final double r = FastMath.sqrt(-2 * FastMath.log(y)); random = r * FastMath.cos(alpha); nextGaussian = r * FastMath.sin(alpha); } else {/* w w w . j a v a 2 s. c o m*/ // use the second element of the pair already generated random = nextGaussian; nextGaussian = Double.NaN; } return random; }