Changeset 12922 for trunk/abcl/src/org
 Timestamp:
 09/25/10 10:10:22 (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/abcl/src/org/armedbear/lisp/MathFunctions.java
r12513 r12922 38 38 public final class MathFunctions 39 39 { 40 41 // Implementation of section 12.1.5.3, which says: 42 // "If the result of any computation would be a complex number whose 43 // real part is of type rational and whose imaginary part is zero, 44 // the result is converted to the rational which is the real part." 45 private static final LispObject complexToRealFixup(LispObject result, 46 LispObject arg) 47 { 48 if (result instanceof Complex 49 && ! (arg instanceof Complex)) { 50 Complex c = (Complex)result; 51 LispObject im = c.getImaginaryPart(); 52 if (im.zerop()) 53 return c.getRealPart(); 54 } 55 return result; 56 } 57 40 58 // ### sin 41 59 private static final Primitive SIN = new Primitive("sin", "radians") … … 136 154 result = result.multiplyBy(Complex.getInstance(Fixnum.ZERO, 137 155 Fixnum.MINUS_ONE)); 138 if (result instanceof Complex) { 139 if (arg instanceof Complex) 140 return result; 141 LispObject im = ((Complex)result).getImaginaryPart(); 142 if (im.zerop()) 143 return ((Complex)result).getRealPart(); 144 } 145 return result; 156 157 return complexToRealFixup(result, arg); 146 158 } 147 159 … … 178 190 } 179 191 result = result.subtract(asin(arg)); 180 if (result instanceof Complex) { 181 if (arg instanceof Complex) 182 return result; 183 LispObject im = ((Complex)result).getImaginaryPart(); 184 if (im.zerop()) 185 return ((Complex)result).getRealPart(); 186 } 187 return result; 192 193 return complexToRealFixup(result, arg); 188 194 } 189 195 … … 278 284 result = result.subtract(exp(arg.multiplyBy(Fixnum.MINUS_ONE))); 279 285 result = result.divideBy(Fixnum.TWO); 280 if (result instanceof Complex) { 281 if (arg instanceof Complex) 282 return result; 283 LispObject im = ((Complex)result).getImaginaryPart(); 284 if (im.zerop()) 285 return ((Complex)result).getRealPart(); 286 } 287 return result; 286 287 return complexToRealFixup(result, arg); 288 288 } 289 289 … … 316 316 result = result.add(exp(arg.multiplyBy(Fixnum.MINUS_ONE))); 317 317 result = result.divideBy(Fixnum.TWO); 318 if (result instanceof Complex) { 319 if (arg instanceof Complex) 320 return result; 321 LispObject im = ((Complex)result).getImaginaryPart(); 322 if (im.zerop()) 323 return ((Complex)result).getRealPart(); 324 } 325 return result; 318 319 return complexToRealFixup(result, arg); 326 320 } 327 321 … … 366 360 result = result.add(arg); 367 361 result = log(result); 368 if (result instanceof Complex) { 369 if (arg instanceof Complex) 370 return result; 371 LispObject im = ((Complex)result).getImaginaryPart(); 372 if (im.zerop()) 373 return ((Complex)result).getRealPart(); 374 } 375 return result; 362 363 return complexToRealFixup(result, arg); 376 364 } 377 365 … … 403 391 result = log(result); 404 392 result = result.multiplyBy(Fixnum.TWO); 405 if (result instanceof Complex) { 406 if (arg instanceof Complex) 407 return result; 408 LispObject im = ((Complex)result).getImaginaryPart(); 409 if (im.zerop()) 410 return ((Complex)result).getRealPart(); 411 } 412 return result; 393 394 return complexToRealFixup(result, arg); 413 395 } 414 396 … … 435 417 LispObject result = n1.subtract(n2); 436 418 result = result.divideBy(Fixnum.TWO); 437 if (result instanceof Complex) { 438 if (arg instanceof Complex) 439 return result; 440 LispObject im = ((Complex)result).getImaginaryPart(); 441 if (im.zerop()) 442 return ((Complex)result).getRealPart(); 443 } 444 return result; 419 420 return complexToRealFixup(result, arg); 445 421 } 446 422
Note: See TracChangeset
for help on using the changeset viewer.