List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
static int configDistance(EGL10 egl, EGLDisplay display, EGLConfig config, int want_r, int want_g, int want_b, int want_a, int want_depth, int want_stencil) { int r = getConfigAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0); int g = getConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0); int b = getConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0); int a = getConfigAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0); int d = getConfigAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0); int s = getConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0); return Math.abs(r - want_r) + Math.abs(g - want_g) + Math.abs(b - want_b) + Math.abs(a - want_a) + Math.abs(d - want_depth) + Math.abs(s - want_stencil); }
From source file:eu.ggnet.dwoss.report.assist.gen.ReportLineGenerator.java
/** This Method return a Random Positiv Long Value; * <p/>/* w w w . jav a 2s . c o m*/ * @return a positiv long Value. */ private static long getRandomLong() { return Math.abs(R.nextInt(100000)); }
From source file:br.unicamp.ic.recod.gpsi.measures.gpsiDistanceOfMediansScore.java
@Override public double score(double[][][] input) { Median median = new Median(); RealMatrix matrix0 = MatrixUtils.createRealMatrix(input[0]); RealMatrix matrix1 = MatrixUtils.createRealMatrix(input[1]); return Math.abs(median.evaluate(matrix0.getColumn(0)) - median.evaluate(matrix1.getColumn(0))); }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Abs.java
public static void inPlace(long[] v) { Validate.notNull(v);//from ww w .j av a 2 s. c o m final int n = v.length; for (int i = 0; i < n; i++) { v[i] = Math.abs(v[i]); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); int siteIndex = Math.abs(random.nextInt()) % sites.size(); String site = (String) sites.elementAt(siteIndex); res.setStatus(res.SC_MOVED_TEMPORARILY); res.setHeader("Location", site); }
From source file:Main.java
public static int[] createSequence(int begin, int end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; int[] seq = new int[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign;/* ww w. j a v a 2 s .c o m*/ } return seq; }
From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheb.java
public static double[] cheb(int n, double[] x) { if (n <= 0) { throw new IllegalArgumentException("cheb: n has to be a positive integer"); }/*from ww w . ja v a 2 s . c o m*/ if (x.length == 0) { return new double[0]; } //# avoid resizing latencies double[] T = new double[x.length]; for (int i = 0; i < x.length; i++) { if (Math.abs(x[i]) > 1) { T[i] = FastMath.cos(n * FastMath.acos(x[i])); } else { T[i] = FastMath.cosh(n * FastMath.acosh(x[i])); } } return T; }
From source file:Main.java
/** Returns Map with total, squaredTotal, count, average, stdDev, maximum; fieldName field in Maps must have type BigDecimal; * if count of non-null fields is less than 2 returns null as cannot calculate a standard deviation */ public static Map<String, BigDecimal> stdDevMaxFromMapField(List<Map<String, Object>> dataList, String fieldName, BigDecimal stdDevMultiplier) { BigDecimal total = BigDecimal.ZERO; BigDecimal squaredTotal = BigDecimal.ZERO; int count = 0; for (Map<String, Object> dataMap : dataList) { if (dataMap == null) continue; BigDecimal value = (BigDecimal) dataMap.get(fieldName); if (value == null) continue; total = total.add(value);//from w w w. j a va 2 s . com squaredTotal = squaredTotal.add(value.multiply(value)); count++; } if (count < 2) return null; BigDecimal countBd = new BigDecimal(count); BigDecimal average = total.divide(countBd, BigDecimal.ROUND_HALF_UP); double totalDouble = total.doubleValue(); BigDecimal stdDev = new BigDecimal(Math .sqrt(Math.abs(squaredTotal.doubleValue() - ((totalDouble * totalDouble) / count)) / (count - 1))); Map<String, BigDecimal> retMap = new HashMap<>(6); retMap.put("total", total); retMap.put("squaredTotal", squaredTotal); retMap.put("count", countBd); retMap.put("average", average); retMap.put("stdDev", stdDev); if (stdDevMultiplier != null) retMap.put("maximum", average.add(stdDev.multiply(stdDevMultiplier))); return retMap; }
From source file:Main.java
/** Calculate the absolute angular difference between the two headings * // w ww. j av a 2 s .c om * @param hdg angle 1 in degrees (typically the heading) * @param brg angle 2 in degrees (typically the bearing) * @return difference between hdg and brg in degrees */ public static double angularDifference(double hdg, double brg) { double absDiff = Math.abs(hdg - brg); if (absDiff > 180) { return 360 - absDiff; } return absDiff; }
From source file:com.example.PJS.java
/** Otra version de la NORMSDIST (z) sacada de aca: * http://www.codeproject.com/Articles/408214/Excel-Function-NORMSDIST-z *Esta es la Cumulative Normal Ditribution Function */// w w w. java2 s. co m private static double erf(double x) { //A&S formula 7.1.26 double a1 = 0.254829592; double a2 = -0.284496736; double a3 = 1.421413741; double a4 = -1.453152027; double a5 = 1.061405429; double p = 0.3275911; x = Math.abs(x); double t = 1 / (1 + p * x); //Direct calculation using formula 7.1.26 is absolutely correct //But calculation of nth order polynomial takes O(n^2) operations //return 1 - (a1 * t + a2 * t * t + a3 * t * t * t + a4 * t * t * t * t + a5 * t * t * t * t * t) * Math.Exp(-1 * x * x); //Horner's method, takes O(n) operations for nth order polynomial return 1 - ((((((a5 * t + a4) * t) + a3) * t + a2) * t) + a1) * t * Math.exp(-1 * x * x); }