summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jvm/clojure/lang/BigNum.java250
-rw-r--r--src/jvm/clojure/lang/DoubleNum.java208
-rw-r--r--src/jvm/clojure/lang/FixNum.java269
-rw-r--r--src/jvm/clojure/lang/FloatNum.java17
-rw-r--r--src/jvm/clojure/lang/IntegerNum.java73
-rw-r--r--src/jvm/clojure/lang/Num.java238
-rw-r--r--src/jvm/clojure/lang/RatioNum.java192
-rw-r--r--src/jvm/clojure/lang/RationalNum.java17
-rw-r--r--src/jvm/clojure/lang/RealNum.java17
-rw-r--r--src/jvm/clojure/lang/Reflector.java6
10 files changed, 3 insertions, 1284 deletions
diff --git a/src/jvm/clojure/lang/BigNum.java b/src/jvm/clojure/lang/BigNum.java
deleted file mode 100644
index 5a440059..00000000
--- a/src/jvm/clojure/lang/BigNum.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/**
- * 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.
- **/
-
-/* rich Mar 28, 2006 10:08:33 AM */
-
-package clojure.lang;
-
-import java.math.BigInteger;
-
-class BigNum extends IntegerNum{
-public BigInteger val;
-
-public boolean equals(Object arg0){
- return arg0 != null
- && arg0 instanceof BigNum
- && ((BigNum) arg0).val.equals(val);
-}
-
-public int hashCode(){
- return val.hashCode();
-}
-
-public String toString(){
- return val.toString();
-}
-
-public BigNum(long val){
- this.val = BigInteger.valueOf(val);
-}
-
-public BigNum(BigInteger val){
- this.val = val;
-}
-
-public double doubleValue(){
- return val.doubleValue();
-}
-
-public float floatValue(){
- return val.floatValue();
-}
-
-public int intValue(){
- return val.intValue();
-}
-
-public long longValue(){
- return val.longValue();
-}
-
-public boolean equiv(Num rhs){
- return rhs.equivTo(val);
-}
-
-public boolean equivTo(BigInteger x){
- return x.equals(val);
-}
-
-public boolean equivTo(int x){
- //must be outside of range of int or would be one itself
- return false;
-}
-
-public boolean equivTo(RatioNum x){
- //wouldn't still be a RatioNum if it was an integer
- return false;
-}
-
-public boolean lt(Num rhs){
- return rhs.gt(val);
-}
-
-public boolean gt(BigInteger x){
- return x.compareTo(val) < 0;
-}
-
-public boolean gt(int x){
- return BigInteger.valueOf(x).compareTo(val) < 0;
-}
-
-public boolean gt(RatioNum x){
- return x.numerator.lt(x.denominator.multiply(val));
-}
-
-public Num add(Num rhs){
- return rhs.addTo(val);
-}
-
-public Num addTo(BigInteger x){
- return Num.from(x.add(val));
-}
-
-public Num addTo(int x){
- return Num.from(val.add(BigInteger.valueOf(x)));
-}
-
-public Num addTo(RatioNum x){
- return x.addTo(val);
-}
-
-public Num subtractFrom(Num x){
- return x.addTo(val.negate());
-}
-
-public Num multiplyBy(Num rhs){
- return rhs.multiply(val);
-}
-
-public Num multiply(BigInteger x){
- return Num.from(x.multiply(val));
-}
-
-public Num multiply(int x){
- return Num.from(val.multiply(BigInteger.valueOf(x)));
-}
-
-public Num multiply(RatioNum x){
- return x.multiply(val);
-}
-
-public Num divideBy(Num rhs){
- return rhs.divide(val);
-}
-
-public Num divide(BigInteger n){
- return Num.divide(n, val);
-}
-
-public Num divide(int n){
- return Num.divide(BigInteger.valueOf(n), val);
-}
-
-public Num divide(RatioNum x){
- return Num.divide(x.numerator, x.denominator.multiply(val));
-}
-
-public Object[] truncateDivide(Num num){
- return num.truncateBy(val);
-}
-
-public Object[] truncateBy(int div){
- return Num.truncateBigints(val, BigInteger.valueOf(div));
-}
-
-public Object[] truncateBy(BigInteger div){
- return Num.truncateBigints(val, div);
-}
-
-public Object[] truncateBy(RatioNum div){
- Num q = (Num) Num.truncate(div.denominator.multiply(val), div.numerator)[0];
- return RT.setValues(q, q.multiplyBy(div).subtractFrom(this));
-}
-
-public Num negate(){
- return Num.from(val.negate());
-}
-
-public boolean minusp(){
- return val.signum() < 0;
-}
-
-public boolean plusp(){
- return val.signum() > 0;
-}
-
-public boolean zerop(){
- return val.compareTo(BigInteger.ZERO) == 0;
-}
-
-public Num oneMinus(){
- return Num.from(val.subtract(BigInteger.ONE));
-}
-
-public Num onePlus(){
- return Num.from(val.add(BigInteger.ONE));
-}
-
-public Num bitXorBy(IntegerNum rhs){
- return rhs.bitXor(val);
-}
-
-public Num bitXor(BigInteger y){
- return Num.from(val.xor(y));
-}
-
-public Num bitXor(int y){
- return Num.from(val.xor(BigInteger.valueOf(y)));
-}
-
-public Num bitAndBy(IntegerNum rhs){
- return rhs.bitAnd(val);
-}
-
-public Num bitAnd(int y){
- return Num.from(val.and(BigInteger.valueOf(y)));
-}
-
-public Num bitAnd(BigInteger y){
- return Num.from(val.and(y));
-}
-
-public Num bitOrBy(IntegerNum rhs){
- return rhs.bitOr(val);
-}
-
-public Num bitOr(int y){
- return Num.from(val.or(BigInteger.valueOf(y)));
-}
-
-public Num bitOr(BigInteger y){
- return Num.from(val.or(y));
-}
-
-public Num bitNot(){
- return Num.from(val.not());
-}
-
-public Num shiftLeftBy(IntegerNum rhs){
- return rhs.shiftLeft(val);
-}
-
-public Num shiftLeft(BigInteger y){
- return Num.from(val.shiftLeft(y.intValue()));
-}
-
-public Num shiftLeft(int y){
- return Num.from(val.shiftLeft(y));
-}
-
-public Num shiftRightBy(IntegerNum rhs){
- return rhs.shiftRight(val);
-}
-
-public Num shiftRight(BigInteger y){
- return Num.from(val.shiftRight(y.intValue()));
-}
-
-public Num shiftRight(int y){
- return Num.from(val.shiftRight(y));
-}
-
-}
-
diff --git a/src/jvm/clojure/lang/DoubleNum.java b/src/jvm/clojure/lang/DoubleNum.java
deleted file mode 100644
index f0e5e1c6..00000000
--- a/src/jvm/clojure/lang/DoubleNum.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/**
- * 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.
- **/
-
-/* rich Mar 28, 2006 10:13:45 AM */
-
-package clojure.lang;
-
-import java.math.BigInteger;
-import java.math.BigDecimal;
-
-class DoubleNum extends FloatNum{
-double val;
-
-public DoubleNum(double val){
- this.val = val;
-}
-
-public double doubleValue(){
- return val;
-}
-
-public float floatValue(){
- return (float) val;
-}
-
-public int intValue(){
- return (int) val;
-}
-
-public long longValue(){
- return (long) val;
-}
-
-final static BigInteger BIGTEN = BigInteger.valueOf(10);
-
-public Num toRational(){
- BigDecimal d = new BigDecimal(val);
- return Num.divide(d.unscaledValue(), BIGTEN.pow(d.scale()));
-}
-
-public boolean equiv(Num rhs){
- if(rhs instanceof RatioNum)
- return equivTo((RatioNum) rhs);
- return val == rhs.doubleValue();
-}
-
-public boolean equivTo(BigInteger x){
- return val == x.doubleValue();
-}
-
-public boolean equivTo(int x){
- return x == val;
-}
-
-public boolean equivTo(RatioNum x){
- return toRational().equivTo(x);
-}
-
-public boolean lt(Num rhs){
- if(rhs instanceof RatioNum)
- return toRational().lt(rhs);
- return val < rhs.doubleValue();
-}
-
-public boolean gt(BigInteger x){
- return val > x.doubleValue();
-}
-
-public boolean gt(int x){
- return val > x;
-}
-
-public boolean gt(RatioNum x){
- return toRational().gt(x);
-}
-
-public Num add(Num rhs){
- return Num.from(val + rhs.doubleValue());
-}
-
-public Num addTo(int x){
- return Num.from(val + x);
-}
-
-public Num addTo(BigInteger x){
- return Num.from(val + x.doubleValue());
-}
-
-public Num addTo(RatioNum x){
- return Num.from(val + x.doubleValue());
-}
-
-public Num subtractFrom(Num x){
- return Num.from(x.doubleValue() - val);
-}
-
-public Num multiplyBy(Num rhs){
- return Num.from(val * rhs.doubleValue());
-}
-
-public Num multiply(int x){
- return Num.from(val * x);
-}
-
-public Num multiply(BigInteger x){
- return Num.from(val * x.doubleValue());
-}
-
-public Num multiply(RatioNum x){
- return Num.from(val * x.doubleValue());
-}
-
-public Num divideBy(Num rhs){
- return Num.from(val / rhs.doubleValue());
-}
-
-public Num divide(int x){
- return Num.from(x / val);
-}
-
-public Num divide(BigInteger x){
- return Num.from(x.doubleValue() / val);
-}
-
-public Num divide(RatioNum x){
- return Num.from(x.doubleValue() / val);
-}
-
-static Object[] truncate(double n, double d){
- double q = n / d;
- if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE)
- {
- return RT.setValues(Num.from((int) q),
- Num.from(n - ((int) q) * d));
- }
- else
- { //bigint quotient
- Num bq = Num.from(new BigDecimal(q).toBigInteger());
- return RT.setValues(bq,
- Num.from(n - bq.doubleValue() * d));
- }
-}
-
-public Object[] truncateBy(BigInteger x){
- return truncate(val, x.doubleValue());
-}
-
-public Object[] truncateBy(int x){
- return truncate(val, x);
-}
-
-public Object[] truncateBy(RatioNum x){
- return truncate(val, x.doubleValue());
-}
-
-public Object[] truncateDivide(Num num){
- return truncate(num.doubleValue(), val);
-}
-
-public Num negate(){
- return Num.from(-val);
-}
-
-public boolean equals(Object arg0){
- return arg0 != null
- && arg0 instanceof DoubleNum
- && Double.doubleToLongBits(((DoubleNum) arg0).val) ==
- Double.doubleToLongBits(val);
-}
-
-public int hashCode(){
- long v = Double.doubleToLongBits(val);
- return (int) (v ^ (v >>> 32));
-}
-
-public String toString(){
- return Double.toString(val);
-}
-
-public boolean minusp(){
- return val < 0;
-}
-
-public boolean plusp(){
- return val > 0;
-}
-
-public boolean zerop(){
- return val == 0;
-}
-
-public Num oneMinus(){
- return Num.from(val - 1);
-}
-
-public Num onePlus(){
- return Num.from(val + 1);
-}
-
-}
-
diff --git a/src/jvm/clojure/lang/FixNum.java b/src/jvm/clojure/lang/FixNum.java
deleted file mode 100644
index b8cf7a6a..00000000
--- a/src/jvm/clojure/lang/FixNum.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/**
- * 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.
- **/
-
-/* rich Mar 28, 2006 10:09:27 AM */
-
-package clojure.lang;
-
-import java.math.BigInteger;
-
-class FixNum extends IntegerNum{
-public int val;
-
-public boolean equals(Object arg0){
- return arg0 != null
- && arg0 instanceof FixNum
- && ((FixNum) arg0).val == val;
-}
-
-public int hashCode(){
- return val;
-}
-
-public String toString(){
- return Integer.toString(val);
-}
-
-public FixNum(int val){
- this.val = val;
-}
-
-public double doubleValue(){
- return (double) val;
-}
-
-public float floatValue(){
- return (float) val;
-}
-
-public int intValue(){
- return val;
-}
-
-public long longValue(){
- return (long) val;
-}
-
-public boolean equiv(Num rhs){
- return rhs.equivTo(val);
-}
-
-public boolean equivTo(BigInteger x){
- //wouldn't still be a BigInteger if it fit in int
- return false;
-}
-
-public boolean equivTo(int x){
- return x == val;
-}
-
-public boolean equivTo(RatioNum x){
- //wouldn't still be a RatioNum if it was an integer
- return false;
-}
-
-public boolean lt(Num rhs){
- return rhs.gt(val);
-}
-
-public boolean gt(BigInteger x){
- return x.compareTo(BigInteger.valueOf(val)) < 0;
-}
-
-public boolean gt(int x){
- return x < val;
-}
-
-public boolean gt(RatioNum x){
- return x.numerator.lt(x.denominator.multiply(val));
-}
-
-public Num add(Num rhs){
- return rhs.addTo(val);
-}
-
-public Num addTo(BigInteger x){
- return Num.from(x.add(BigInteger.valueOf(val)));
-}
-
-public Num addTo(int x){
- return Num.from((long) x + val);
-}
-
-public Num addTo(RatioNum x){
- return x.addTo(val);
-}
-
-public Num subtractFrom(Num x){
- return x.addTo(-val);
-}
-
-public Num multiplyBy(Num rhs){
- return rhs.multiply(val);
-}
-
-public Num multiply(BigInteger x){
- return Num.from(x.multiply(BigInteger.valueOf(val)));
-}
-
-public Num multiply(int x){
- return Num.from((long) x * val);
-}
-
-public Num multiply(RatioNum x){
- return x.multiply(val);
-}
-
-public Object[] truncateDivide(Num num){
- return num.truncateBy(val);
-}
-
-public Object[] truncateBy(int div){
- return RT.setValues(Num.from(val / div), Num.from(val % div));
-}
-
-public Object[] truncateBy(BigInteger div){
- return Num.truncateBigints(BigInteger.valueOf(val), div);
-}
-
-public Object[] truncateBy(RatioNum div){
- Num q = (Num) Num.truncate(div.denominator.multiply(val), div.numerator)[0];
- return RT.setValues(q, q.multiplyBy(div).subtractFrom(this));
-}
-
-public Num divideBy(Num rhs){
- return rhs.divide(val);
-}
-
-public Num divide(BigInteger n){
- return Num.divide(n, BigInteger.valueOf(val));
-}
-
-static int gcd(int u, int v){
- while(v != 0)
- {
- int r = u % v;
- u = v;
- v = r;
- }
- return u;
-}
-
-public Num divide(int n){
- int gcd = gcd(n, val);
- if(gcd == 0)
- return Num.ZERO;
-
- n = n / gcd;
- int d = val / gcd;
- if(d == 1)
- return Num.from(n);
- if(d < 0)
- {
- n = -n;
- d = -d;
- }
- return new RatioNum((IntegerNum) Num.from(n), (IntegerNum) Num.from(d));
-}
-
-public Num divide(RatioNum x){
- return Num.divide(x.numerator, x.denominator.multiply(val));
-}
-
-public Num negate(){
- return Num.from(-val);
-}
-
-public boolean minusp(){
- return val < 0;
-}
-
-public boolean plusp(){
- return val > 0;
-}
-
-public boolean zerop(){
- return val == 0;
-}
-
-public Num oneMinus(){
- return Num.from(val - 1);
-}
-
-public Num onePlus(){
- return Num.from(val + 1);
-}
-
-public Num bitXorBy(IntegerNum rhs){
- return rhs.bitXor(val);
-}
-
-public Num bitXor(BigInteger y){
- return Num.from(BigInteger.valueOf(val).xor(y));
-}
-
-public Num bitXor(int y){
- return Num.from(val ^ y);
-}
-
-public Num bitAndBy(IntegerNum rhs){
- return rhs.bitAnd(val);
-}
-
-public Num bitAnd(int y){
- return Num.from(val & y);
-}
-
-public Num bitAnd(BigInteger y){
- return Num.from(BigInteger.valueOf(val).and(y));
-}
-
-public Num bitOrBy(IntegerNum rhs){
- return rhs.bitOr(val);
-}
-
-public Num bitOr(int y){
- return Num.from(val | y);
-}
-
-public Num bitOr(BigInteger y){
- return Num.from(BigInteger.valueOf(val).or(y));
-}
-
-public Num bitNot(){
- return Num.from(~val);
-}
-
-public Num shiftLeftBy(IntegerNum rhs){
- return rhs.shiftLeft(val);
-}
-
-public Num shiftLeft(BigInteger y){
- return Num.from(val << y.intValue());
-}
-
-public Num shiftLeft(int y){
- return Num.from(val << y);
-}
-
-public Num shiftRightBy(IntegerNum rhs){
- return rhs.shiftRight(val);
-}
-
-public Num shiftRight(BigInteger y){
- return Num.from(val >> y.intValue());
-}
-
-public Num shiftRight(int y){
- return Num.from(val >> y);
-}
-
-
-}
diff --git a/src/jvm/clojure/lang/FloatNum.java b/src/jvm/clojure/lang/FloatNum.java
deleted file mode 100644
index 8725b5de..00000000
--- a/src/jvm/clojure/lang/FloatNum.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * 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.
- **/
-
-/* rich Mar 28, 2006 10:17:21 AM */
-
-package clojure.lang;
-
-abstract class FloatNum extends RealNum {
-
-}
diff --git a/src/jvm/clojure/lang/IntegerNum.java b/src/jvm/clojure/lang/IntegerNum.java
deleted file mode 100644
index b931d18c..00000000
--- a/src/jvm/clojure/lang/IntegerNum.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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.
- **/
-
-/* rich Mar 28, 2006 10:11:55 AM */
-
-package clojure.lang;
-
-import java.math.BigInteger;
-
-abstract class IntegerNum extends RationalNum{
-static public Num bitXor(Object x, Object y){
- return ((IntegerNum) Num.from(y)).bitXorBy((IntegerNum) Num.from(x));
-}
-
-abstract public Num bitXorBy(IntegerNum y);
-
-abstract public Num bitXor(int y);
-
-abstract public Num bitXor(BigInteger y);
-
-static public Num bitAnd(Object x, Object y){
- return ((IntegerNum) Num.from(y)).bitAndBy((IntegerNum) Num.from(x));
-}
-
-abstract public Num bitAndBy(IntegerNum y);
-
-abstract public Num bitAnd(int y);
-
-abstract public Num bitAnd(BigInteger y);
-
-static public Num bitOr(Object x, Object y){
- return ((IntegerNum) Num.from(y)).bitOrBy((IntegerNum) Num.from(x));
-}
-
-abstract public Num bitOrBy(IntegerNum y);
-
-abstract public Num bitOr(int y);
-
-abstract public Num bitOr(BigInteger y);
-
-static public Num bitNot(Object x){
- return ((IntegerNum) Num.from(x)).bitNot();
-}
-
-abstract public Num bitNot();
-
-static public Num shiftLeft(Object x, Object y){
- return ((IntegerNum) Num.from(y)).shiftLeftBy((IntegerNum) Num.from(x));
-}
-
-abstract public Num shiftLeftBy(IntegerNum y);
-
-abstract public Num shiftLeft(BigInteger y);
-
-abstract public Num shiftLeft(int y);
-
-static public Num shiftRight(Object x, Object y){
- return ((IntegerNum) Num.from(y)).shiftRightBy((IntegerNum) Num.from(x));
-}
-
-abstract public Num shiftRightBy(IntegerNum y);
-
-abstract public Num shiftRight(BigInteger y);
-
-abstract public Num shiftRight(int y);
-} \ No newline at end of file
diff --git a/src/jvm/clojure/lang/Num.java b/src/jvm/clojure/lang/Num.java
deleted file mode 100644
index 30f72acd..00000000
--- a/src/jvm/clojure/lang/Num.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/**
- * 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.
- **/
-
-/* rich Mar 28, 2006 10:07:33 AM */
-
-package clojure.lang;
-
-import java.math.BigInteger;
-
-abstract class Num extends Number implements Comparable{
-
-public final static Num ZERO = from(0);
-public final static Num ONE = from(1);
-
-static public Num from(int val){
- //todo - cache a bunch of small fixnums
- return new FixNum(val);
-}
-
-static public Num from(double val){
- return new DoubleNum(val);
-}
-
-static public Num from(long val){
- if(val <= Integer.MAX_VALUE && val >= Integer.MIN_VALUE)
- return from((int) val);
- else
- return new BigNum(val);
-}
-
-static public Num from(BigInteger val){
- if(val.bitLength() < 32)
- return from(val.intValue());
- else
- return new BigNum(val);
-}
-
-static public Num from(Object x){
- if(x instanceof Num)
- return (Num) x;
- else
- {
- Class c = x.getClass();
- if(c == Integer.class)
- return Num.from(((Integer) x).intValue());
- else if(c == Double.class || c == Float.class)
- return Num.from(((Number) x).doubleValue());
- else if(c == Long.class)
- return Num.from(((Long) x).longValue());
- else if(c == BigInteger.class)
- return Num.from((BigInteger) x);
- else
- return Num.from(((Number) x).intValue());
- }
-}
-
-static public Num add(Object x, Object y){
- //if(x instanceof Num && y instanceof Num)
- //return ((Num)x).add((Num) y);
- return Num.from(x).add(Num.from(y));
-}
-
-abstract public Num add(Num rhs);
-
-abstract public Num addTo(int x);
-
-abstract public Num addTo(BigInteger x);
-
-abstract public Num addTo(RatioNum x);
-
-static public Num subtract(Object x, Object y){
- return Num.from(y).subtractFrom(Num.from(x));
-}
-
-//this double-dispatches to addTo(-self)
-abstract public Num subtractFrom(Num rhs);
-
-static public Num multiply(Object x, Object y){
- return Num.from(x).multiplyBy(Num.from(y));
-}
-
-abstract public Num multiplyBy(Num rhs);
-
-abstract public Num multiply(int x);
-
-abstract public Num multiply(BigInteger x);
-
-abstract public Num multiply(RatioNum x);
-
-static public Num divide(Object x, Object y){
- Num ny = Num.from(y);
- if(ny.zerop())
- throw new ArithmeticException("Divide by zero");
- return Num.from(x).divideBy(ny);
-}
-
-abstract public Num divideBy(Num rhs);
-
-abstract public Num divide(int x);
-
-abstract public Num divide(BigInteger x);
-
-abstract public Num divide(RatioNum x);
-
-static public Object[] truncate(Object num, Object div){
- return Num.from(div).truncateDivide(Num.from(num));
-}
-
-static public Object quotient(Object num, Object div){
- return truncate(num, div)[0];
-}
-
-static public Object remainder(Object num, Object div){
- return truncate(num, div)[1];
-}
-
-abstract public Object[] truncateDivide(Num rhs);
-
-abstract public Object[] truncateBy(int x);
-
-abstract public Object[] truncateBy(BigInteger x);
-
-abstract public Object[] truncateBy(RatioNum x);
-
-static public Object[] truncateBigints(BigInteger n, BigInteger d){
- BigInteger[] result = n.divideAndRemainder(d);
- return RT.setValues(Num.from(result[0]), Num.from(result[1]));
-}
-
-static public Num divide(BigInteger n, BigInteger d){
- if(d.equals(BigInteger.ZERO))
- throw new ArithmeticException("Divide by zero");
- BigInteger gcd = n.gcd(d);
- if(gcd.equals(BigInteger.ZERO))
- return Num.ZERO;
- n = n.divide(gcd);
- d = d.divide(gcd);
- if(d.equals(BigInteger.ONE))
- return Num.from(n);
- return new RatioNum((IntegerNum) Num.from(d.signum() < 0 ? n.negate() : n),
- (IntegerNum) Num.from(d.signum() < 0 ? d.negate() : d));
-}
-
-static public boolean equiv(Object x, Object y){
- if(!(y instanceof Number && x instanceof Number))
- return false;
- return Num.from(x).equiv(Num.from(y));
-}
-
-abstract public boolean equiv(Num rhs);
-
-abstract public boolean equivTo(int x);
-
-abstract public boolean equivTo(BigInteger x);
-
-abstract public boolean equivTo(RatioNum x);
-
-static public boolean lt(Object x, Object y){
- return Num.from(x).lt(Num.from(y));
-}
-
-static public boolean lte(Object x, Object y){
- Num lx = Num.from(x);
- Num ly = Num.from(y);
- return lx.lt(ly) || lx.equiv(ly);
-}
-
-static public boolean gt(Object x, Object y){
- return Num.from(y).lt(Num.from(x));
-}
-
-static public boolean gte(Object x, Object y){
- Num lx = Num.from(x);
- Num ly = Num.from(y);
- return ly.lt(lx) || lx.equiv(ly);
-}
-
-abstract public boolean lt(Num rhs);
-
-abstract public boolean gt(int x);
-
-abstract public boolean gt(BigInteger x);
-
-abstract public boolean gt(RatioNum x);
-
-static public Num negate(Object x){
- return Num.from(x).negate();
-}
-
-static public Object negPred(Object x){
- return Num.from(x).minusp() ? RT.T : RT.F;
-}
-
-static public Object posPred(Object x){
- return Num.from(x).plusp() ? RT.T : RT.F;
-}
-
-static public Object zeroPred(Object x){
- return Num.from(x).zerop() ? RT.T : RT.F;
-}
-
-static public Num dec(Object x){
- return Num.from(x).oneMinus();
-}
-
-static public Num inc(Object x){
- return Num.from(x).onePlus();
-}
-
-abstract public Num negate();
-
-abstract public boolean minusp();
-
-abstract public boolean plusp();
-
-abstract public boolean zerop();
-
-abstract public Num oneMinus();
-
-abstract public Num onePlus();
-
-public int compareTo(Object object){
- Num other = Num.from(object);
- if(this.equiv(other))
- return 0;
- else if(this.lt(other))
- return -1;
- else
- return 1;
-}
-}
diff --git a/src/jvm/clojure/lang/RatioNum.java b/src/jvm/clojure/lang/RatioNum.java
deleted file mode 100644
index 63630032..00000000
--- a/src/jvm/clojure/lang/RatioNum.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * 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.
- **/
-
-/* rich Mar 28, 2006 10:14:44 AM */
-
-package clojure.lang;
-
-import java.math.BigInteger;
-
-class RatioNum extends RationalNum{
-public boolean equals(Object arg0){
- return arg0 != null
- && arg0 instanceof RatioNum
- && ((RatioNum) arg0).numerator.equals(numerator)
- && ((RatioNum) arg0).denominator.equals(denominator);
-}
-
-public int hashCode(){
- return numerator.hashCode() ^ denominator.hashCode();
-}
-
-public String toString(){
- return numerator.toString() + "/" + denominator.toString();
-}
-
-public IntegerNum numerator;
-public IntegerNum denominator;
-
-public RatioNum(IntegerNum n, IntegerNum d){
- this.numerator = n;
- this.denominator = d;
-}
-
-public double doubleValue(){
- return numerator.doubleValue() / denominator.doubleValue();
-}
-
-public float floatValue(){
- return (float) doubleValue();
-}
-
-public int intValue(){
- return (int) doubleValue();
-}
-
-public long longValue(){
- return (long) doubleValue();
-}
-
-public boolean equiv(Num rhs){
- return rhs.equivTo(this);
-}
-
-public boolean equivTo(BigInteger x){
- return false;
-}
-
-public boolean equivTo(int x){
- return false;
-}
-
-public boolean equivTo(RatioNum x){
- return numerator.equiv(x.numerator) && denominator.equiv(x.denominator);
-}
-
-public boolean lt(Num rhs){
- return rhs.gt(this);
-}
-
-public boolean gt(BigInteger x){
- return denominator.multiply(x).lt(numerator);
-}
-
-public boolean gt(int x){
- return denominator.multiply(x).lt(numerator);
-}
-
-public boolean gt(RatioNum x){
- return x.numerator.multiplyBy(denominator).lt(numerator.multiplyBy(x.denominator));
-}
-
-public Num add(Num rhs){
- return rhs.addTo(this);
-}
-
-public Num addTo(BigInteger x){
- return Num.divide(numerator.add(denominator.multiply(x)), denominator);
-}
-
-public Num addTo(int x){
- return Num.divide(numerator.add(denominator.multiply(x)), denominator);
-}
-
-public Num addTo(RatioNum x){
- return Num.divide(numerator.multiplyBy(x.denominator)
- .add(x.numerator.multiplyBy(denominator))
- , denominator.multiplyBy(x.denominator));
-}
-
-public Num subtractFrom(Num x){
- return x.add(this.multiply(-1));
-}
-
-public Num multiplyBy(Num rhs){
- return rhs.multiply(this);
-}
-
-public Num multiply(BigInteger x){
- return Num.divide(numerator.multiply(x), denominator);
-}
-
-public Num multiply(int x){
- return Num.divide(numerator.multiply(x), denominator);
-}
-
-public Num multiply(RatioNum x){
- return Num.divide(numerator.multiplyBy(x.numerator)
- , denominator.multiplyBy(x.denominator));
-}
-
-public Num divideBy(Num rhs){
- return rhs.divide(this);
-}
-
-public Num divide(BigInteger n){
- return Num.divide(denominator.multiply(n), numerator);
-}
-
-public Num divide(int n){
- return Num.divide(denominator.multiply(n), numerator);
-}
-
-public Num divide(RatioNum n){
- return Num.divide(denominator.multiplyBy(n.numerator)
- , numerator.multiplyBy(n.denominator));
-}
-
-
-public Object[] truncateDivide(Num num){
- return num.truncateBy(this);
-}
-
-public Object[] truncateBy(int div){
- Num q = (Num) Num.truncate(numerator, denominator.multiply(div))[0];
- return RT.setValues(q, q.multiply(div).subtractFrom(this));
-}
-
-public Object[] truncateBy(BigInteger div){
- Num q = (Num) Num.truncate(numerator, denominator.multiply(div))[0];
- return RT.setValues(q, q.multiply(div).subtractFrom(this));
-}
-
-public Object[] truncateBy(RatioNum div){
- Num q = (Num) Num.truncate(numerator.multiplyBy(div.denominator),
- denominator.multiplyBy(div.numerator))[0];
- return RT.setValues(q, q.multiplyBy(div).subtractFrom(this));
-}
-
-
-public Num negate(){
- return Num.divide(numerator.negate(), denominator);
-}
-
-public boolean minusp(){
- return numerator.minusp();
-}
-
-publ