FastMath { public static double log(final double x) { return log(x, null); } private  FastMath(); static double sqrt(final double a); static double cosh(double x); static double sinh(double x); static double tanh(double x); static double acosh(final double a); static double asinh(double a); static double atanh(double a); static double signum(final double a); static float signum(final float a); static double nextUp(final double a); static float nextUp(final float a); static double nextDown(final double a); static float nextDown(final float a); static double random(); static double exp(double x); static double expm1(double x); static double log(final double x); static double log1p(final double x); static double log10(final double x); static double log(double base, double x); static double pow(double x, double y); static double pow(double d, int e); static double sin(double x); static double cos(double x); static double tan(double x); static double atan(double x); static double atan2(double y, double x); static double asin(double x); static double acos(double x); static double cbrt(double x); static double toRadians(double x); static double toDegrees(double x); static int abs(final int x); static long abs(final long x); static float abs(final float x); static double abs(double x); static double ulp(double x); static float ulp(float x); static double scalb(final double d, final int n); static float scalb(final float f, final int n); static double nextAfter(double d, double direction); static float nextAfter(final float f, final double direction); static double floor(double x); static double ceil(double x); static double rint(double x); static long round(double x); static int round(final float x); static int min(final int a, final int b); static long min(final long a, final long b); static float min(final float a, final float b); static double min(final double a, final double b); static int max(final int a, final int b); static long max(final long a, final long b); static float max(final float a, final float b); static double max(final double a, final double b); static double hypot(final double x, final double y); static double IEEEremainder(double dividend, double divisor); static int toIntExact(final long n); static int incrementExact(final int n); static long incrementExact(final long n); static int decrementExact(final int n); static long decrementExact(final long n); static int addExact(final int a, final int b); static long addExact(final long a, final long b); static int subtractExact(final int a, final int b); static long subtractExact(final long a, final long b); static int multiplyExact(final int a, final int b); static long multiplyExact(final long a, final long b); static int floorDiv(final int a, final int b); static long floorDiv(final long a, final long b); static int floorMod(final int a, final int b); static long floorMod(final long a, final long b); static double copySign(double magnitude, double sign); static float copySign(float magnitude, float sign); static int getExponent(final double d); static int getExponent(final float f); static void main(String[] a); static final double PI; static final double E; }
@Test public void testLogSpecialCases() { Assert.assertTrue("Log of zero should be -Inf", Double.isInfinite(FastMath.log(0.0))); Assert.assertTrue("Log of -zero should be -Inf", Double.isInfinite(FastMath.log(-0.0))); Assert.assertTrue("Log of NaN should be NaN", Double.isNaN(FastMath.log(Double.NaN))); Assert.assertTrue("Log of negative number should be NaN", Double.isNaN(FastMath.log(-1.0))); Assert.assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, FastMath.log(Double.MIN_VALUE), Precision.EPSILON); Assert.assertTrue("Log of infinity should be infinity", Double.isInfinite(FastMath.log(Double.POSITIVE_INFINITY))); }
@Test public void testLogWithBase() { Assert.assertEquals(2.0, FastMath.log(2, 4), 0); Assert.assertEquals(3.0, FastMath.log(2, 8), 0); Assert.assertTrue(Double.isNaN(FastMath.log(-1, 1))); Assert.assertTrue(Double.isNaN(FastMath.log(1, -1))); Assert.assertTrue(Double.isNaN(FastMath.log(0, 0))); Assert.assertEquals(0, FastMath.log(0, 10), 0); Assert.assertEquals(Double.NEGATIVE_INFINITY, FastMath.log(10, 0), 0); }