List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Engine.AlgebraUtils.java
public static Vector3D ReturnClosestWectorMirror(double[] v1, double[] v2, WorldMap worldMap) { double x = (worldMap.mapSize - 1) * GenerateTerrain.Size; double y = (worldMap.mapSize - 1) * GenerateTerrain.Size; double distance = DistanceBetweenDoubleTablesMirror(v1, v2, worldMap); if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0], v1[1], v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0], v1[1], v1[2]); if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0] + x, v1[1], v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0] + x, v1[1], v1[2]); if (Math.abs( DistanceBetweenDoubleTables(new double[] { v1[0] + x, v1[1] + y, v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0] + x, v1[1] + y, v1[2]); if (Math.abs( DistanceBetweenDoubleTables(new double[] { v1[0] + x, v1[1] - y, v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0] + x, v1[1] - y, v1[2]); if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0] - x, v1[1], v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0] - x, v1[1], v1[2]); if (Math.abs( DistanceBetweenDoubleTables(new double[] { v1[0] - x, v1[1] + y, v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0] - x, v1[1] + y, v1[2]); if (Math.abs( DistanceBetweenDoubleTables(new double[] { v1[0] - x, v1[1] - y, v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0] - x, v1[1] - y, v1[2]); if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0], v1[1] + y, v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0], v1[1] + y, v1[2]); if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0], v1[1] - y, v1[2] }, v2) - distance) < 0.001) return new Vector3D(v1[0], v1[1] - y, v1[2]); return Vector3D.ZERO; }
From source file:Main.java
public static int[] findClosestFpsRange(Camera camera, int minFrameRate, int maxFrameRate) { minFrameRate *= 1000;/*ww w . j a va 2 s .c om*/ maxFrameRate *= 1000; Camera.Parameters parameters = camera.getParameters(); int minIndex = 0; int minDiff = Integer.MAX_VALUE; List<int[]> rangeList = parameters.getSupportedPreviewFpsRange(); Log.d(TAG, "support preview fps range list: " + dumpFpsRangeList(rangeList)); for (int i = 0; i < rangeList.size(); i++) { int[] fpsRange = rangeList.get(i); if (fpsRange.length != 2) { continue; } int minFps = fpsRange[0] / 1000; int maxFps = fpsRange[1] / 1000; int diff = Math.abs(minFps - minFrameRate) + Math.abs(maxFps - maxFrameRate); if (diff < minDiff) { minDiff = diff; minIndex = i; } } int[] result = rangeList.get(minIndex); return result; }
From source file:Main.java
@Nonnull public static int[] generateCodePointSet(final int codePointSetSize, @Nonnull final Random random) { final int[] codePointSet = new int[codePointSetSize]; for (int i = codePointSet.length - 1; i >= 0;) { final int r = Math.abs(random.nextInt()); if (r < 0) { continue; }// ww w . jav a2 s .c o m // Don't insert 0~0x20, but insert any other code point. // Code points are in the range 0~0x10FFFF. final int candidateCodePoint = 0x20 + r % (Character.MAX_CODE_POINT - 0x20); // Code points between MIN_ and MAX_SURROGATE are not valid on their own. if (candidateCodePoint >= Character.MIN_SURROGATE && candidateCodePoint <= Character.MAX_SURROGATE) { continue; } codePointSet[i] = candidateCodePoint; --i; } return codePointSet; }
From source file:com.cloud.test.stress.TestClientWithAPI.java
public static void main(String[] args) { String host = "http://localhost"; String port = "8092"; String devPort = "8080"; String apiUrl = "/client/api"; try {/* www . j a va2s. co m*/ // Parameters List<String> argsList = Arrays.asList(args); Iterator<String> iter = argsList.iterator(); while (iter.hasNext()) { String arg = iter.next(); // host if (arg.equals("-h")) { host = "http://" + iter.next(); } if (arg.equals("-p")) { port = iter.next(); } if (arg.equals("-dp")) { devPort = iter.next(); } if (arg.equals("-t")) { numThreads = Integer.parseInt(iter.next()); } if (arg.equals("-s")) { sleepTime = Long.parseLong(iter.next()); } if (arg.equals("-a")) { accountName = iter.next(); } if (arg.equals("-c")) { cleanUp = Boolean.parseBoolean(iter.next()); if (!cleanUp) sleepTime = 0L; // no need to wait if we don't ever // cleanup } if (arg.equals("-r")) { repeat = Boolean.parseBoolean(iter.next()); } if (arg.equals("-u")) { numOfUsers = Integer.parseInt(iter.next()); } if (arg.equals("-i")) { internet = Boolean.parseBoolean(iter.next()); } if (arg.equals("-w")) { wait = Integer.parseInt(iter.next()); } if (arg.equals("-z")) { zoneId = iter.next(); } if (arg.equals("-snapshot")) { snapshot_test = "yes"; } if (arg.equals("-so")) { serviceOfferingId = iter.next(); } if (arg.equals("-do")) { diskOfferingId = iter.next(); } if (arg.equals("-no")) { networkOfferingId = iter.next(); } if (arg.equals("-pass")) { vmPassword = iter.next(); } if (arg.equals("-url")) { downloadUrl = iter.next(); } } final String server = host + ":" + port + "/"; final String developerServer = host + ":" + devPort + apiUrl; s_logger.info("Starting test against server: " + server + " with " + numThreads + " thread(s)"); if (cleanUp) s_logger.info("Clean up is enabled, each test will wait " + sleepTime + " ms before cleaning up"); if (numOfUsers > 0) { s_logger.info("Pre-generating users for test of size : " + numOfUsers); users = new String[numOfUsers]; Random ran = new Random(); for (int i = 0; i < numOfUsers; i++) { users[i] = Math.abs(ran.nextInt()) + "-user"; } } for (int i = 0; i < numThreads; i++) { new Thread(new Runnable() { @Override public void run() { do { String username = null; try { long now = System.currentTimeMillis(); Random ran = new Random(); if (users != null) { username = users[Math.abs(ran.nextInt()) % numOfUsers]; } else { username = Math.abs(ran.nextInt()) + "-user"; } NDC.push(username); s_logger.info("Starting test for the user " + username); int response = executeDeployment(server, developerServer, username, snapshot_test); boolean success = false; String reason = null; if (response == 200) { success = true; if (internet) { s_logger.info("Deploy successful...waiting 5 minute before SSH tests"); Thread.sleep(300000L); // Wait 60 // seconds so // the windows VM // can boot up and do a sys prep. if (accountName == null) { s_logger.info("Begin Linux SSH test for account " + _account.get()); reason = sshTest(_linuxIP.get(), _linuxPassword.get(), snapshot_test); } if (reason == null) { s_logger.info( "Linux SSH test successful for account " + _account.get()); s_logger.info("Begin WindowsSSH test for account " + _account.get()); reason = sshTest(_linuxIP.get(), _linuxPassword.get(), snapshot_test); // reason = sshWinTest(_windowsIP.get()); } // release the linux IP now... _linuxIP.set(null); // release the Windows IP now _windowsIP.set(null); } // sleep for 3 min before getting the latest network stat // s_logger.info("Sleeping for 5 min before getting the lates network stat for the account"); // Thread.sleep(300000); // verify that network stat is correct for the user; if it's not - stop all the resources // for the user // if ((reason == null) && (getNetworkStat(server) == false) ) { // s_logger.error("Stopping all the resources for the account " + _account.get() + // " as network stat is incorrect"); // int stopResponseCode = executeStop( // server, developerServer, // username, false); // s_logger // .info("stop command finished with response code: " // + stopResponseCode); // success = false; // since the SSH test // // } else if (reason == null) { if (internet) { s_logger.info( "Windows SSH test successful for account " + _account.get()); } else { s_logger.info("deploy test successful....now cleaning up"); if (cleanUp) { s_logger.info( "Waiting " + sleepTime + " ms before cleaning up vms"); Thread.sleep(sleepTime); } else { success = true; } } if (usageIterator >= numThreads) { int eventsAndBillingResponseCode = executeEventsAndBilling(server, developerServer); s_logger.info( "events and usage records command finished with response code: " + eventsAndBillingResponseCode); usageIterator = 1; } else { s_logger.info( "Skipping events and usage records for this user: usageIterator " + usageIterator + " and number of Threads " + numThreads); usageIterator++; } if ((users == null) && (accountName == null)) { s_logger.info("Sending cleanup command"); int cleanupResponseCode = executeCleanup(server, developerServer, username); s_logger.info("cleanup command finished with response code: " + cleanupResponseCode); success = (cleanupResponseCode == 200); } else { s_logger.info("Sending stop DomR / destroy VM command"); int stopResponseCode = executeStop(server, developerServer, username, true); s_logger.info("stop(destroy) command finished with response code: " + stopResponseCode); success = (stopResponseCode == 200); } } else { // Just stop but don't destroy the // VMs/Routers s_logger.info("SSH test failed for account " + _account.get() + "with reason '" + reason + "', stopping VMs"); int stopResponseCode = executeStop(server, developerServer, username, false); s_logger.info( "stop command finished with response code: " + stopResponseCode); success = false; // since the SSH test // failed, mark the // whole test as // failure } } else { // Just stop but don't destroy the // VMs/Routers s_logger.info("Deploy test failed with reason '" + reason + "', stopping VMs"); int stopResponseCode = executeStop(server, developerServer, username, true); s_logger.info("stop command finished with response code: " + stopResponseCode); success = false; // since the deploy test // failed, mark the // whole test as failure } if (success) { s_logger.info("***** Completed test for user : " + username + " in " + ((System.currentTimeMillis() - now) / 1000L) + " seconds"); } else { s_logger.info("##### FAILED test for user : " + username + " in " + ((System.currentTimeMillis() - now) / 1000L) + " seconds with reason : " + reason); } s_logger.info("Sleeping for " + wait + " seconds before starting next iteration"); Thread.sleep(wait); } catch (Exception e) { s_logger.warn("Error in thread", e); try { int stopResponseCode = executeStop(server, developerServer, username, true); s_logger.info("stop response code: " + stopResponseCode); } catch (Exception e1) { } } finally { NDC.clear(); } } while (repeat); } }).start(); } } catch (Exception e) { s_logger.error(e); } }
From source file:Main.java
private static int joystickScale(float in, MotionRange range, int zone) { if (range == null) { return 0; // no range means we don't have this control }//from www .j av a 2 s . c om float min = range.getMin(); float max = range.getMax(); if (in < min) { in = min; } if (in > max) { in = max; } if (Math.abs(in) >= range.getFlat()) { if (in >= 0) { min = range.getFlat(); return (int) (((in - min) / (max - min)) * (32767 - zone)) + zone; } else { max = -range.getFlat(); return (int) (((in - min) / (max - min)) * (32768 - zone) - 32768.0); } } else { // scaling up TO the zone; this is the nominally ZERO zone min = -range.getFlat(); max = range.getFlat(); return (int) (((in - min) / (max - min)) * zone * 2 - zone); } }
From source file:com.ms.commons.test.tool.UnitTestTools.java
/** * ??5?//from ww w .jav a 2 s. c om * * @param len * @return */ public static Integer nextInt(Integer len) { if (len == null) { len = 2; } int v = 0; int i = 0; while (i < len) { v *= 10; int x = RandomUtils.nextInt(10); while (x == 0) { x = RandomUtils.nextInt(10); } v += Math.abs(x); i++; } return Math.abs(v); }
From source file:Main.java
public static Bitmap rotateAndFrame(Bitmap bitmap) { final boolean positive = sRandom.nextFloat() >= 0.5f; final float angle = (ROTATION_ANGLE_MIN + sRandom.nextFloat() * ROTATION_ANGLE_EXTRA) * (positive ? 1.0f : -1.0f); final double radAngle = Math.toRadians(angle); final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); final double cosAngle = Math.abs(Math.cos(radAngle)); final double sinAngle = Math.abs(Math.sin(radAngle)); final int strokedWidth = (int) (bitmapWidth + 2 * PHOTO_BORDER_WIDTH); final int strokedHeight = (int) (bitmapHeight + 2 * PHOTO_BORDER_WIDTH); final int width = (int) (strokedHeight * sinAngle + strokedWidth * cosAngle); final int height = (int) (strokedWidth * sinAngle + strokedHeight * cosAngle); final float x = (width - bitmapWidth) / 2.0f; final float y = (height - bitmapHeight) / 2.0f; final Bitmap decored = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(decored); canvas.rotate(angle, width / 2.0f, height / 2.0f); canvas.drawBitmap(bitmap, x, y, sPaint); canvas.drawRect(x, y, x + bitmapWidth, y + bitmapHeight, sStrokePaint); return decored; }
From source file:Main.java
public static double p_norm(double[] vals, int p) { double pnorm = 0.0; for (double d : vals) { pnorm += Math.pow(Math.abs(d), p); }/* w w w . jav a 2 s . c om*/ return Math.pow(pnorm, (1.0d / (double) p)); }
From source file:Main.java
public static double calculateDistance(int frequency, int level) { return Math.pow(10.0, (DISTANCE_MHZ_M - (20 * Math.log10(frequency)) + Math.abs(level)) / 20.0); }
From source file:Main.java
public static double[] decimalDegreesToDegreeMinutes(double fDegrees) { final double fAbsDegrees = Math.abs(fDegrees); int dAbsDegrees = (int) fAbsDegrees; // Adjust degrees if minutes calulate to 60, due to rounding errors: double fAbsMinutes = 60.0 * (fAbsDegrees - dAbsDegrees); String minutesString = String.format(Locale.US, "%1$06.3f", fAbsMinutes); if (minutesString.equals("60.000")) { dAbsDegrees = dAbsDegrees + 1;// w w w. j a va 2s. co m fAbsMinutes = 0; } return new double[] { dAbsDegrees, fAbsMinutes }; }