Changeset 8757


Ignore:
Timestamp:
03/12/05 17:54:30 (17 years ago)
Author:
piso
Message:

truncate()

Location:
trunk/j/src/org/armedbear/lisp
Files:
3 edited

Legend:

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

    r8564 r8757  
    33 *
    44 * Copyright (C) 2003-2005 Peter Graves
    5  * $Id: Bignum.java,v 1.61 2005-02-14 04:02:12 piso Exp $
     5 * $Id: Bignum.java,v 1.62 2005-03-12 17:53:48 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    428428                value1 = quotient;
    429429                value2 = remainder;
     430            } else if (obj instanceof LispFloat) {
     431                // "When rationals and floats are combined by a numerical
     432                // function, the rational is first converted to a float of the
     433                // same format." 12.1.4.1
     434                return new LispFloat(floatValue()).truncate(obj);
    430435            } else
    431                 return signal(new LispError("Bignum.truncate(): not implemented: " + obj.typeOf()));
     436                return signal(new TypeError(obj, Symbol.REAL));
    432437        }
    433438        catch (ArithmeticException e) {
  • trunk/j/src/org/armedbear/lisp/Fixnum.java

    r8628 r8757  
    33 *
    44 * Copyright (C) 2002-2005 Peter Graves
    5  * $Id: Fixnum.java,v 1.110 2005-02-23 16:28:45 piso Exp $
     5 * $Id: Fixnum.java,v 1.111 2005-03-12 17:54:30 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    599599                value1 = quotient;
    600600                value2 = remainder;
     601            } else if (obj instanceof LispFloat) {
     602                // "When rationals and floats are combined by a numerical
     603                // function, the rational is first converted to a float of the
     604                // same format." 12.1.4.1
     605                return new LispFloat(value).truncate(obj);
    601606            } else
    602                 return signal(new LispError("Fixnum.truncate(): not implemented: " + obj.typeOf()));
     607                return signal(new TypeError(obj, Symbol.REAL));
    603608        }
    604609        catch (ArithmeticException e) {
  • trunk/j/src/org/armedbear/lisp/LispFloat.java

    r8756 r8757  
    33 *
    44 * Copyright (C) 2003-2005 Peter Graves
    5  * $Id: LispFloat.java,v 1.84 2005-03-12 17:08:23 piso Exp $
     5 * $Id: LispFloat.java,v 1.85 2005-03-12 17:53:30 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    372372    public LispObject truncate(LispObject obj) throws ConditionThrowable
    373373    {
    374         final LispThread thread = LispThread.currentThread();
     374        // "When rationals and floats are combined by a numerical function,
     375        // the rational is first converted to a float of the same format."
     376        // 12.1.4.1
    375377        if (obj instanceof Fixnum) {
    376             LispObject rational = rational();
    377             LispObject quotient = rational.truncate(obj);
    378             thread._values[1] = subtract(quotient); // Remainder.
    379             return quotient;
     378            return truncate(new LispFloat(((Fixnum)obj).value));
     379        }
     380        if (obj instanceof Bignum) {
     381            return truncate(new LispFloat(((Bignum)obj).floatValue()));
     382        }
     383        if (obj instanceof Ratio) {
     384            return truncate(new LispFloat(((Ratio)obj).floatValue()));
    380385        }
    381386        if (obj instanceof LispFloat) {
     387            final LispThread thread = LispThread.currentThread();
    382388            double divisor = ((LispFloat)obj).value;
    383389            double quotient = value / divisor;
     
    408414            return thread.setValues(result, remainder);
    409415        }
    410         if (obj instanceof Ratio) {
    411             // "When rationals and floats are combined by a numerical function,
    412             // the rational is first converted to a float of the same format."
    413             // 12.1.4.1
    414             return truncate(new LispFloat(((Ratio)obj).floatValue()));
    415         }
    416         return signal(new LispError("LispFloat.truncate(): not implemented: " +
    417                                     obj.typeOf().writeToString()));
     416        return signal(new TypeError(obj, Symbol.REAL));
    418417    }
    419418
Note: See TracChangeset for help on using the changeset viewer.