summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2010-06-25 13:13:02 -0400
committerRich Hickey <richhickey@gmail.com>2010-06-25 13:13:02 -0400
commit07f05862c2362f6b51e7c92ccd9476c45c9dff6e (patch)
treee518b40a8858e118c54d0ae9a19d6bb7ca542a40
parent845c63e9317826a5564ef766550562b3fbe68181 (diff)
incorporate BigIntequiv
-rw-r--r--src/clj/clojure/core.clj14
-rw-r--r--src/clj/clojure/core_print.clj7
-rw-r--r--src/clj/clojure/pprint/cl_format.clj2
-rw-r--r--src/jvm/clojure/lang/BigInt.java18
-rw-r--r--src/jvm/clojure/lang/LispReader.java14
-rw-r--r--src/jvm/clojure/lang/Numbers.java191
-rw-r--r--src/jvm/clojure/lang/RT.java14
-rw-r--r--src/jvm/clojure/lang/Util.java1
-rw-r--r--test/clojure/test_clojure/numbers.clj2
-rw-r--r--test/clojure/test_clojure/reader.clj11
10 files changed, 165 insertions, 109 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index b35722b6..55d4d588 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -3008,6 +3008,7 @@
[n]
(or (instance? Integer n)
(instance? Long n)
+ (instance? clojure.lang.BigInt n)
(instance? BigInteger n)
(instance? Short n)
(instance? Byte n)))
@@ -3065,6 +3066,19 @@
(or (integer? n) (ratio? n) (decimal? n)))
(defn bigint
+ "Coerce to BigInt"
+ {:tag clojure.lang.BigInt
+ :static true
+ :added "1.3"}
+ [x] (cond
+ (instance? clojure.lang.BigInt x) x
+ (instance? BigInteger x) (clojure.lang.BigInt/fromBigInteger x)
+ (decimal? x) (bigint (.toBigInteger ^BigDecimal x))
+ (ratio? x) (bigint (.bigIntegerValue ^clojure.lang.Ratio x))
+ (number? x) (clojure.lang.BigInt/valueOf (long x))
+ :else (bigint (BigInteger. x))))
+
+(defn biginteger
"Coerce to BigInteger"
{:tag BigInteger
:added "1.0"
diff --git a/src/clj/clojure/core_print.clj b/src/clj/clojure/core_print.clj
index 21af0ac9..a8a198fd 100644
--- a/src/clj/clojure/core_print.clj
+++ b/src/clj/clojure/core_print.clj
@@ -242,6 +242,7 @@
(defmethod print-dup java.lang.Double [o w] (print-method o w))
(defmethod print-dup clojure.lang.Ratio [o w] (print-method o w))
(defmethod print-dup java.math.BigDecimal [o w] (print-method o w))
+(defmethod print-dup clojure.lang.BigInt [o w] (print-method o w))
(defmethod print-dup java.math.BigInteger [o w] (print-method o w))
(defmethod print-dup clojure.lang.PersistentHashMap [o w] (print-method o w))
(defmethod print-dup clojure.lang.PersistentHashSet [o w] (print-method o w))
@@ -279,10 +280,14 @@
(.write w (str b))
(.write w "M"))
-(defmethod print-method java.math.BigInteger [b, ^Writer w]
+(defmethod print-method clojure.lang.BigInt [b, ^Writer w]
(.write w (str b))
(.write w "N"))
+(defmethod print-method java.math.BigInteger [b, ^Writer w]
+ (.write w (str b))
+ (.write w "BIGINT"))
+
(defmethod print-method java.util.regex.Pattern [p ^Writer w]
(.write w "#\"")
(loop [[^Character c & r :as s] (seq (.pattern ^java.util.regex.Pattern p))
diff --git a/src/clj/clojure/pprint/cl_format.clj b/src/clj/clojure/pprint/cl_format.clj
index 22bb11b2..5c934f31 100644
--- a/src/clj/clojure/pprint/cl_format.clj
+++ b/src/clj/clojure/pprint/cl_format.clj
@@ -247,7 +247,7 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
for improved performance"
[base val]
(let [format-str (get java-base-formats base)]
- (if (and format-str (integer? val))
+ (if (and format-str (integer? val) (not (instance? clojure.lang.BigInt val)))
(clojure.core/format format-str val)
(base-str base val))))
diff --git a/src/jvm/clojure/lang/BigInt.java b/src/jvm/clojure/lang/BigInt.java
index 1732a760..a678fd51 100644
--- a/src/jvm/clojure/lang/BigInt.java
+++ b/src/jvm/clojure/lang/BigInt.java
@@ -19,6 +19,10 @@ public final class BigInt extends Number{
final public long lpart;
final public BigInteger bipart;
+final public static BigInt ZERO = new BigInt(0,null);
+final public static BigInt ONE = new BigInt(1,null);
+
+
//must follow Long
public int hashCode(){
if(bipart == null)
@@ -106,4 +110,18 @@ public short shortValue(){
return bipart.shortValue();
}
+public static BigInt valueOf(long val){
+ return new BigInt(val, null);
+}
+
+public String toString(){
+ if(bipart == null)
+ return String.valueOf(lpart);
+ return bipart.toString();
+}
+
+public int bitLength(){
+ return toBigInteger().bitLength();
+}
+
}
diff --git a/src/jvm/clojure/lang/LispReader.java b/src/jvm/clojure/lang/LispReader.java
index e7cf1560..9589472f 100644
--- a/src/jvm/clojure/lang/LispReader.java
+++ b/src/jvm/clojure/lang/LispReader.java
@@ -329,7 +329,7 @@ private static Object matchNumber(String s){
if(m.group(2) != null)
{
if(m.group(8) != null)
- return BigInteger.ZERO;
+ return BigInt.ZERO;
return Numbers.num(0);
}
boolean negate = (m.group(1).equals("-"));
@@ -346,9 +346,13 @@ private static Object matchNumber(String s){
if(n == null)
return null;
BigInteger bn = new BigInteger(n, radix);
+ if(negate)
+ bn = bn.negate();
if(m.group(8) != null)
- return negate ? bn.negate() : bn;
- return Numbers.reduceBigInteger(negate ? bn.negate() : bn);
+ return BigInt.fromBigInteger(bn);
+ return bn.bitLength() < 64 ?
+ Numbers.num(bn.longValue())
+ : BigInt.fromBigInteger(bn);
}
m = floatPat.matcher(s);
if(m.matches())
@@ -360,8 +364,8 @@ private static Object matchNumber(String s){
m = ratioPat.matcher(s);
if(m.matches())
{
- return Numbers.divide(Numbers.reduceBigInteger(new BigInteger(m.group(1))),
- Numbers.reduceBigInteger((new BigInteger(m.group(2)))));
+ return Numbers.divide(Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(m.group(1)))),
+ Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(m.group(2)))));
}
return null;
}
diff --git a/src/jvm/clojure/lang/Numbers.java b/src/jvm/clojure/lang/Numbers.java
index 42dc9611..c68d393a 100644
--- a/src/jvm/clojure/lang/Numbers.java
+++ b/src/jvm/clojure/lang/Numbers.java
@@ -27,7 +27,7 @@ static interface Ops{
Ops opsWith(RatioOps x);
- Ops opsWith(BigIntegerOps x);
+ Ops opsWith(BigIntOps x);
Ops opsWith(BigDecimalOps x);
@@ -90,7 +90,7 @@ static interface BitOps{
BitOps bitOpsWith(LongBitOps x);
- BitOps bitOpsWith(BigIntegerBitOps x);
+ BitOps bitOpsWith(BigIntBitOps x);
public Number not(Number x);
@@ -262,9 +262,20 @@ static public int compare(Number x, Number y){
return 0;
}
+static BigInt toBigInt(Object x){
+ if(x instanceof BigInt)
+ return (BigInt) x;
+ if(x instanceof BigInteger)
+ return BigInt.fromBigInteger((BigInteger) x);
+ else
+ return BigInt.fromLong(((Number) x).longValue());
+}
+
static BigInteger toBigInteger(Object x){
if(x instanceof BigInteger)
return (BigInteger) x;
+ else if(x instanceof BigInt)
+ return ((BigInt) x).toBigInteger();
else
return BigInteger.valueOf(((Number) x).longValue());
}
@@ -272,6 +283,14 @@ static BigInteger toBigInteger(Object x){
static BigDecimal toBigDecimal(Object x){
if(x instanceof BigDecimal)
return (BigDecimal) x;
+ else if(x instanceof BigInt)
+ {
+ BigInt bi = (BigInt) x;
+ if(bi.bipart == null)
+ return BigDecimal.valueOf(bi.lpart);
+ else
+ return new BigDecimal(bi.bipart);
+ }
else if(x instanceof BigInteger)
return new BigDecimal((BigInteger) x);
else if(x instanceof Double)
@@ -312,7 +331,7 @@ static public Number rationalize(Number x){
BigInteger bv = bx.unscaledValue();
int scale = bx.scale();
if(scale < 0)
- return bv.multiply(BigInteger.TEN.pow(-scale));
+ return BigInt.fromBigInteger(bv.multiply(BigInteger.TEN.pow(-scale)));
else
return divide(bv, BigInteger.TEN.pow(scale));
}
@@ -335,15 +354,11 @@ static public Number rationalize(Number x){
// return Double.valueOf((double) val);
//}
-static public Number reduceBigInteger(BigInteger val){
- int bitLength = val.bitLength();
-// if(bitLength < 32)
-// return val.intValue();
-// else
- if(bitLength < 64)
- return num(val.longValue());
+static public Number reduceBigInt(BigInt val){
+ if(val.bipart == null)
+ return num(val.lpart);
else
- return val;
+ return val.bipart;
}
static public Number divide(BigInteger n, BigInteger d){
@@ -351,13 +366,13 @@ static public Number divide(BigInteger n, BigInteger d){
throw new ArithmeticException("Divide by zero");
BigInteger gcd = n.gcd(d);
if(gcd.equals(BigInteger.ZERO))
- return 0;
+ return BigInt.ZERO;
n = n.divide(gcd);
d = d.divide(gcd);
if(d.equals(BigInteger.ONE))
- return reduceBigInteger(n);
+ return BigInt.fromBigInteger(n);
else if(d.equals(BigInteger.ONE.negate()))
- return reduceBigInteger(n.negate());
+ return BigInt.fromBigInteger(n.negate());
return new Ratio((d.signum() < 0 ? n.negate() : n),
(d.signum() < 0 ? d.negate() : d));
}
@@ -452,8 +467,8 @@ final static class LongOps implements Ops{
return RATIO_OPS;
}
- final public Ops opsWith(BigIntegerOps x){
- return BIGINTEGER_OPS;
+ final public Ops opsWith(BigIntOps x){
+ return BIGINT_OPS;
}
final public Ops opsWith(BigDecimalOps x){
@@ -480,7 +495,7 @@ final static class LongOps implements Ops{
long lx = x.longValue(), ly = y.longValue();
long ret = lx + ly;
if ((ret ^ lx) < 0 && (ret ^ ly) < 0)
- return BIGINTEGER_OPS.add(x, y);
+ return BIGINT_OPS.add(x, y);
return num(ret);
}
@@ -492,7 +507,7 @@ final static class LongOps implements Ops{
long lx = x.longValue(), ly = y.longValue();
long ret = lx * ly;
if (ly != 0 && ret/ly != lx)
- return BIGINTEGER_OPS.multiply(x, y);
+ return BIGINT_OPS.multiply(x, y);
return num(ret);
}
static long gcd(long u, long v){
@@ -550,7 +565,7 @@ final static class LongOps implements Ops{
long val = x.longValue();
if(val > Long.MIN_VALUE)
return num(-val);
- return BigInteger.valueOf(val).negate();
+ return BigInt.fromBigInteger(BigInteger.valueOf(val).negate());
}
public Number inc(Number x){
long val = x.longValue();
@@ -561,7 +576,7 @@ final static class LongOps implements Ops{
long val = x.longValue();
if(val < Long.MAX_VALUE)
return num(val + 1);
- return BIGINTEGER_OPS.inc(x);
+ return BIGINT_OPS.inc(x);
}
public Number dec(Number x){
@@ -573,7 +588,7 @@ final static class LongOps implements Ops{
long val = x.longValue();
if(val > Long.MIN_VALUE)
return num(val - 1);
- return BIGINTEGER_OPS.dec(x);
+ return BIGINT_OPS.dec(x);
}
}
@@ -594,7 +609,7 @@ final static class DoubleOps extends OpsP{
return this;
}
- final public Ops opsWith(BigIntegerOps x){
+ final public Ops opsWith(BigIntOps x){
return this;
}
@@ -673,7 +688,7 @@ final static class RatioOps extends OpsP{
return this;
}
- final public Ops opsWith(BigIntegerOps x){
+ final public Ops opsWith(BigIntOps x){
return this;
}
@@ -697,10 +712,10 @@ final static class RatioOps extends OpsP{
}
static Number normalizeRet(Number ret, Number x, Number y){
- if(ret instanceof BigInteger && !(x instanceof BigInteger || y instanceof BigInteger))
- {
- return reduceBigInteger((BigInteger) ret);
- }
+// if(ret instanceof BigInteger && !(x instanceof BigInteger || y instanceof BigInteger))
+// {
+// return reduceBigInt((BigInteger) ret);
+// }
return ret;
}
@@ -734,7 +749,7 @@ final static class RatioOps extends OpsP{
Ratio ry = toRatio(y);
BigInteger q = rx.numerator.multiply(ry.denominator).divide(
rx.denominator.multiply(ry.numerator));
- return normalizeRet(q, x, y);
+ return normalizeRet(BigInt.fromBigInteger(q), x, y);
}
public Number remainder(Number x, Number y){
@@ -775,7 +790,7 @@ final static class RatioOps extends OpsP{
}
-final static class BigIntegerOps extends OpsP{
+final static class BigIntOps extends OpsP{
public Ops combine(Ops y){
return y.opsWith(this);
}
@@ -792,7 +807,7 @@ final static class BigIntegerOps extends OpsP{
return RATIO_OPS;
}
- final public Ops opsWith(BigIntegerOps x){
+ final public Ops opsWith(BigIntOps x){
return this;
}
@@ -801,26 +816,32 @@ final static class BigIntegerOps extends OpsP{
}
public boolean isZero(Number x){
- BigInteger bx = toBigInteger(x);
- return bx.signum() == 0;
+ BigInt bx = toBigInt(x);
+ if(bx.bipart == null)
+ return bx.lpart == 0;
+ return bx.bipart.signum() == 0;
}
public boolean isPos(Number x){
- BigInteger bx = toBigInteger(x);
- return bx.signum() > 0;
+ BigInt bx = toBigInt(x);
+ if(bx.bipart == null)
+ return bx.lpart > 0;
+ return bx.bipart.signum() > 0;
}
public boolean isNeg(Number x){
- BigInteger bx = toBigInteger(x);
- return bx.signum() < 0;
+ BigInt bx = toBigInt(x);
+ if(bx.bipart == null)
+ return bx.lpart < 0;
+ return bx.bipart.signum() < 0;
}
final public Number add(Number x, Number y){
- return reduceBigInteger(toBigInteger(x).add(toBigInteger(y)));
+ return BigInt.fromBigInteger(toBigInteger(x).add(toBigInteger(y)));
}
final public Number multiply(Number x, Number y){
- return reduceBigInteger(toBigInteger(x).multiply(toBigInteger(y)));
+ return BigInt.fromBigInteger(toBigInteger(x).multiply(toBigInteger(y)));
}
public Number divide(Number x, Number y){
@@ -828,15 +849,15 @@ final static class BigIntegerOps extends OpsP{
}
public Number quotient(Number x, Number y){
- return reduceBigInteger(toBigInteger(x).divide(toBigInteger(y)));
+ return BigInt.fromBigInteger(toBigInteger(x).divide(toBigInteger(y)));
}
public Number remainder(Number x, Number y){
- return reduceBigInteger(toBigInteger(x).remainder(toBigInteger(y)));
+ return BigInt.fromBigInteger(toBigInteger(x).remainder(toBigInteger(y)));
}
public boolean equiv(Number x, Number y){
- return toBigInteger(x).equals(toBigInteger(y));
+ return toBigInt(x).equals(toBigInt(y));
}
public boolean lt(Number x, Number y){
@@ -845,20 +866,21 @@ final static class BigIntegerOps extends OpsP{
//public Number subtract(Number x, Number y);
final public Number negate(Number x){
- return reduceBigInteger(toBigInteger(x).negate());
+ return BigInt.fromBigInteger(toBigInteger(x).negate());
}
public Number inc(Number x){
BigInteger bx = toBigInteger(x);
- return reduceBigInteger(bx.add(BigInteger.ONE));
+ return BigInt.fromBigInteger(bx.add(BigInteger.ONE));
}
public Number dec(Number x){
BigInteger bx = toBigInteger(x);
- return reduceBigInteger(bx.subtract(BigInteger.ONE));
+ return BigInt.fromBigInteger(bx.subtract(BigInteger.ONE));
}
}
+
final static class BigDecimalOps extends OpsP{
final static Var MATH_CONTEXT = RT.MATH_CONTEXT;
@@ -878,7 +900,7 @@ final static class BigDecimalOps extends OpsP{
return this;
}
- final public Ops opsWith(BigIntegerOps x){
+ final public Ops opsWith(BigIntOps x){
return this;
}
@@ -978,8 +1000,8 @@ final static class LongBitOps implements BitOps{
return this;
}
- final public BitOps bitOpsWith(BigIntegerBitOps x){
- return BIGINTEGER_BITOPS;
+ final public BitOps bitOpsWith(BigIntBitOps x){
+ return BIGINT_BITOPS;
}
public Number not(Number x){
@@ -1006,21 +1028,21 @@ final static class LongBitOps implements BitOps{
if(n < 63)
return (num(x.longValue() & ~(1L << n)));
else
- return toBigInteger(x).clearBit(n);
+ return BigInt.fromBigInteger(toBigInteger(x).clearBit(n));
}
public Number setBit(Number x, int n){
if(n < 63)
return num(x.longValue() | (1L << n));
else
- return toBigInteger(x).setBit(n);
+ return BigInt.fromBigInteger(toBigInteger(x).setBit(n));
}
public Number flipBit(Number x, int n){
if(n < 63)
return num(x.longValue() ^ (1L << n));
else
- return toBigInteger(x).flipBit(n);
+ return BigInt.fromBigInteger(toBigInteger(x).flipBit(n));
}
public boolean testBit(Number x, int n){
@@ -1043,7 +1065,7 @@ final static class LongBitOps implements BitOps{
}
}
-final static class BigIntegerBitOps implements BitOps{
+final static class BigIntBitOps implements BitOps{
public BitOps combine(BitOps y){
return y.bitOpsWith(this);
}
@@ -1052,40 +1074,40 @@ final static class BigIntegerBitOps implements BitOps{
return this;
}
- final public BitOps bitOpsWith(BigIntegerBitOps x){
+ final public BitOps bitOpsWith(BigIntBitOps x){
return this;
}
public Number not(Number x){
- return toBigInteger(x).not();
+ return BigInt.fromBigInteger(toBigInteger(x).not());
}
public Number and(Number x, Number y){
- return toBigInteger(x).and(toBigInteger(y));
+ return BigInt.fromBigInteger(toBigInteger(x).and(toBigInteger(y)));
}
public Number or(Number x, Number y){
- return toBigInteger(x).or(toBigInteger(y));
+ return BigInt.fromBigInteger(toBigInteger(x).or(toBigInteger(y)));
}
public Number xor(Number x, Number y){
- return toBigInteger(x).xor(toBigInteger(y));
+ return BigInt.fromBigInteger(toBigInteger(x).xor(toBigInteger(y)));
}
public Number andNot(Number x, Number y){
- return toBigInteger(x).andNot(toBigInteger(y));
+ return BigInt.fromBigInteger(toBigInteger(x).andNot(toBigInteger(y)));
}
public Number clearBit(Number x, int n){
- return toBigInteger(x).clearBit(n);
+ return BigInt.fromBigInteger(toBigInteger(x).clearBit(n));
}
public Number setBit(Number x, int n){
- return toBigInteger(x).setBit(n);
+ return BigInt.fromBigInteger(toBigInteger(x).setBit(n));
}
public Number flipBit(Number x, int n){
- return toBigInteger(x).flipBit(n);
+ return BigInt.fromBigInteger(toBigInteger(x).flipBit(n));
}
public boolean testBit(Number x, int n){
@@ -1093,22 +1115,22 @@ final static class BigIntegerBitOps implements BitOps{
}
public Number shiftLeft(Number x, int n){
- return toBigInteger(x).shiftLeft(n);
+ return BigInt.fromBigInteger(toBigInteger(x).shiftLeft(n));
}
public Number shiftRight(Number x, int n){
- return toBigInteger(x).shiftRight(n);
+ return BigInt.fromBigInteger(toBigInteger(x).shiftRight(n));
}
}
static final LongOps LONG_OPS = new LongOps();
static final DoubleOps DOUBLE_OPS = new DoubleOps();
static final RatioOps RATIO_OPS = new RatioOps();
-static final BigIntegerOps BIGINTEGER_OPS = new BigIntegerOps();
+static final BigIntOps BIGINT_OPS = new BigIntOps();
static final BigDecimalOps BIGDECIMAL_OPS = new BigDecimalOps();
static final LongBitOps LONG_BITOPS = new LongBitOps();
-static final BigIntegerBitOps BIGINTEGER_BITOPS = new BigIntegerBitOps();
+static final BigIntBitOps BIGINT_BITOPS = new BigIntBitOps();
static public enum Category {INTEGER, FLOATING, DECIMAL, RATIO};
@@ -1123,8 +1145,10 @@ static Ops ops(Object x){
return LONG_OPS;
else if(xc == Float.class)
return DOUBLE_OPS;
+ else if(xc == BigInt.class)
+ return BIGINT_OPS;
else if(xc == BigInteger.class)
- return BIGINTEGER_OPS;
+ return BIGINT_OPS;
else if(xc == Ratio.class)
return RATIO_OPS;
else if(xc == BigDecimal.class)
@@ -1144,7 +1168,7 @@ static Category category(Object x){
return Category.INTEGER;
else if(xc == Float.class)
return Category.FLOATING;
- else if(xc == BigInteger.class)
+ else if(xc == BigInt.class)
return Category.INTEGER;
else if(xc == Ratio.class)
return Category.RATIO;
@@ -1161,39 +1185,16 @@ static BitOps bitOps(Object x){
return LONG_BITOPS;
else if(xc == Integer.class)
return LONG_BITOPS;
+ else if(xc == BigInt.class)
+ return BIGINT_BITOPS;
else if(xc == BigInteger.class)
- return BIGINTEGER_BITOPS;
+ return BIGINT_BITOPS;
else if(xc == Double.class || xc == Float.class || xc == BigDecimalOps.class || xc == Ratio.class)
throw new ArithmeticException("bit operation on non integer type: " + xc);
else
return LONG_BITOPS;
}
-//final static ExecutorService executor = Executors.newCachedThreadPool();
-//static public int minChunk = 100;
-//static int chunkSize(int alength){
-// return Math.max(alength / Runtime.getRuntime().availableProcessors(), minChunk);
-//}
-
-// }
-// else
-// {
-// LinkedList<Callable<Float>> ops = new LinkedList<Callable<Float>>();
-// for(int offset = 0;offset < xs.length;offset+=chunk)
-// {
-// final int start = offset;
-// final int end = Math.min(xs.length, start + chunk);
-// ops.add(new Callable<Float>(){
-// public Float call() throws Exception{
-// for(int i=start;i<end;i++)
-// xs[i] += ys[i];
-// return null;
-// }});
-// }
-// executor.invokeAll(ops);
-// }
-
-
static public float[] float_array(int size, Object init){
float[] ret = new float[size];
if(init instanceof Number)
@@ -1776,7 +1777,7 @@ static public long minus(long x){
static public Number minusP(long x){
if(x == Long.MIN_VALUE)
- return BigInteger.valueOf(x).negate();
+ return BigInt.fromBigInteger(BigInteger.valueOf(x).negate());
return num(-x);
}
@@ -1788,7 +1789,7 @@ static public long inc(long x){
static public Number incP(long x){
if(x == Long.MAX_VALUE)
- return BIGINTEGER_OPS.inc(x);
+ return BIGINT_OPS.inc(x);
return num(x + 1);
}
@@ -1800,7 +1801,7 @@ static public long dec(long x){
static public Number decP(long x){
if(x == Long.MIN_VALUE)
- return BIGINTEGER_OPS.dec(x);
+ return BIGINT_OPS.dec(x);
return num(x - 1);
}
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 0ba8a9e2..2ce9a70a 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -967,6 +967,14 @@ static public int intCast(double x){
static public long longCast(Object x){
if(x instanceof Integer || x instanceof Long)
return ((Number) x).longValue();
+ else if (x instanceof BigInt)
+ {
+ BigInt bi = (BigInt) x;
+ if(bi.bipart == null)
+ return bi.lpart;
+ else
+ throw new IllegalArgumentException("Value out of range for long: " + x);
+ }
else if (x instanceof BigInteger)
{
BigInteger bi = (BigInteger) x;
@@ -1416,10 +1424,14 @@ static public void print(Object x, Writer w) throws Exception{
w.write(x.toString());
w.write('M');
}
- else if(x instanceof BigInteger && readably) {
+ else if(x instanceof BigInt && readably) {
w.write(x.toString());
w.write('N');
}
+ else if(x instanceof BigInteger && readably) {
+ w.write(x.toString());
+ w.write("BIGINT");
+ }
else if(x instanceof Var) {
Var v = (Var) x;
w.write("#=(var " + v.ns.name + "/" + v.sym + ")");
diff --git a/src/jvm/clojure/lang/Util.java b/src/jvm/clojure/lang/Util.java
index 3e80172d..6f21d93e 100644
--- a/src/jvm/clojure/lang/Util.java
+++ b/src/jvm/clojure/lang/Util.java
@@ -128,6 +128,7 @@ static public boolean isPrimitive(Class c){
static public boolean isInteger(Object x){
return x instanceof Integer
|| x instanceof Long
+ || x instanceof BigInt
|| x instanceof BigInteger;
}
diff --git a/test/clojure/test_clojure/numbers.clj b/test/clojure/test_clojure/numbers.clj
index 52eb224c..9c6be05f 100644
--- a/test/clojure/test_clojure/numbers.clj
+++ b/test/clojure/test_clojure/numbers.clj
@@ -343,7 +343,7 @@
(defn- expt
"clojure.contrib.math/expt is a better and much faster impl, but this works.
Math/pow overflows to Infinity."
- [x n] (apply * (replicate n x)))
+ [x n] (apply *' (replicate n x)))
(deftest test-bit-shift-left
(are [x y] (= x y)
diff --git a/test/clojure/test_clojure/reader.clj b/test/clojure/test_clojure/reader.clj
index e3bee190..e1ef9253 100644
--- a/test/clojure/test_clojure/reader.clj
+++ b/test/clojure/test_clojure/reader.clj
@@ -17,7 +17,8 @@
;; Created 22 October 2008
(ns clojure.test-clojure.reader
- (:use clojure.test))
+ (:use clojure.test)
+ (:import clojure.lang.BigInt))
;; Symbols
@@ -81,10 +82,10 @@
sequence))))
; Read BigInteger
- (is (instance? BigInteger 9223372036854775808))
- (is (instance? BigInteger -9223372036854775809))
- (is (instance? BigInteger 10000000000000000000000000000000000000000000000000))
- (is (instance? BigInteger -10000000000000000000000000000000000000000000000000))
+ (is (instance? BigInt 9223372036854775808))
+ (is (instance? BigInt -9223372036854775809))
+ (is (instance? BigInt 10000000000000000000000000000000000000000000000000))
+ (is (instance? BigInt -10000000000000000000000000000000000000000000000000))
; Read Double
(is (instance? Double +1.0e+1))