1 21 22 package org.armedbear.lisp; 23 24 public final class floor extends Primitive 26 { 27 private floor() 28 { 29 super("floor", "number &optional divisor"); 30 } 31 32 public LispObject execute(LispObject number) 33 throws ConditionThrowable 34 { 35 LispObject quotient = number.truncate(Fixnum.ONE); 36 final LispThread thread = LispThread.currentThread(); 37 LispObject remainder = thread._values[1]; 38 if (!remainder.zerop()) { 39 if (number.minusp()) { 40 quotient = quotient.decr(); 41 remainder = remainder.incr(); 42 thread._values[0] = quotient; 43 thread._values[1] = remainder; 44 } 45 } 46 return quotient; 47 } 48 49 public LispObject execute(LispObject number, LispObject divisor) 50 throws ConditionThrowable 51 { 52 LispObject quotient = number.truncate(divisor); 53 final LispThread thread = LispThread.currentThread(); 54 LispObject remainder = thread._values[1]; 55 boolean adjust = false; 56 if (!remainder.zerop()) { 57 if (divisor.minusp()) { 58 if (number.plusp()) 59 adjust = true; 60 } else { 61 if (number.minusp()) 62 adjust = true; 63 } 64 } 65 if (adjust) { 66 quotient = quotient.decr(); 67 remainder = remainder.add(divisor); 68 thread._values[0] = quotient; 69 thread._values[1] = remainder; 70 } 71 return quotient; 72 } 73 74 private static final Primitive FLOOR = new floor(); 75 } 76 | Popular Tags |