List of usage examples for java.lang StrictMath abs
public static double abs(double a)
From source file:Main.java
public static void main(String[] args) { int i1 = 12, i2 = -34; System.out.println("absolute value of " + i1 + " = " + StrictMath.abs(i1)); System.out.println("absolute value of " + i2 + " = " + StrictMath.abs(i2)); }
From source file:Main.java
public static void main(String[] args) { float f1 = 12, f2 = -1; System.out.println("absolute value of " + f1 + " = " + StrictMath.abs(f1)); System.out.println("absolute value of " + f2 + " = " + StrictMath.abs(f2)); }
From source file:Main.java
public static void main(String[] args) { double d1 = 1245.6, d2 = -123.4; System.out.println("absolute value of " + d1 + " = " + StrictMath.abs(d1)); System.out.println("absolute value of " + d2 + " = " + StrictMath.abs(d2)); }
From source file:Main.java
public static void main(String[] args) { long l1 = 12345678909876L, l2 = -12345678909876L; // returns the absolute value of positive long value long lAbsValue = StrictMath.abs(l1); System.out.println("absolute value of " + l1 + " = " + lAbsValue); // returns the absolute value of negative long value lAbsValue = StrictMath.abs(l2); System.out.println("absolute value of " + l2 + " = " + lAbsValue); }
From source file:net.nicoulaj.benchmarks.math.DoubleAbs.java
@GenerateMicroBenchmark public void strictmath(BlackHole hole) { for (int i = 0; i < data.length - 1; i++) hole.consume(StrictMath.abs(data[i])); }
From source file:gis.proj.drivers.Snyder.java
protected static double toDD(String dms) { double dd;/*from www. j a v a 2s. c om*/ dms = dms.toLowerCase(); String[] deg = dms.split("d"); if (deg.length > 1) { String[] min = deg[1].split("m"); double sec = 0; if (min.length > 1) sec = Double.parseDouble(min[1].split("s")[0]); double sign = Double.parseDouble(deg[0]) < 0.0 ? -1.0 : 1.0; dd = (StrictMath.abs(Double.parseDouble(deg[0])) + Double.parseDouble(min[0]) / 60.0 + sec / 3600.0) * sign; } else dd = Double.parseDouble(deg[0]); return dd; }
From source file:org.cirdles.calamari.algorithms.TukeyBiweight.java
public static ValueModel calculateTukeyBiweightMean(String name, double tuningConstant, double[] values) { // guarantee termination BigDecimal epsilon = BigDecimal.ONE.movePointLeft(10); int iterationMax = 100; int iterationCounter = 0; int n = values.length; // initial mean is median BigDecimal mean = new BigDecimal(calculateMedian(values)); // initial sigma is median absolute deviation from mean = median (MAD) double deviations[] = new double[n]; for (int i = 0; i < values.length; i++) { deviations[i] = StrictMath.abs(values[i] - mean.doubleValue()); }//w ww . ja v a2 s. co m BigDecimal sigma = new BigDecimal(calculateMedian(deviations)).max(BigDecimal.valueOf(SQUID_TINY_VALUE)); BigDecimal previousMean; BigDecimal previousSigma; do { iterationCounter++; previousMean = mean; previousSigma = sigma; // init to zeroes BigDecimal[] deltas = new BigDecimal[n]; BigDecimal[] u = new BigDecimal[n]; BigDecimal sa = BigDecimal.ZERO; BigDecimal sb = BigDecimal.ZERO; BigDecimal sc = BigDecimal.ZERO; BigDecimal tee = new BigDecimal(tuningConstant).multiply(sigma); for (int i = 0; i < n; i++) { deltas[i] = new BigDecimal(values[i]).subtract(mean); if (tee.compareTo(deltas[i].abs()) > 0) { deltas[i] = new BigDecimal(values[i]).subtract(mean); u[i] = deltas[i].divide(tee, MathContext.DECIMAL128); BigDecimal uSquared = u[i].multiply(u[i]); sa = sa.add(deltas[i].multiply(BigDecimal.ONE.subtract(uSquared).pow(2)).pow(2)); sb = sb.add(BigDecimal.ONE.subtract(uSquared) .multiply(BigDecimal.ONE.subtract(new BigDecimal(5.0).multiply(uSquared)))); sc = sc.add(u[i].multiply(BigDecimal.ONE.subtract(uSquared).pow(2))); } } sigma = bigDecimalSqrtBabylonian(sa.multiply(new BigDecimal(n))).divide(sb.abs(), MathContext.DECIMAL128); sigma = sigma.max(BigDecimal.valueOf(SQUID_TINY_VALUE)); mean = previousMean.add(tee.multiply(sc).divide(sb, MathContext.DECIMAL128)); } // both tests against epsilon must pass OR iterations top out // april 2016 Simon B discovered we need 101 iterations possible, hence the "<=" below while (((sigma.subtract(previousSigma).abs().divide(sigma, MathContext.DECIMAL128).compareTo(epsilon) > 0)// || mean.subtract(previousMean).abs().divide(mean, MathContext.DECIMAL128).compareTo(epsilon) > 0)// && (iterationCounter <= iterationMax)); return new ValueModel(name, mean, "ABS", sigma); }
From source file:org.esa.beam.util.math.FastMathPerformance.java
public void testAbs() { System.gc();/*ww w .j av a2s . c om*/ double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) x += StrictMath.abs(i * (1 - 0.5 * RUNS)); long strictTime = System.nanoTime() - time; System.gc(); double y = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) y += FastMath.abs(i * (1 - 0.5 * RUNS)); long fastTime = System.nanoTime() - time; System.gc(); double z = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) x += Math.abs(i * (1 - 0.5 * RUNS)); long mathTime = System.nanoTime() - time; report("abs", x + y + z, strictTime, fastTime, mathTime); }
From source file:org.esa.beam.util.math.FastMathTest.java
@Test public void testMathAbsStrict() { for (double i = 0; i < numItr; ++i) { double val = StrictMath.abs(i); }/*from ww w . ja va2 s .com*/ }