List of usage examples for java.lang Float isInfinite
public static boolean isInfinite(float v)
From source file:Main.java
public static void main(String[] args) { float f = (float) 1 / 0; boolean b1 = Float.isInfinite(f); System.out.println(b1);// w w w . j a v a2 s.co m Float fObj = new Float(f); boolean b2 = fObj.isInfinite(); System.out.println(b2); }
From source file:Main.java
public static void main(String[] args) { Float f1 = new Float(1.0 / 0.0); Float f2 = new Float(0.0 / 0.0); System.out.println(f1 + " = " + Float.isInfinite(f1)); System.out.println(f2 + " = " + Float.isInfinite(f2)); }
From source file:Main.java
/** * Returns <code>true</code> if the specified number is infinitely * large in magnitude, <code>false</code> otherwise. * * <p>Note that this method is equivalent to the {@link * Float#isInfinite(float) Float.isInfinite} method; the * functionality is included in this class for convenience. * * @param f the value to be tested./* w w w .j a v a2 s . com*/ * @return <code>true</code> if the argument is positive infinity or * negative infinity; <code>false</code> otherwise. */ public static boolean isInfinite(float f) { return Float.isInfinite(f); }
From source file:org.dbpedia.spotlight.lucene.similarity.NewSimilarity.java
private float round(float d) { float result = d; DecimalFormat twoDForm = new DecimalFormat("#.######"); if (Float.isInfinite(d)) { result = Float.MAX_VALUE; } else if (Float.isNaN(d)) { result = -2;/*from w ww. j a v a2 s. c o m*/ } else { result = Float.valueOf(twoDForm.format(d)); } return result; }
From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java
@Override public boolean onScale(ScaleGestureDetector detector) { float scaleFactor = detector.getScaleFactor(); if (Float.isNaN(scaleFactor) || Float.isInfinite(scaleFactor)) { return false; }/* w w w. j a v a2 s . c o m*/ mScaleDragGestureListener.onScale(scaleFactor, detector.getFocusX(), detector.getFocusY()); return true; }
From source file:Main.java
/** * Determines the minimum and maximum values in the <tt>array</tt>, ignoring any instances of <tt>noDataValue</tt>. * /*www . j a va 2 s . co m*/ * @param array * @param noDataValue * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum */ public static float[] minMax(float[] array, float noDataValue) { float[] ret = null; float min = Float.POSITIVE_INFINITY, max = Float.NEGATIVE_INFINITY; float val; for (int i = 0; i < array.length; i++) { val = array[i]; if (val != noDataValue) { min = (val < min) ? val : min; max = (val > max) ? val : max; } } if (!Float.isInfinite(min) & !Float.isInfinite(max)) { ret = new float[] { min, max }; } return ret; }
From source file:org.itstep.java.web.controller.GoodControllerTest.java
/** * Test of test method, of class GoodController. *//*from w w w .ja va 2 s .c om*/ @Test public void testTest() { System.out.println("test"); BindingAwareModelMap model = new BindingAwareModelMap(); TestableGoodController instance = new TestableGoodController(); instance.setGoodService(new GoodService() { @Override public List<Good> all() { return new ArrayList<>(); } @Override public List<Good> all(Integer categoryId) { return new ArrayList<>(); } }); String expResult = "test"; String result = instance.test(6f, 2f, model); assertEquals(expResult, result); assertEquals(3f, model.get("result")); instance.test(14f, 2f, model); assertEquals(7f, model.get("result")); instance.test(15f, 2f, model); assertEquals(7.5f, model.get("result")); instance.test(15f, 0f, model); assertTrue(Float.isInfinite((Float) model.get("result"))); }
From source file:org.kordamp.ezmorph.primitive.BooleanMorpher.java
/** * Morphs the input object into an output object of the supported type. * * @param value The input value to be morphed * @throws MorphException if conversion cannot be performed successfully */// w w w . j av a2 s. c o m public boolean morph(Object value) { if (value == null) { if (isUseDefault()) { return defaultValue; } else { throw new MorphException("value is null"); } } if (value instanceof Boolean) { return ((Boolean) value).booleanValue(); } else if (value instanceof Number) { if (value instanceof Double && (Double.isInfinite(((Number) value).doubleValue()) || Double.isNaN(((Number) value).doubleValue()))) { return true; } if (value instanceof Float && (Float.isInfinite(((Number) value).floatValue()) || Float.isNaN(((Number) value).floatValue()))) { return true; } long l = ((Number) value).longValue(); return l != 0; } else { String s = String.valueOf(value); if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("on")) { return true; } else if (s.equalsIgnoreCase("false") || s.equalsIgnoreCase("no") || s.equalsIgnoreCase("off")) { return false; } else if (isUseDefault()) { return defaultValue; } } throw new MorphException("Can't morph value: " + value); }
From source file:test.uk.co.modularaudio.util.audio.gui.buffervis.BufferVisualiser.java
private void computeMinMax(final float[] buffer, final int numSamples) { minVal = Float.MAX_VALUE;/* w w w . ja v a2 s . co m*/ maxVal = Float.MIN_VALUE; for (int i = 0; i < numSamples; i++) { final float v = buffer[i]; if (Float.isNaN(v) || Float.isInfinite(v)) { continue; } if (v < minVal) minVal = v; if (v > maxVal) maxVal = v; } diff = maxVal - minVal; }
From source file:model.utilities.pid.decorator.AutotunerTest.java
private PIDAutotuner runLearningExperimentWithUnknownDeadTime(MersenneTwisterFast random, float proportionalParameter, float integrativeParameter, Supplier<Double> noiseMaker, DynamicProcess systemDynamic) throws FileNotFoundException { PIDAutotuner controller = new PIDAutotuner( new PIDController(proportionalParameter, integrativeParameter, 0)); controller.setAfterHowManyDaysShouldTune(1001); int target = 10; if (noiseMaker != null) systemDynamic.setRandomNoise(noiseMaker); //create the regression too //output starts at intercept float output = 0; //delayed input, useful for learning SummaryStatistics errorBeforeTuning = new SummaryStatistics(); SummaryStatistics errorAfterTuning = new SummaryStatistics(); SummaryStatistics finalError = new SummaryStatistics(); for (int step = 0; step < 2000; step++) { //PID step controller.adjust(new ControllerInput(target, output), true, mock(MacroII.class), null, ActionOrder.DAWN);//from ww w . j a v a2s .co m //process reacts float input = controller.getCurrentMV(); assert !Float.isNaN(input); assert !Float.isInfinite(input); output = (float) systemDynamic.newStep(input); if (step <= 1000) errorBeforeTuning.addValue(Math.pow(target - output, 2)); else errorAfterTuning.addValue(Math.pow(target - output, 2)); if (step > 1900) finalError.addValue(Math.pow(target - output, 2)); //shock target with 10% if (random.nextBoolean(.10)) { if (random.nextBoolean()) target++; else target = Math.max(target - 1, 0); } } System.out.println("errors: " + errorBeforeTuning.getMean() + " --- " + errorAfterTuning.getMean()); System.out.println("final error: " + finalError.getMean()); System.out.println("regression: " + controller.getRegression()); RegressionStatics.tracksAcceptably(controller.getRegression(), systemDynamic, RegressionStatics.MAXIMUM_ABS_ERROR, 100, Math.max(controller.getCurrentMV(), RegressionStatics.FIXED_INPUT)); Assert.assertTrue(errorAfterTuning.getMean() < errorBeforeTuning.getMean()); //either have a very low error, or at least have improved by a factor of over 100 Assert.assertTrue(finalError.getMean() < 10 || finalError.getMean() < errorBeforeTuning.getMean() / 100); return controller; }