2015-03-13 18:52:59 +00:00
|
|
|
/* Copyright (c) 2008-2015, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
package java.lang;
|
|
|
|
|
2008-03-21 00:39:25 +00:00
|
|
|
import java.util.Random;
|
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
public final class Math {
|
2007-09-12 01:13:05 +00:00
|
|
|
public static final double E = 2.718281828459045;
|
|
|
|
public static final double PI = 3.141592653589793;
|
2015-09-13 01:58:50 +00:00
|
|
|
|
|
|
|
private static class Static {
|
|
|
|
public static final Random random = new Random();
|
|
|
|
}
|
2007-09-12 01:13:05 +00:00
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
private Math() { }
|
|
|
|
|
2007-08-30 23:31:32 +00:00
|
|
|
public static double max(double a, double b) {
|
|
|
|
return (a < b ? b : a);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double min(double a, double b) {
|
|
|
|
return (a > b ? b : a);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float max(float a, float b) {
|
|
|
|
return (a < b ? b : a);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float min(float a, float b) {
|
|
|
|
return (a > b ? b : a);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long max(long a, long b) {
|
|
|
|
return (a < b ? b : a);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long min(long a, long b) {
|
|
|
|
return (a > b ? b : a);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int max(int a, int b) {
|
|
|
|
return (a < b ? b : a);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int min(int a, int b) {
|
|
|
|
return (a > b ? b : a);
|
|
|
|
}
|
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
public static int abs(int v) {
|
|
|
|
return (v < 0 ? -v : v);
|
2007-07-29 23:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static long abs(long v) {
|
|
|
|
return (v < 0 ? -v : v);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float abs(float v) {
|
|
|
|
return (v < 0 ? -v : v);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double abs(double v) {
|
|
|
|
return (v < 0 ? -v : v);
|
2007-07-29 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static long round(double v) {
|
2007-08-30 23:31:32 +00:00
|
|
|
return (long) Math.floor(v + 0.5);
|
2007-07-29 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int round(float v) {
|
2007-08-30 23:31:32 +00:00
|
|
|
return (int) Math.floor(v + 0.5);
|
2007-07-29 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 05:23:42 +00:00
|
|
|
public static double signum(double d) {
|
|
|
|
return d > 0 ? +1.0 : d < 0 ? -1.0 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float signum(float f) {
|
|
|
|
return f > 0 ? +1.0f : f < 0 ? -1.0f : 0;
|
|
|
|
}
|
|
|
|
|
2007-11-29 00:06:04 +00:00
|
|
|
public static double random() {
|
2015-09-13 01:58:50 +00:00
|
|
|
return Static.random.nextDouble();
|
2007-11-29 00:06:04 +00:00
|
|
|
}
|
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double floor(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double ceil(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double exp(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double log(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double cos(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double sin(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double tan(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2013-01-21 21:43:29 +00:00
|
|
|
public static native double cosh(double v);
|
|
|
|
|
|
|
|
public static native double sinh(double v);
|
|
|
|
|
|
|
|
public static native double tanh(double v);
|
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double acos(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double asin(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double atan(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2014-10-11 08:05:40 +00:00
|
|
|
public static native double atan2(double y, double x);
|
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double sqrt(double v);
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2007-07-30 23:19:05 +00:00
|
|
|
public static native double pow(double v, double e);
|
2007-07-29 23:32:23 +00:00
|
|
|
}
|