Changeset 3587
- Timestamp:
- 09/06/03 14:09:11 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Ratio.java
r3585 r3587 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: Ratio.java,v 1.2 6 2003-09-05 14:30:55piso Exp $5 * $Id: Ratio.java,v 1.27 2003-09-06 14:09:11 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 231 231 public LispObject divideBy(LispObject obj) throws LispError 232 232 { 233 try { 234 if (obj instanceof Fixnum) { 235 BigInteger n = ((Fixnum)obj).getBigInteger(); 236 return number(numerator, denominator.multiply(n)); 237 } 238 if (obj instanceof Bignum) { 239 BigInteger n = ((Bignum)obj).getValue(); 240 return number(numerator, denominator.multiply(n)); 241 } 242 if (obj instanceof Ratio) { 243 BigInteger n = ((Ratio)obj).numerator; 244 BigInteger d = ((Ratio)obj).denominator; 245 return number(numerator.multiply(d), denominator.multiply(n)); 246 } 247 if (obj instanceof LispFloat) { 248 return new LispFloat(floatValue() / ((LispFloat)obj).getValue()); 249 } 250 throw new TypeError(obj, "number"); 251 } 252 catch (ArithmeticException e) { 233 if (obj instanceof Fixnum) { 234 BigInteger n = ((Fixnum)obj).getBigInteger(); 235 return number(numerator, denominator.multiply(n)); 236 } 237 if (obj instanceof Bignum) { 238 BigInteger n = ((Bignum)obj).getValue(); 239 return number(numerator, denominator.multiply(n)); 240 } 241 if (obj instanceof Ratio) { 242 BigInteger n = ((Ratio)obj).numerator; 243 BigInteger d = ((Ratio)obj).denominator; 244 return number(numerator.multiply(d), denominator.multiply(n)); 245 } 246 if (obj instanceof LispFloat) { 253 247 if (obj.zerop()) 254 248 throw new DivisionByZero(); 255 throw new ArithmeticError(e.getMessage()); 256 } 249 return new LispFloat(floatValue() / ((LispFloat)obj).getValue()); 250 } 251 throw new TypeError(obj, "number"); 257 252 } 258 253
Note: See TracChangeset
for help on using the changeset viewer.