List of usage examples for java.lang Long MAX_VALUE
long MAX_VALUE
To view the source code for java.lang Long MAX_VALUE.
Click Source Link
From source file:Main.java
/** * Puts a thread to sleep forever.//from w w w. j a v a 2s .c o m */ public static void sleep() { try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException iex) { // ignore } }
From source file:Money.java
public static Money getInfiniteMoney() { Long x = Long.MAX_VALUE; return new Money(x.toString()); }
From source file:Main.java
public static long getAndAddRequest(AtomicLong requested, long n) { long current; long next;//from w w w .j a v a 2s .c o m do { current = requested.get(); next = current + n; if (next < 0) { next = Long.MAX_VALUE; } } while (!requested.compareAndSet(current, next)); return current; }
From source file:Main.java
public static void skipAll(InputStream in) throws IOException { do {//from ww w.j a v a2s . co m in.skip(Long.MAX_VALUE); } while (in.read() != -1); }
From source file:Main.java
public static boolean isLikelyDouble(long value) { // Check for some common named double values // We don't check for Double.MIN_VALUE, which has a long representation of 1 if (value == canonicalDoubleNaN || value == maxDouble || value == piDouble || value == eDouble) { return true; }//from www. ja va 2 s.com // Check for some named long values if (value == Long.MAX_VALUE || value == Long.MIN_VALUE) { return false; } // a non-canocical NaN is more likely to be an long double doubleValue = Double.longBitsToDouble(value); if (Double.isNaN(doubleValue)) { return false; } // Otherwise, whichever has a shorter scientific notation representation is more likely. // Long wins the tie String asLong = format.format(value); String asDouble = format.format(doubleValue); // try to strip off any small imprecision near the end of the mantissa int decimalPoint = asDouble.indexOf('.'); int exponent = asDouble.indexOf("E"); int zeros = asDouble.indexOf("000"); if (zeros > decimalPoint && zeros < exponent) { asDouble = asDouble.substring(0, zeros) + asDouble.substring(exponent); } else { int nines = asDouble.indexOf("999"); if (nines > decimalPoint && nines < exponent) { asDouble = asDouble.substring(0, nines) + asDouble.substring(exponent); } } return asDouble.length() < asLong.length(); }
From source file:com.android.volley.utils.CacheTestUtils.java
/** * Makes a random cache entry.//from ww w . java 2 s .c om * @param data Data to use, or null to use random data * @param isExpired Whether the TTLs should be set such that this entry is expired * @param needsRefresh Whether the TTLs should be set such that this entry needs refresh */ public static Cache.Entry makeRandomCacheEntry(byte[] data, boolean isExpired, boolean needsRefresh) { Random random = new Random(); Cache.Entry entry = new Cache.Entry(); if (data != null) { entry.data = data; } else { entry.data = new byte[random.nextInt(1024)]; } entry.etag = String.valueOf(random.nextLong()); entry.lastModified = random.nextLong(); entry.ttl = isExpired ? 0 : Long.MAX_VALUE; entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE; return entry; }
From source file:Main.java
/** * Multiplies two positive longs and caps the result at Long.MAX_VALUE. * @param a the first value//w w w . j a v a 2 s .c om * @param b the second value * @return the capped product of a and b */ public static long multiplyCap(long a, long b) { long u = a * b; if (((a | b) >>> 31) != 0) { if (b != 0L && (u / b != a)) { u = Long.MAX_VALUE; } } return u; }
From source file:Main.java
public static void setupXAxis(NumberAxis numberAxis, ObservableList<XYChart.Series<Number, Number>> seriesList) { long min = Long.MAX_VALUE; long max = 0; for (XYChart.Series<Number, ?> series : seriesList) { for (Data<Number, ?> data : series.getData()) { min = Math.min(data.getXValue().longValue(), min); max = Math.max(data.getXValue().longValue(), max); }//from w ww .j av a2 s.co m } setupXAxis(numberAxis, min, max); }
From source file:Main.java
/** * Atomically subtracts a value from the requested amount unless it's at Long.MAX_VALUE. * @param requested the requested amount holder * @param n the value to subtract from the requested amount, has to be positive (not verified) * @return the new requested amount//from w ww .j a v a 2 s . c om * @throws IllegalStateException if n is greater than the current requested amount, which * indicates a bug in the request accounting logic */ public static long produced(AtomicLong requested, long n) { for (;;) { long current = requested.get(); if (current == Long.MAX_VALUE) { return Long.MAX_VALUE; } long next = current - n; if (next < 0L) { throw new IllegalStateException("More produced than requested: " + next); } if (requested.compareAndSet(current, next)) { return next; } } }
From source file:ffx.numerics.fft.RowMajorComplex3DCuda.java
/** * <p>//from w ww. j a va 2 s . co m * main</p> * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { int dimNotFinal = 64; int reps = 10; if (args != null) { try { dimNotFinal = Integer.parseInt(args[0]); if (dimNotFinal < 1) { dimNotFinal = 64; } reps = Integer.parseInt(args[2]); if (reps < 1) { reps = 5; } } catch (Exception e) { } } final int dim = dimNotFinal; System.out.println(String.format( " Initializing a %d cubed grid.\n" + " The best timing out of %d repititions will be used.", dim, reps)); final int dimCubed = dim * dim * dim; /** * Create an array to save the initial input and result. */ double orig[] = new double[dimCubed]; double answer[] = new double[dimCubed]; double data[] = new double[dimCubed * 2]; double recip[] = new double[dimCubed]; Random random = new Random(1); for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { int index = RowMajorComplex3D.iComplex3D(x, y, z, dim, dim); orig[index / 2] = random.nextDouble(); recip[index / 2] = orig[index / 2]; } } } RowMajorComplex3D complex3D = new RowMajorComplex3D(dim, dim, dim); RowMajorComplex3DParallel complex3DParallel = new RowMajorComplex3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed()); RowMajorComplex3DCuda complex3DCUDA = new RowMajorComplex3DCuda(dim, dim, dim, data, recip); Thread cudaThread = new Thread(complex3DCUDA); cudaThread.setPriority(Thread.MAX_PRIORITY); cudaThread.start(); double toSeconds = 0.000000001; long parTime = Long.MAX_VALUE; long seqTime = Long.MAX_VALUE; long clTime = Long.MAX_VALUE; complex3D.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3D.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Sequential: %8.3f", i + 1, toSeconds * time)); if (time < seqTime) { seqTime = time; } } for (int j = 0; j < dimCubed; j++) { answer[j] = data[j * 2]; } complex3DParallel.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DParallel.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Parallel: %8.3f", i + 1, toSeconds * time)); if (time < parTime) { parTime = time; } } double maxError = Double.MIN_VALUE; double rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs(answer[i] - data[2 * i]); if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError)); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DCUDA.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d CUDA: %8.3f", i + 1, toSeconds * time)); if (time < clTime) { clTime = time; } } maxError = Double.MIN_VALUE; double avg = 0.0; rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs((answer[i] - data[2 * i]) / dimCubed); avg += error; if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; avg /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg)); complex3DCUDA.free(); complex3DCUDA = null; System.out.println(String.format(" Best Sequential Time: %8.3f", toSeconds * seqTime)); System.out.println(String.format(" Best Parallel Time: %8.3f", toSeconds * parTime)); System.out.println(String.format(" Best CUDA Time: %8.3f", toSeconds * clTime)); System.out.println(String.format(" Parallel Speedup: %15.5f", (double) seqTime / parTime)); System.out.println(String.format(" CUDA Speedup: %15.5f", (double) seqTime / clTime)); }