1 7 8 package java.lang; 9 import java.util.Random ; 10 11 12 69 70 public final class Math { 71 72 75 private Math() {} 76 77 81 public static final double E = 2.7182818284590452354; 82 83 88 public static final double PI = 3.14159265358979323846; 89 90 103 public static double sin(double a) { 104 return StrictMath.sin(a); } 106 107 118 public static double cos(double a) { 119 return StrictMath.cos(a); } 121 122 135 public static double tan(double a) { 136 return StrictMath.tan(a); } 138 139 153 public static double asin(double a) { 154 return StrictMath.asin(a); } 156 157 169 public static double acos(double a) { 170 return StrictMath.acos(a); } 172 173 186 public static double atan(double a) { 187 return StrictMath.atan(a); } 189 190 200 public static double toRadians(double angdeg) { 201 return angdeg / 180.0 * PI; 202 } 203 204 216 public static double toDegrees(double angrad) { 217 return angrad * 180.0 / PI; 218 } 219 220 236 public static double exp(double a) { 237 return StrictMath.exp(a); } 239 240 257 public static double log(double a) { 258 return StrictMath.log(a); } 260 261 282 public static double log10(double a) { 283 return StrictMath.log10(a); } 285 286 303 public static double sqrt(double a) { 304 return StrictMath.sqrt(a); } 310 311 312 338 public static double cbrt(double a) { 339 return StrictMath.cbrt(a); 340 } 341 342 364 public static double IEEEremainder(double f1, double f2) { 365 return StrictMath.IEEEremainder(f1, f2); } 367 368 387 public static double ceil(double a) { 388 return StrictMath.ceil(a); } 390 391 406 public static double floor(double a) { 407 return StrictMath.floor(a); } 409 410 425 public static double rint(double a) { 426 return StrictMath.rint(a); } 428 429 480 public static double atan2(double y, double x) { 481 return StrictMath.atan2(y, x); } 483 484 607 public static double pow(double a, double b) { 608 return StrictMath.pow(a, b); } 610 611 633 public static int round(float a) { 634 return (int)floor(a + 0.5f); 635 } 636 637 660 public static long round(double a) { 661 return (long)floor(a + 0.5d); 662 } 663 664 private static Random randomNumberGenerator; 665 666 private static synchronized void initRNG() { 667 if (randomNumberGenerator == null) 668 randomNumberGenerator = new Random (); 669 } 670 671 692 public static double random() { 693 if (randomNumberGenerator == null) initRNG(); 694 return randomNumberGenerator.nextDouble(); 695 } 696 697 711 public static int abs(int a) { 712 return (a < 0) ? -a : a; 713 } 714 715 729 public static long abs(long a) { 730 return (a < 0) ? -a : a; 731 } 732 733 748 public static float abs(float a) { 749 return (a <= 0.0F) ? 0.0F - a : a; 750 } 751 752 767 public static double abs(double a) { 768 return (a <= 0.0D) ? 0.0D - a : a; 769 } 770 771 782 public static int max(int a, int b) { 783 return (a >= b) ? a : b; 784 } 785 786 797 public static long max(long a, long b) { 798 return (a >= b) ? a : b; 799 } 800 801 private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f); 802 private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d); 803 804 818 public static float max(float a, float b) { 819 if (a != a) return a; if ((a == 0.0f) && (b == 0.0f) 821 && (Float.floatToIntBits(a) == negativeZeroFloatBits)) { 822 return b; 823 } 824 return (a >= b) ? a : b; 825 } 826 827 841 public static double max(double a, double b) { 842 if (a != a) return a; if ((a == 0.0d) && (b == 0.0d) 844 && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) { 845 return b; 846 } 847 return (a >= b) ? a : b; 848 } 849 850 861 public static int min(int a, int b) { 862 return (a <= b) ? a : b; 863 } 864 865 876 public static long min(long a, long b) { 877 return (a <= b) ? a : b; 878 } 879 880 894 public static float min(float a, float b) { 895 if (a != a) return a; if ((a == 0.0f) && (b == 0.0f) 897 && (Float.floatToIntBits(b) == negativeZeroFloatBits)) { 898 return b; 899 } 900 return (a <= b) ? a : b; 901 } 902 903 917 public static double min(double a, double b) { 918 if (a != a) return a; if ((a == 0.0d) && (b == 0.0d) 920 && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) { 921 return b; 922 } 923 return (a <= b) ? a : b; 924 } 925 926 949 public static double ulp(double d) { 950 return sun.misc.FpUtils.ulp(d); 951 } 952 953 976 public static float ulp(float f) { 977 return sun.misc.FpUtils.ulp(f); 978 } 979 980 997 public static double signum(double d) { 998 return sun.misc.FpUtils.signum(d); 999 } 1000 1001 1018 public static float signum(float f) { 1019 return sun.misc.FpUtils.signum(f); 1020 } 1021 1022 1047 public static double sinh(double x) { 1048 return StrictMath.sinh(x); 1049 } 1050 1051 1075 public static double cosh(double x) { 1076 return StrictMath.cosh(x); 1077 } 1078 1079 1115 public static double tanh(double x) { 1116 return StrictMath.tanh(x); 1117 } 1118 1119 1144 public static double hypot(double x, double y) { 1145 return StrictMath.hypot(x, y); 1146 } 1147 1148 1181 public static double expm1(double x) { 1182 return StrictMath.expm1(x); 1183 } 1184 1185 1217 public static double log1p(double x) { 1218 return StrictMath.log1p(x); 1219 } 1220} 1221 | Popular Tags |