From c94edeb9b46bf6632b24eb2826a5b6ffe14b88da Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 29 Mar 2011 07:37:15 +0000 Subject: [PATCH] clean up math.java a little...standardize things to the actual Java class library...plus i didn't like having more ifs than needed --- Robust/src/ClassLibrary/Math.java | 102 ++++++++---------------------- 1 file changed, 27 insertions(+), 75 deletions(-) diff --git a/Robust/src/ClassLibrary/Math.java b/Robust/src/ClassLibrary/Math.java index 3e6cb49b..e03b27fa 100644 --- a/Robust/src/ClassLibrary/Math.java +++ b/Robust/src/ClassLibrary/Math.java @@ -1,9 +1,5 @@ public class Math { - - public static double setPI() { - double PI = 3.14159265358979323846; - return PI; - } + static final double PI=3.14159265358979323846; // an alias for setPI() public static double PI() { @@ -12,104 +8,60 @@ public class Math { } public static int abs(int x) { - if (x < 0) { - return -x; - } else { - return x; - } + return (x<0)?-x:x; } - public static double fabs(double x) { - if (x < 0) { - return -x; - } else { - return x; - } + public static long abs(long x) { + return (x<0)?-x:x; } public static double abs(double x) { - if (x < 0) { - return -x; - } else { - return x; - } + return (x<0)?-x:x; } - public static float abs(float a) { - if (a<0) - return -a; - else return a; + public static float abs(float x) { + return (x<0)?-x:x; } public static double max(double a, double b) { - if(a == b) - return a; - if(a > b) { - return a; - } else { - return b; - } + return (a>b)?a:b; + } + + public static float max(float a, float b) { + return (a>b)?a:b; } public static int max(int a, int b) { - if(a == b) - return a; - if(a > b) { - return a; - } else { - return b; - } + return (a>b)?a:b; } public static long max(long a, long b) { - if(a == b) - return a; - if(a > b) { - return a; - } else { - return b; - } + return (a>b)?a:b; } - public static long min(long a, long b) { - if(a == b) - return a; - if(a > b) { - return b; - } else { - return a; - } - } - - public static int imax(int a, int b) { - if(a == b) - return a; - if(a > b) { - return a; - } else { - return b; - } + public static double min(double a, double b) { + return (a b) { - return b; - } else { - return a; - } + public static float min(float a, float b) { + return (a fabs(b)) { + if (abs(a) > abs(b)) { r = b/a; - r = fabs(a)*sqrt(1+r*r); + r = abs(a)*sqrt(1+r*r); } else if (b != 0) { r = a/b; - r = fabs(b)*sqrt(1+r*r); + r = abs(b)*sqrt(1+r*r); } else { r = 0.0; } -- 2.34.1