diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-05-23 16:51:14 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-05-23 16:51:14 +0000 |
commit | 75867cb51ffae89047fdc2b699411b2e294abedc (patch) | |
tree | 7fbe11d736319fd4bf9bfac4627c3f9081e11fd2 | |
parent | 5d9e87e8a30dfc99fe41c3be0a8ddc5ddd4e1d8d (diff) |
added inlined math primitives in int/long/float/double namespaces
-rw-r--r-- | src/jvm/clojure/lang/Numbers.java | 72 | ||||
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 1 | ||||
-rw-r--r-- | src/primmath.clj | 87 |
3 files changed, 154 insertions, 6 deletions
diff --git a/src/jvm/clojure/lang/Numbers.java b/src/jvm/clojure/lang/Numbers.java index 86c6cb01..9a544f38 100644 --- a/src/jvm/clojure/lang/Numbers.java +++ b/src/jvm/clojure/lang/Numbers.java @@ -1220,15 +1220,75 @@ static BitOps bitOps(Object x){ return INTEGER_BITOPS; } -static public int addi(int x, int y) { - return x + y; +static public class I{ +static public int add(int x, int y) {return x + y;} +static public int subtract(int x, int y) {return x - y;} +static public int negate(int x) {return -x;} +static public int inc(int x) {return x+1;} +static public int dec(int x) {return x-1;} +static public int multiply(int x, int y) {return x * y;} +static public int divide(int x, int y) {return x / y;} +static public boolean equiv(int x, int y) {return x == y;} +static public boolean lt(int x, int y) {return x < y;} +static public boolean lte(int x, int y) {return x <= y;} +static public boolean gt(int x, int y) {return x > y;} +static public boolean gte(int x, int y) {return x >= y;} +static public boolean pos(int x) {return x > 0;} +static public boolean neg(int x) {return x < 0;} +static public boolean zero(int x) {return x == 0;} } -static public int subtracti(int x, int y) { - return x - y; +static public class L{ +static public long add(long x, long y) {return x + y;} +static public long subtract(long x, long y) {return x - y;} +static public long negate(long x) {return -x;} +static public long inc(long x) {return x+1;} +static public long dec(long x) {return x-1;} +static public long multiply(long x, long y) {return x * y;} +static public long divide(long x, long y) {return x / y;} +static public boolean equiv(long x, long y) {return x == y;} +static public boolean lt(long x, long y) {return x < y;} +static public boolean lte(long x, long y) {return x <= y;} +static public boolean gt(long x, long y) {return x > y;} +static public boolean gte(long x, long y) {return x >= y;} +static public boolean pos(long x) {return x > 0;} +static public boolean neg(long x) {return x < 0;} +static public boolean zero(long x) {return x == 0;} } -static public boolean lti(int x, int y) { - return x < y; +static public class F{ +static public float add(float x, float y) {return x + y;} +static public float subtract(float x, float y) {return x - y;} +static public float negate(float x) {return -x;} +static public float inc(float x) {return x+1;} +static public float dec(float x) {return x-1;} +static public float multiply(float x, float y) {return x * y;} +static public float divide(float x, float y) {return x / y;} +static public boolean equiv(float x, float y) {return x == y;} +static public boolean lt(float x, float y) {return x < y;} +static public boolean lte(float x, float y) {return x <= y;} +static public boolean gt(float x, float y) {return x > y;} +static public boolean gte(float x, float y) {return x >= y;} +static public boolean pos(float x) {return x > 0;} +static public boolean neg(float x) {return x < 0;} +static public boolean zero(float x) {return x == 0;} +} + +static public class D{ +static public double add(double x, double y) {return x + y;} +static public double subtract(double x, double y) {return x - y;} +static public double negate(double x) {return -x;} +static public double inc(double x) {return x+1;} +static public double dec(double x) {return x-1;} +static public double multiply(double x, double y) {return x * y;} +static public double divide(double x, double y) {return x / y;} +static public boolean equiv(double x, double y) {return x == y;} +static public boolean lt(double x, double y) {return x < y;} +static public boolean lte(double x, double y) {return x <= y;} +static public boolean gt(double x, double y) {return x > y;} +static public boolean gte(double x, double y) {return x >= y;} +static public boolean pos(double x) {return x > 0;} +static public boolean neg(double x) {return x < 0;} +static public boolean zero(double x) {return x == 0;} } } diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index efec0009..8d7922f9 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -286,6 +286,7 @@ static public void init() throws Exception{ static void doInit() throws Exception{ loadResourceScript(RT.class, "boot.clj"); + loadResourceScript(RT.class, "primmath.clj"); loadResourceScript(RT.class, "proxy.clj"); loadResourceScript(RT.class, "zip.clj"); loadResourceScript(RT.class, "xml.clj"); diff --git a/src/primmath.clj b/src/primmath.clj new file mode 100644 index 00000000..17b3360b --- /dev/null +++ b/src/primmath.clj @@ -0,0 +1,87 @@ +; Copyright (c) Rich Hickey. All rights reserved. +; The use and distribution terms for this software are covered by the +; Common Public License 1.0 (http://opensource.org/licenses/cpl.php) +; which can be found in the file CPL.TXT at the root of this distribution. +; By using this software in any fashion, you are agreeing to be bound by +; the terms of this license. +; You must not remove this notice, or any other, from this software. + +(in-ns 'int) +(clojure/refer 'clojure :exclude '(+ - * / == < <= > >= zero? pos? neg? inc dec)) +(import '(clojure.lang Numbers$I)) + +(definline + [x y] `(. Numbers$I add ~x ~y)) +(definline - [x y] `(. Numbers$I subtract ~x ~y)) +(definline * [x y] `(. Numbers$I multiply ~x ~y)) +(definline / [x y] `(. Numbers$I divide ~x ~y)) +(definline == [x y] `(. Numbers$I equiv ~x ~y)) +(definline < [x y] `(. Numbers$I lt ~x ~y)) +(definline <= [x y] `(. Numbers$I lte ~x ~y)) +(definline > [x y] `(. Numbers$I gt ~x ~y)) +(definline >= [x y] `(. Numbers$I gte ~x ~y)) +(definline zero? [x] `(. Numbers$I zero ~x)) +(definline pos? [x] `(. Numbers$I pos ~x)) +(definline neg? [x] `(. Numbers$I neg ~x)) +(definline inc [x] `(. Numbers$I inc ~x)) +(definline dec [x] `(. Numbers$I dec ~x)) +(definline negate [x] `(. Numbers$I negate ~x)) + +(in-ns 'long) +(clojure/refer 'clojure :exclude '(+ - * / == < <= > >= zero? pos? neg? inc dec)) +(import '(clojure.lang Numbers$L)) + +(definline + [x y] `(. Numbers$L add ~x ~y)) +(definline - [x y] `(. Numbers$L subtract ~x ~y)) +(definline * [x y] `(. Numbers$L multiply ~x ~y)) +(definline / [x y] `(. Numbers$L divide ~x ~y)) +(definline == [x y] `(. Numbers$L equiv ~x ~y)) +(definline < [x y] `(. Numbers$L lt ~x ~y)) +(definline <= [x y] `(. Numbers$L lte ~x ~y)) +(definline > [x y] `(. Numbers$L gt ~x ~y)) +(definline >= [x y] `(. Numbers$L gte ~x ~y)) +(definline zero? [x] `(. Numbers$L zero ~x)) +(definline pos? [x] `(. Numbers$L pos ~x)) +(definline neg? [x] `(. Numbers$L neg ~x)) +(definline inc [x] `(. Numbers$L inc ~x)) +(definline dec [x] `(. Numbers$L dec ~x)) +(definline negate [x] `(. Numbers$L negate ~x)) + +(in-ns 'float) +(clojure/refer 'clojure :exclude '(+ - * / == < <= > >= zero? pos? neg? inc dec)) +(import '(clojure.lang Numbers$F)) + +(definline + [x y] `(. Numbers$F add ~x ~y)) +(definline - [x y] `(. Numbers$F subtract ~x ~y)) +(definline * [x y] `(. Numbers$F multiply ~x ~y)) +(definline / [x y] `(. Numbers$F divide ~x ~y)) +(definline == [x y] `(. Numbers$F equiv ~x ~y)) +(definline < [x y] `(. Numbers$F lt ~x ~y)) +(definline <= [x y] `(. Numbers$F lte ~x ~y)) +(definline > [x y] `(. Numbers$F gt ~x ~y)) +(definline >= [x y] `(. Numbers$F gte ~x ~y)) +(definline zero? [x] `(. Numbers$F zero ~x)) +(definline pos? [x] `(. Numbers$F pos ~x)) +(definline neg? [x] `(. Numbers$F neg ~x)) +(definline inc [x] `(. Numbers$F inc ~x)) +(definline dec [x] `(. Numbers$F dec ~x)) +(definline negate [x] `(. Numbers$F negate ~x)) + +(in-ns 'double) +(clojure/refer 'clojure :exclude '(+ - * / == < <= > >= zero? pos? neg? inc dec)) +(import '(clojure.lang Numbers$D)) + +(definline + [x y] `(. Numbers$D add ~x ~y)) +(definline - [x y] `(. Numbers$D subtract ~x ~y)) +(definline * [x y] `(. Numbers$D multiply ~x ~y)) +(definline / [x y] `(. Numbers$D divide ~x ~y)) +(definline == [x y] `(. Numbers$D equiv ~x ~y)) +(definline < [x y] `(. Numbers$D lt ~x ~y)) +(definline <= [x y] `(. Numbers$D lte ~x ~y)) +(definline > [x y] `(. Numbers$D gt ~x ~y)) +(definline >= [x y] `(. Numbers$D gte ~x ~y)) +(definline zero? [x] `(. Numbers$D zero ~x)) +(definline pos? [x] `(. Numbers$D pos ~x)) +(definline neg? [x] `(. Numbers$D neg ~x)) +(definline inc [x] `(. Numbers$D inc ~x)) +(definline dec [x] `(. Numbers$D dec ~x)) +(definline negate [x] `(. Numbers$D negate ~x)) |