Skip to content

Commit 8fbafa9

Browse files
committed
incomplete work in progress
1 parent c5d0985 commit 8fbafa9

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

src/jvm/clojure/lang/Compiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5392,7 +5392,7 @@ public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
53925392
if(!(arg instanceof MaybePrimitiveExpr && arg.hasJavaClass() && arg.getJavaClass() == primc))
53935393
throw new IllegalArgumentException("recur arg for primitive local: " +
53945394
lb.name + " must be matching primitive, had: " +
5395-
arg.getJavaClass().getName() +
5395+
(arg.hasJavaClass() ? arg.getJavaClass().getName():"Object") +
53965396
", needed: " +
53975397
primc.getName());
53985398
}

src/jvm/clojure/lang/Numbers.java

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,37 +137,37 @@ static public Number quotient(Number x, Number y){
137137
Ops yops = ops(y);
138138
if(yops.isZero(y))
139139
throw new ArithmeticException("Divide by zero");
140-
return reduce(ops(x).combine(yops).quotient(x, y));
140+
return ops(x).combine(yops).quotient(x, y);
141141
}
142142

143143
static public Number remainder(Number x, Number y){
144144
Ops yops = ops(y);
145145
if(yops.isZero(y))
146146
throw new ArithmeticException("Divide by zero");
147-
return reduce(ops(x).combine(yops).remainder(x, y));
147+
return ops(x).combine(yops).remainder(x, y);
148148
}
149149

150150
static Number quotient(double n, double d){
151151
double q = n / d;
152-
if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE)
152+
if(q <= Long.MAX_VALUE && q >= Long.MIN_VALUE)
153153
{
154-
return (int) q;
154+
return (long) q;
155155
}
156156
else
157157
{ //bigint quotient
158-
return reduceBigInteger(new BigDecimal(q).toBigInteger());
158+
return new BigDecimal(q).toBigInteger();
159159
}
160160
}
161161

162162
static Number remainder(double n, double d){
163163
double q = n / d;
164-
if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE)
164+
if(q <= Long.MAX_VALUE && q >= Long.MIN_VALUE)
165165
{
166166
return (n - ((int) q) * d);
167167
}
168168
else
169169
{ //bigint quotient
170-
Number bq = reduceBigInteger(new BigDecimal(q).toBigInteger());
170+
Number bq = new BigDecimal(q).toBigInteger();
171171
return (n - bq.doubleValue() * d);
172172
}
173173
}
@@ -253,14 +253,6 @@ else if(x instanceof BigDecimal)
253253
return x;
254254
}
255255

256-
static public Number reduce(Number val){
257-
if(val instanceof Long)
258-
return reduce(val.longValue());
259-
else if (val instanceof BigInteger)
260-
return reduceBigInteger((BigInteger) val);
261-
return val;
262-
}
263-
264256
static public Number reduceBigInteger(BigInteger val){
265257
int bitLength = val.bitLength();
266258
if(bitLength < 32)
@@ -272,13 +264,6 @@ static public Number reduceBigInteger(BigInteger val){
272264
return val;
273265
}
274266

275-
static public Number reduce(long val){
276-
// if(val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE)
277-
// return (int) val;
278-
// else
279-
return val;
280-
}
281-
282267
static public Number divide(BigInteger n, BigInteger d){
283268
if(d.equals(BigInteger.ZERO))
284269
throw new ArithmeticException("Divide by zero");
@@ -288,9 +273,9 @@ static public Number divide(BigInteger n, BigInteger d){
288273
n = n.divide(gcd);
289274
d = d.divide(gcd);
290275
if(d.equals(BigInteger.ONE))
291-
return reduceBigInteger(n);
276+
return n;
292277
else if(d.equals(BigInteger.ONE.negate()))
293-
return reduceBigInteger(n.negate());
278+
return n.negate();
294279
return new Ratio((d.signum() < 0 ? n.negate() : n),
295280
(d.signum() < 0 ? d.negate() : d));
296281
}
@@ -348,6 +333,10 @@ static public int shiftLeft(int x, int n){
348333
return x << n;
349334
}
350335

336+
static public long shiftLeft(long x, int n){
337+
return x << n;
338+
}
339+
351340
static public Number shiftRight(Object x, Object n){
352341
return bitOps(x).shiftRight((Number)x, ((Number)n).intValue());
353342
}
@@ -609,7 +598,7 @@ public Number quotient(Number x, Number y){
609598
Ratio ry = toRatio(y);
610599
BigInteger q = rx.numerator.multiply(ry.denominator).divide(
611600
rx.denominator.multiply(ry.numerator));
612-
return reduceBigInteger(q);
601+
return q;
613602
}
614603

615604
public Number remainder(Number x, Number y){
@@ -690,11 +679,11 @@ public boolean isNeg(Number x){
690679
}
691680

692681
final public Number add(Number x, Number y){
693-
return reduceBigInteger(toBigInteger(x).add(toBigInteger(y)));
682+
return toBigInteger(x).add(toBigInteger(y));
694683
}
695684

696685
final public Number multiply(Number x, Number y){
697-
return reduceBigInteger(toBigInteger(x).multiply(toBigInteger(y)));
686+
return toBigInteger(x).multiply(toBigInteger(y));
698687
}
699688

700689
public Number divide(Number x, Number y){
@@ -724,12 +713,12 @@ final public Number negate(Number x){
724713

725714
public Number inc(Number x){
726715
BigInteger bx = toBigInteger(x);
727-
return reduceBigInteger(bx.add(BigInteger.ONE));
716+
return bx.add(BigInteger.ONE);
728717
}
729718

730719
public Number dec(Number x){
731720
BigInteger bx = toBigInteger(x);
732-
return reduceBigInteger(bx.subtract(BigInteger.ONE));
721+
return bx.subtract(BigInteger.ONE);
733722
}
734723
}
735724

@@ -907,7 +896,7 @@ public boolean testBit(Number x, int n){
907896
public Number shiftLeft(Number x, int n){
908897
if(n < 0)
909898
return shiftRight(x, -n);
910-
return reduceBigInteger(toBigInteger(x).shiftLeft(n));
899+
return Numbers.shiftLeft(x.longValue(),n);
911900
}
912901

913902
public Number shiftRight(Number x, int n){

0 commit comments

Comments
 (0)