Changeset 5977
 Timestamp:
 02/25/04 23:52:28 (17 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/j/src/org/armedbear/lisp/ash.java
r5908 r5977 3 3 * 4 4 * Copyright (C) 20032004 Peter Graves 5 * $Id: ash.java,v 1. 5 20040223 19:56:58 piso Exp $5 * $Id: ash.java,v 1.6 20040225 23:52:28 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 22 22 package org.armedbear.lisp; 23 23 24 import java.math.BigInteger;25 26 24 // ### ash 27 25 // ash integer count => shiftedinteger … … 36 34 throws ConditionThrowable 37 35 { 38 if (first instanceof Fixnum && second instanceof Fixnum) { 39 int count = ((Fixnum)second).value; 40 if (count == 0) 41 return first; 42 long n = ((Fixnum)first).value; 43 if (n == 0) 44 return first; 45 if (count < 32) { 46 // Right shift. 47 return n >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE; 48 } 49 if (count <= 32) 50 return number(count > 0 ? (n << count) : (n >> count)); 51 } 52 BigInteger n; 53 if (first instanceof Fixnum) 54 n = BigInteger.valueOf(((Fixnum)first).value); 55 else if (first instanceof Bignum) 56 n = ((Bignum)first).getValue(); 57 else 58 return signal(new TypeError(first, "integer")); 59 if (second instanceof Fixnum) { 60 int count = ((Fixnum)second).value; 61 if (count == 0) 62 return first; 63 // BigInteger.shiftLeft() succumbs to a stack overflow if count 64 // is Integer.MIN_VALUE, so... 65 if (count == Integer.MIN_VALUE) 66 return n.signum() >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE; 67 return number(n.shiftLeft(count)); 68 } 69 if (second instanceof Bignum) { 70 BigInteger count = ((Bignum)second).getValue(); 71 if (count.signum() > 0) 72 return signal(new LispError("can't represent result of left shift")); 73 if (count.signum() < 0) 74 return n.signum() >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE; 75 Debug.bug(); // Shouldn't happen. 76 } 77 return signal(new TypeError(second, "integer")); 36 return first.ash(second); 78 37 } 79 38 80 private static final ashASH = new ash();39 private static final Primitive2 ASH = new ash(); 81 40 }
Note: See TracChangeset
for help on using the changeset viewer.