List of usage examples for java.lang Float POSITIVE_INFINITY
float POSITIVE_INFINITY
To view the source code for java.lang Float POSITIVE_INFINITY.
Click Source Link
From source file:Main.java
/** * Fills the array with random floats. Values will be between min (inclusive) and * max (inclusive)./* ww w . j av a2 s. c om*/ */ public static void genRandomFloats(long seed, float min, float max, float array[], boolean includeExtremes) { Random r = new Random(seed); int minExponent = Math.min(Math.getExponent(min), 0); int maxExponent = Math.max(Math.getExponent(max), 0); if (minExponent < -6 || maxExponent > 6) { // Use an exponential distribution int exponentDiff = maxExponent - minExponent; for (int i = 0; i < array.length; i++) { float mantissa = r.nextFloat(); int exponent = minExponent + r.nextInt(maxExponent - minExponent); int sign = (min >= 0) ? 1 : 1 - r.nextInt(2) * 2; // -1 or 1 float rand = sign * mantissa * (float) Math.pow(2.0, exponent); if (rand < min || rand > max) { continue; } array[i] = rand; } } else { // Use a linear distribution for (int i = 0; i < array.length; i++) { float rand = r.nextFloat(); array[i] = min + rand * (max - min); } } // Seed a few special numbers we want to be sure to test. for (int i = 0; i < sInterestingDoubles.length; i++) { float f = (float) sInterestingDoubles[i]; if (min <= f && f <= max) { array[r.nextInt(array.length)] = f; } } array[r.nextInt(array.length)] = min; array[r.nextInt(array.length)] = max; if (includeExtremes) { array[r.nextInt(array.length)] = Float.NaN; array[r.nextInt(array.length)] = Float.POSITIVE_INFINITY; array[r.nextInt(array.length)] = Float.NEGATIVE_INFINITY; array[r.nextInt(array.length)] = Float.MIN_VALUE; array[r.nextInt(array.length)] = Float.MIN_NORMAL; array[r.nextInt(array.length)] = Float.MAX_VALUE; array[r.nextInt(array.length)] = -Float.MIN_VALUE; array[r.nextInt(array.length)] = -Float.MIN_NORMAL; array[r.nextInt(array.length)] = -Float.MAX_VALUE; } }
From source file:test.uk.co.modularaudio.util.math.Float16Tester.java
@Test public void testFromFloat() { final float[] testFloats = new float[] { Float16.MAX_VALUE, Float16.MIN_VALUE, // Interesting values from an audio perspective -1.0f, -0.001f, -0.0001f, 0.0f, 0.0001f, 0.001f, 1.0f, -1.1f, -0.9f, 0.9f, 1.1f, // Some "steady" values 0.1f, 0.125f, 0.2f, 0.25f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.75f, 0.8f, 0.825f, // And some values to examine precision 192000.0f, 41000.0f, 22050.0f, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, }; for (final float testFloat : testFloats) { final Float16 f16 = new Float16(testFloat); final float andBack = f16.asFloat(); log.debug("OF(" + MathFormatter.slowFloatPrint(testFloat, 16, true) + ") F16(" + MathFormatter.slowFloatPrint(andBack, 16, true) + ")"); }// w w w . j a v a 2 s . c o m }
From source file:Main.java
public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(parameters.getSupportedPreviewSizes()); Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() { @Override/*from ww w. j a v a2 s.c o m*/ public int compare(Camera.Size a, Camera.Size b) { int aPixels = a.height * a.width; int bPixels = b.height * b.width; if (bPixels < aPixels) { return -1; } if (bPixels > aPixels) { return 1; } return 0; } }); Point bestSize = null; float screenAspectRatio = (float) screenResolution.x / (float) screenResolution.y; float diff = Float.POSITIVE_INFINITY; for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { int realWidth = supportedPreviewSize.width; int realHeight = supportedPreviewSize.height; int pixels = realWidth * realHeight; if (pixels < MIN_PREVIEW_PIXELS || pixels > MAX_PREVIEW_PIXELS) { continue; } boolean isCandidatePortrait = realWidth < realHeight; int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { return new Point(realWidth, realHeight); } float aspectRatio = (float) maybeFlippedWidth / (float) maybeFlippedHeight; float newDiff = Math.abs(aspectRatio - screenAspectRatio); if (newDiff < diff) { bestSize = new Point(realWidth, realHeight); diff = newDiff; } } if (bestSize == null) { Camera.Size defaultSize = parameters.getPreviewSize(); bestSize = new Point(defaultSize.width, defaultSize.height); } return bestSize; }
From source file:Main.java
/** * Determines the minimum and maximum values in the <tt>array</tt>, ignoring any instances of <tt>noDataValue</tt>. * //from w w w . j a v a 2s . 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:uk.co.modularaudio.util.audio.controlinterpolation.CDSpringAndDamperDouble24Interpolator.java
public CDSpringAndDamperDouble24Interpolator() { curState.x = 0.0;/*from www . ja va2s .co m*/ curState.v = 0.0; this.lowerBound = Float.NEGATIVE_INFINITY; this.upperBound = Float.POSITIVE_INFINITY; deltaTimestep = INTEGRATION_TIMESTEP_FOR_48K; }
From source file:uk.co.modularaudio.util.audio.controlinterpolation.CDSpringAndDamperDouble12Interpolator.java
public CDSpringAndDamperDouble12Interpolator() { curState.x = 0.0;/*from w ww. j a v a 2 s . c o m*/ curState.v = 0.0; this.lowerBound = Float.NEGATIVE_INFINITY; this.upperBound = Float.POSITIVE_INFINITY; deltaTimestep = INTEGRATION_TIMESTEP_FOR_48K; }
From source file:io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory.java
@JsonCreator public ApproximateHistogramAggregatorFactory(@JsonProperty("name") String name, @JsonProperty("fieldName") String fieldName, @JsonProperty("resolution") Integer resolution, @JsonProperty("numBuckets") Integer numBuckets, @JsonProperty("lowerLimit") Float lowerLimit, @JsonProperty("upperLimit") Float upperLimit ) {/*from ww w . j a v a 2 s .c om*/ this.name = name; this.fieldName = fieldName; this.resolution = resolution == null ? ApproximateHistogram.DEFAULT_HISTOGRAM_SIZE : resolution; this.numBuckets = numBuckets == null ? ApproximateHistogram.DEFAULT_BUCKET_SIZE : numBuckets; this.lowerLimit = lowerLimit == null ? Float.NEGATIVE_INFINITY : lowerLimit; this.upperLimit = upperLimit == null ? Float.POSITIVE_INFINITY : upperLimit; Preconditions.checkArgument(this.resolution > 0, "resolution must be greater than 1"); Preconditions.checkArgument(this.numBuckets > 0, "numBuckets must be greater than 1"); Preconditions.checkArgument(this.upperLimit > this.lowerLimit, "upperLimit must be greater than lowerLimit"); }
From source file:uk.co.modularaudio.util.audio.controlinterpolation.SpringAndDamper24Interpolator.java
public SpringAndDamper24Interpolator() { curState.x = 0.0f;/* ww w . ja v a 2 s .c om*/ curState.v = 0.0f; this.lowerBound = Float.NEGATIVE_INFINITY; this.upperBound = Float.POSITIVE_INFINITY; deltaTimestep = INTEGRATION_TIMESTEP_FOR_48K; }
From source file:uk.co.modularaudio.util.audio.controlinterpolation.SpringAndDamperDouble24Interpolator.java
public SpringAndDamperDouble24Interpolator() { curState.x = 0.0;//from w w w . j a v a 2s . com curState.v = 0.0; this.lowerBound = Float.NEGATIVE_INFINITY; this.upperBound = Float.POSITIVE_INFINITY; deltaTimestep = INTEGRATION_TIMESTEP_FOR_48K; }
From source file:net.gtaun.shoebill.data.Location.java
public float distance(Location loc) { if (loc.interiorId != interiorId || loc.worldId != worldId) return Float.POSITIVE_INFINITY; return super.distance(loc); }