Changeset 8564


Ignore:
Timestamp:
02/14/05 04:02:12 (16 years ago)
Author:
piso
Message:

add(int)
multiplyBy(int)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/Bignum.java

    r8255 r8564  
    22 * Bignum.java
    33 *
    4  * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: Bignum.java,v 1.60 2004-12-16 17:26:37 piso Exp $
     4 * Copyright (C) 2003-2005 Peter Graves
     5 * $Id: Bignum.java,v 1.61 2005-02-14 04:02:12 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    214214    }
    215215
     216    public LispObject add(int n) throws ConditionThrowable
     217    {
     218        return number(value.add(BigInteger.valueOf(n)));
     219    }
     220
    216221    public LispObject add(LispObject obj) throws ConditionThrowable
    217222    {
     
    255260        }
    256261        return signal(new TypeError(obj, Symbol.NUMBER));
     262    }
     263
     264    public LispObject multiplyBy(int n) throws ConditionThrowable
     265    {
     266        if (n == 0)
     267            return Fixnum.ZERO;
     268        if (n == 1)
     269            return this;
     270        return new Bignum(value.multiply(BigInteger.valueOf(n)));
    257271    }
    258272
     
    392406        LispObject value1, value2;
    393407  try {
    394             if (obj instanceof Ratio) {
    395                 Ratio divisor = (Ratio) obj;
    396                 LispObject quotient =
    397                     multiplyBy(divisor.DENOMINATOR()).truncate(divisor.NUMERATOR());
    398                 LispObject remainder =
    399                     subtract(quotient.multiplyBy(divisor));
    400                 value1 = quotient;
    401                 value2 = remainder;
    402             } else if (obj instanceof Fixnum) {
     408            if (obj instanceof Fixnum) {
    403409                BigInteger divisor = ((Fixnum)obj).getBigInteger();
    404410                BigInteger[] results = value.divideAndRemainder(divisor);
Note: See TracChangeset for help on using the changeset viewer.