01: package gnu.jemacs.lang;
02:
03: import gnu.math.*;
04: import gnu.mapping.*;
05:
06: public class DivideOp extends ProcedureN {
07: public DivideOp(String name) {
08: setName(name);
09: }
10:
11: public static final DivideOp $Sl = new DivideOp("/");
12:
13: public static Object $Sl(Object arg1) {
14: return $Sl(IntNum.one(), arg1);
15: }
16:
17: public static Object $Sl(Object arg1, Object arg2) {
18: Numeric num1 = ELisp.asNumber(arg1);
19: Numeric num2 = ELisp.asNumber(arg2);
20: if (num1 instanceof IntNum && num2 instanceof IntNum)
21: return IntNum.quotient((IntNum) num1, (IntNum) num2,
22: Numeric.TRUNCATE);
23: return num1.div(num2);
24: }
25:
26: public static Object $Sl$V(Object arg1, Object arg2, Object arg3,
27: Object[] rest) {
28: return applyN($Sl($Sl(arg1, arg2), arg3), rest);
29: }
30:
31: public static Object applyN(Object init, Object[] args) {
32: int len = args.length;
33: Object result = init;
34: for (int i = 0; i < len; i++)
35: result = $Sl(result, args[i]);
36: return result;
37: }
38:
39: public Object applyN(Object[] args) {
40: int len = args.length;
41: if (len <= 1)
42: return $Sl(args[0]);
43: Object result = args[0];
44: for (int i = 1; i < len; i++)
45: result = $Sl(result, args[i]);
46: return result;
47: }
48: }
|