From 4409cc6ce1bf1e1fc4df0208b00f6f9ca7632aa3 Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Fri, 6 May 2011 11:06:52 -0400 Subject: [PATCH] inline min/max #784 - not contagious - do math inline for #{prim prim}, #{obj double} - delegate to gt/lt for #{obj long} #{obj obj} --- src/clj/clojure/core.clj | 10 ++- src/jvm/clojure/lang/Numbers.java | 146 +++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 4 deletions(-) diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 3f12284..32a1c55 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1033,18 +1033,20 @@ (defn max "Returns the greatest of the nums." {:added "1.0" - :static true} + :inline-arities #{2} + :inline (fn [x y] `(. clojure.lang.Numbers (max ~x ~y)))} ([x] x) - ([x y] (if (> x y) x y)) + ([x y] (. clojure.lang.Numbers (max x y))) ([x y & more] (reduce1 max (max x y) more))) (defn min "Returns the least of the nums." {:added "1.0" - :static true} + :inline-arities #{2} + :inline (fn [x y] `(. clojure.lang.Numbers (min ~x ~y)))} ([x] x) - ([x y] (if (< x y) x y)) + ([x y] (. clojure.lang.Numbers (min x y))) ([x y & more] (reduce1 min (min x y) more))) diff --git a/src/jvm/clojure/lang/Numbers.java b/src/jvm/clojure/lang/Numbers.java index a5c151b..b89ee0e 100644 --- a/src/jvm/clojure/lang/Numbers.java +++ b/src/jvm/clojure/lang/Numbers.java @@ -3797,5 +3797,151 @@ static public boolean equiv(long x, double y){ return x == y; } +static public double max(double x, double y){ + if(x > y){ + return x; + } else { + return y; + } +} + +static public Object max(double x, long y){ + if(x > y){ + return x; + } else { + return y; + } +} + +static public Object max(double x, Object y){ + if(x > ((Number)y).doubleValue()){ + return x; + } else { + return y; + } +} + +static public Object max(long x, double y){ + if(x > y){ + return x; + } else { + return y; + } +} + + +static public long max(long x, long y){ + if(x > y) { + return x; + } else { + return y; + } +} + +static public Object max(long x, Object y){ + if(gt(x,y)){ + return x; + } else { + return y; + } +} + +static public Object max(Object x, long y){ + if(gt(x,y)){ + return x; + } else { + return y; + } +} + +static public Object max(Object x, double y){ + if(((Number)x).doubleValue() > y){ + return x; + } else { + return y; + } +} + +static public Object max(Object x, Object y){ + if(gt(x, y)) { + return x; + } else { + return y; + } +} + + +static public double min(double x, double y){ + if(x < y){ + return x; + } else { + return y; + } +} + +static public Object min(double x, long y){ + if(x < y){ + return x; + } else { + return y; + } +} + +static public Object min(double x, Object y){ + if(x < ((Number)y).doubleValue()){ + return x; + } else { + return y; + } +} + +static public Object min(long x, double y){ + if(x < y){ + return x; + } else { + return y; + } +} + + +static public long min(long x, long y){ + if(x < y) { + return x; + } else { + return y; + } +} + +static public Object min(long x, Object y){ + if(lt(x,y)){ + return x; + } else { + return y; + } +} + +static public Object min(Object x, long y){ + if(lt(x,y)){ + return x; + } else { + return y; + } +} + +static public Object min(Object x, double y){ + if(((Number)x).doubleValue() < y){ + return x; + } else { + return y; + } +} + +static public Object min(Object x, Object y){ + if(lt(x,y)) { + return x; + } else { + return y; + } +} } -- 1.7.3.5