List of usage examples for java.lang Float NEGATIVE_INFINITY
float NEGATIVE_INFINITY
To view the source code for java.lang Float NEGATIVE_INFINITY.
Click Source Link
From source file:jp.furplag.util.commons.NumberUtilsTest.java
/** * {@link jp.furplag.util.commons.NumberUtils#add(java.lang.Number, java.lang.Number)}. *///from w ww . j ava 2 s. co m @SuppressWarnings("unchecked") @Test public void testAddTNumber() { assertEquals("null", null, add(null, null)); assertEquals("null", null, add(null, 10)); assertEquals("null", (Object) 123.456d, add(123.456, 0)); assertEquals("null", (Object) 123.456f, add(123.456f, 0)); assertEquals("123 + .456: Float", (Object) 123, add(123, .456f)); assertEquals("123 + .456: Float", (Object) Double.class, add(123d, .456f).getClass()); assertEquals("123 + .456: Float", (Object) BigDecimal.class, add(BigDecimal.valueOf(123d), .456f).getClass()); for (Class<?> type : NUMBERS) { try { Object o = null; Number augend = null; Class<? extends Number> typeOfN = (Class<? extends Number>) type; Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type); if (ClassUtils.isPrimitiveWrapper(wrapper)) { o = wrapper.getMethod("valueOf", String.class).invoke(null, "123"); } else { Constructor<?> c = type.getDeclaredConstructor(String.class); o = c.newInstance("123"); } assertEquals("123.456: " + type.getSimpleName(), add((Number) o, augend, typeOfN), add((Number) o, augend)); augend = .456f; assertEquals("123.456: " + type.getSimpleName(), add((Number) o, augend, typeOfN), add((Number) o, augend)); augend = Double.NaN; assertEquals("NaN: " + type.getSimpleName(), add((Number) o, augend, typeOfN), add((Number) o, augend)); augend = Float.NEGATIVE_INFINITY; assertEquals("-Infinity: Float: " + type.getSimpleName(), add((Number) o, augend, typeOfN), add((Number) o, augend)); augend = Double.POSITIVE_INFINITY; assertEquals("Infinity: Double: : " + type.getSimpleName(), add((Number) o, augend, typeOfN), add((Number) o, augend)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())); } } }
From source file:com.cognitect.transit.TransitMPTest.java
public void testWriteReadSpecialNumbers() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer w = TransitFactory.writer(TransitFactory.Format.MSGPACK, out); w.write(Double.NaN);/* w w w .j av a 2 s . c o m*/ w.write(Float.NaN); w.write(Double.POSITIVE_INFINITY); w.write(Float.POSITIVE_INFINITY); w.write(Double.NEGATIVE_INFINITY); w.write(Float.NEGATIVE_INFINITY); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); Reader r = TransitFactory.reader(TransitFactory.Format.MSGPACK, in); assert ((Double) r.read()).isNaN(); assert ((Double) r.read()).isNaN(); assertEquals(Double.POSITIVE_INFINITY, (Double) r.read()); assertEquals(Double.POSITIVE_INFINITY, (Double) r.read()); assertEquals(Double.NEGATIVE_INFINITY, (Double) r.read()); assertEquals(Double.NEGATIVE_INFINITY, (Double) r.read()); }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static float convertToFloat(String s) { if ((s == null) || s.equals("")) { return Float.NaN; }/*from w w w .j a v a 2 s . c o m*/ if (s.startsWith("+")) { s = s.substring(1); } if (POSITIVE_INFINITY.equals(s)) { return Float.POSITIVE_INFINITY; } else if (NEGATIVE_INFINITY.equals(s)) { return Float.NEGATIVE_INFINITY; } return Float.parseFloat(s); }
From source file:info.debatty.java.datasets.sift.Matrix.java
public static float max(final float[] A) { float maxval = Float.NEGATIVE_INFINITY; for (float val : A) { if (val > maxval) { maxval = val; }// w ww.ja va 2s . c om } return maxval; }
From source file:org.apache.vxquery.runtime.functions.cast.CastToStringOperation.java
public void convertFloatCanonical(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException { abvsInner.reset();//from w w w . j av a 2s . c o m float value = floatp.getFloat(); if (Float.isInfinite(value)) { if (value == Float.NEGATIVE_INFINITY) { FunctionHelper.writeCharSequence("-", dOutInner); } FunctionHelper.writeCharSequence("INF", dOutInner); } else if (Float.isNaN(value)) { FunctionHelper.writeCharSequence("NaN", dOutInner); } else { dOut.write(returnTag); dOut.writeUTF(Float.toString(value)); return; } sendStringDataOutput(dOut); }
From source file:papaya.Rank.java
/** Decide how to proceed with the NaN values */ private static List<Integer> nanStrategy(IntFloatPair[] ranks, int nanStrategy) { List<Integer> nanPositions = null; // Recode, remove or record positions of NaNs switch (nanStrategy) { case MAXIMAL: // Replace NaNs with +INFs recodeNaNs(ranks, Float.POSITIVE_INFINITY); break;/*from w w w.j a v a2s. c o m*/ case MINIMAL: // Replace NaNs with -INFs recodeNaNs(ranks, Float.NEGATIVE_INFINITY); break; case REMOVED: // Drop NaNs from data ranks = removeNaNs(ranks); break; case FIXED: // Record positions of NaNs nanPositions = getNanPositions(ranks); break; } return nanPositions; }
From source file:org.caleydo.view.bicluster.elem.GLRootElement.java
/** * * @param isDimensionThresholds//from w w w .j a v a2 s. c o m * @param thresholds * bicluster id x threshold */ public void setThresholds(EDimension dimension, Map<Integer, Float> thresholds) { float thresh = Float.NEGATIVE_INFINITY; for (NormalClusterElement elem : allNormalClusters()) { int number = elem.getBiClusterNumber(); if (thresholds.containsKey(number)) { float t = thresholds.get(number); if (Float.isInfinite(thresh)) thresh = t; if (t != thresh) thresh = Float.NaN; elem.setThreshold(dimension, t, MyUnboundSpinner.UNBOUND, EThresholdMode.ABS); } } if (!Float.isNaN(thresh) && !Float.isInfinite(thresh)) { // all the same set that in the parameter toolbar this.toolbarParam.setThreshold(dimension, thresh); } updateAllEdges(); }
From source file:com.opera.core.systems.scope.stp.services.ScopeEcmascriptService.java
/** * Parses a reply and returns the result of the script execution. The result from EcmaScript is * converted based on the object types specified by Scope: * * <dl> <dt>undefined</dt> <dd> The undefined type, returned when no value was found or * "undefined" was references. Will return null. </dd> * * <dt>true</dt> <dd>Boolean true value.</dd> * * <dt>false</dt> <dd>Boolean false value.</dd> * * <dt>NaN</dt> <dd> NaN value (not a number) which cannot be exported to JSON directly. Will be * treated as a number, and returns a {@link Float#NaN} reference. </dd> * * <dt>Infinity</dt> <dd> Plus infinity value which cannot be exported to JSON directly. Will be * treated as a number, and returns a {@link Float#POSITIVE_INFINITY} reference. </dd> * * <dt>-Infinity</dt> <dd> Negative infinity value which cannot be exported to JSON directly. Will * be treated as a number, and returns a {@link Float#NEGATIVE_INFINITY} reference. </dd> * * <dt>number</dt> <dd>A number, will return a long or double value depending on its value.</dd> * * <dt>string</dt> <dd>A string.</dd> * * <dt>object</dt> <dd> A non-primitive value in EcmaScript, typically a generic object. This * includes functions and arrays. </dd> </dl> * * @param result the result of a script execution * @return the parsed result of a reply/*from w w w .j a v a 2 s . c om*/ */ private Object parseEvalReply(EvalResult result) { Status status = result.getStatus(); switch (status) { case CANCELLED: return null; case EXCEPTION: throw new ScopeException("EcmaScript exception"); case NO_MEMORY: //releaseObjects(); throw new ScopeException("Out of memory"); case FAILURE: throw new ScopeException("Could not execute script"); } Value value = result.getValue(); Type type = value.getType(); switch (type) { case STRING: return value.getStr(); case FALSE: return false; case TRUE: return true; case OBJECT: return value.getObject(); case NUMBER: return parseNumber(String.valueOf(value.getNumber())); case NAN: return Float.NaN; case MINUS_INFINITY: return Float.NEGATIVE_INFINITY; case PLUS_INFINITY: return Float.POSITIVE_INFINITY; case UNDEFINED: case NULL: default: return null; } }
From source file:com.anhth12.nn.multilayer.MultiLayerNetwork.java
public double reductionRation(INDArray p, double currScore, double score, INDArray gradient) { double currentDamp = layerWiseConfiguration.getDampingFactor(); layerWiseConfiguration.setDampingFactor(0); ;/* w w w.ja v a2s.c om*/ INDArray denom = getBackPropRGradient(p); denom.muli(0.5).muli(p.mul(denom)).sum(0); denom.subi(gradient.mul(p).sum(0)); double rho = (currScore - score) / (double) denom.getScalar(0).element(); layerWiseConfiguration.setDampingFactor(currentDamp); if (score - currScore > 0) { return Float.NEGATIVE_INFINITY; } return rho; }
From source file:com.cognitect.transit.TransitTest.java
public void testSpecialNumbers() throws Exception { assertEquals(scalar("\"~zNaN\""), writeJson(Double.NaN)); assertEquals(scalar("\"~zINF\""), writeJson(Double.POSITIVE_INFINITY)); assertEquals(scalar("\"~z-INF\""), writeJson(Double.NEGATIVE_INFINITY)); assertEquals(scalar("\"~zNaN\""), writeJson(Float.NaN)); assertEquals(scalar("\"~zINF\""), writeJson(Float.POSITIVE_INFINITY)); assertEquals(scalar("\"~z-INF\""), writeJson(Float.NEGATIVE_INFINITY)); assertEquals(scalarVerbose("\"~zNaN\""), writeJsonVerbose(Double.NaN)); assertEquals(scalarVerbose("\"~zINF\""), writeJsonVerbose(Double.POSITIVE_INFINITY)); assertEquals(scalarVerbose("\"~z-INF\""), writeJsonVerbose(Double.NEGATIVE_INFINITY)); assertEquals(scalarVerbose("\"~zNaN\""), writeJsonVerbose(Float.NaN)); assertEquals(scalarVerbose("\"~zINF\""), writeJsonVerbose(Float.POSITIVE_INFINITY)); assertEquals(scalarVerbose("\"~z-INF\""), writeJsonVerbose(Float.NEGATIVE_INFINITY)); }