1 21 22 package org.armedbear.lisp; 23 24 import java.math.BigInteger ; 25 26 public final class logand extends Primitive 29 { 30 private logand() 31 { 32 super("logand", "&rest integers"); 33 } 34 35 public LispObject execute() 36 { 37 return Fixnum.MINUS_ONE; 38 } 39 40 public LispObject execute(LispObject first, LispObject second) 41 throws ConditionThrowable 42 { 43 if (first instanceof Fixnum && second instanceof Fixnum) { 44 return new Fixnum(((Fixnum)first).value & 45 ((Fixnum)second).value); 46 } else { 47 BigInteger n1, n2; 48 if (first instanceof Fixnum) 49 n1 = ((Fixnum)first).getBigInteger(); 50 else if (first instanceof Bignum) 51 n1 = ((Bignum)first).value; 52 else 53 return signal(new TypeError(first, Symbol.INTEGER)); 54 if (second instanceof Fixnum) 55 n2 = ((Fixnum)second).getBigInteger(); 56 else if (second instanceof Bignum) 57 n2 = ((Bignum)second).value; 58 else 59 return signal(new TypeError(second, Symbol.INTEGER)); 60 return number(n1.and(n2)); 61 } 62 } 63 64 public LispObject execute(LispObject[] args) throws ConditionThrowable 65 { 66 BigInteger result = BigInteger.valueOf(-1); 67 for (int i = 0; i < args.length; i++) { 68 BigInteger n; 69 if (args[i] instanceof Fixnum) 70 n = ((Fixnum)args[i]).getBigInteger(); 71 else if (args[i] instanceof Bignum) 72 n = ((Bignum)args[i]).value; 73 else 74 return signal(new TypeError(args[i], Symbol.INTEGER)); 75 result = result.and(n); 76 } 77 return number(result); 78 } 79 80 private static final Primitive LOGAND = new logand(); 81 } 82 | Popular Tags |