Changeset 11282
- Timestamp:
- 08/13/08 16:22:30 (15 years ago)
- Location:
- trunk/j/src/org/armedbear/lisp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Complex.java
r11158 r11282 3 3 * 4 4 * Copyright (C) 2003-2006 Peter Graves 5 * $Id: Complex.java,v 1. 39 2007-02-23 21:17:33 pisoExp $5 * $Id: Complex.java,v 1.40 2008-08-13 16:22:30 ehuelsmann Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 275 275 276 276 private static Method hypotMethod = null; 277 static { try { 278 hypotMethod = 279 Class.forName("java.lang.Math") 280 .getMethod("hypot", new Class[] { Double.TYPE, Double.TYPE }); 281 } 282 catch (Throwable t) { Debug.trace(t); } 283 } 277 284 278 285 public LispObject ABS() throws ConditionThrowable … … 282 289 double real = DoubleFloat.coerceToFloat(realpart).value; 283 290 double imag = DoubleFloat.coerceToFloat(imagpart).value; 284 if (isJava15OrLater) 285 { 286 try 287 { 288 if (hypotMethod == null) 289 { 290 Class c = Class.forName("java.lang.Math"); 291 Class[] parameterTypes = new Class[2]; 292 parameterTypes[0] = parameterTypes[1] = Double.TYPE; 293 hypotMethod = c.getMethod("hypot", parameterTypes); 294 } 295 if (hypotMethod != null) 296 { 297 Object[] args; 298 args = new Object[2]; 299 args[0] = new Double(real); 300 args[1] = new Double(imag); 301 Double d = (Double) hypotMethod.invoke(null, args); 302 if (realpart instanceof DoubleFloat) 303 return new DoubleFloat(d.doubleValue()); 304 else 305 return new SingleFloat((float)d.doubleValue()); 306 } 307 } 308 catch (Throwable t) 309 { 310 Debug.trace(t); 311 // Fall through... 312 } 291 try 292 { 293 if (hypotMethod != null) 294 { 295 Object[] args; 296 args = new Object[2]; 297 args[0] = new Double(real); 298 args[1] = new Double(imag); 299 Double d = (Double) hypotMethod.invoke(null, args); 300 if (realpart instanceof DoubleFloat) 301 return new DoubleFloat(d.doubleValue()); 302 else 303 return new SingleFloat((float)d.doubleValue()); 304 } 305 } 306 catch (Throwable t) 307 { 308 Debug.trace(t); 309 // Fall through... 313 310 } 314 311 double result = Math.sqrt(real * real + imag * imag); -
trunk/j/src/org/armedbear/lisp/Lisp.java
r11278 r11282 3 3 * 4 4 * Copyright (C) 2002-2007 Peter Graves <peter@armedbear.org> 5 * $Id: Lisp.java,v 1.45 0 2008-08-12 21:59:07ehuelsmann Exp $5 * $Id: Lisp.java,v 1.451 2008-08-13 16:22:30 ehuelsmann Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 35 35 public abstract class Lisp 36 36 { 37 protected static final boolean isJava15OrLater;38 39 37 public static final boolean debug = true; 40 38 … … 2162 2160 { 2163 2161 final String version = System.getProperty("java.version"); 2164 if (version.startsWith("1.4")) 2165 { 2166 Symbol.FEATURES.setSymbolValue(new Cons(Keyword.JAVA_1_4, 2167 Symbol.FEATURES.getSymbolValue())); 2168 isJava15OrLater = false; 2169 } 2170 else if (version.startsWith("1.5")) 2162 if (version.startsWith("1.5")) 2171 2163 { 2172 2164 Symbol.FEATURES.setSymbolValue(new Cons(Keyword.JAVA_1_5, 2173 2165 Symbol.FEATURES.getSymbolValue())); 2174 isJava15OrLater = true;2175 2166 } 2176 2167 else if (version.startsWith("1.6")) … … 2178 2169 Symbol.FEATURES.setSymbolValue(new Cons(Keyword.JAVA_1_6, 2179 2170 Symbol.FEATURES.getSymbolValue())); 2180 isJava15OrLater = true;2181 2171 } 2182 2172 else if (version.startsWith("1.7")) … … 2184 2174 Symbol.FEATURES.setSymbolValue(new Cons(Keyword.JAVA_1_7, 2185 2175 Symbol.FEATURES.getSymbolValue())); 2186 isJava15OrLater = true; 2187 } 2188 else 2189 isJava15OrLater = false; 2176 } 2190 2177 } 2191 2178 static -
trunk/j/src/org/armedbear/lisp/MathFunctions.java
r11158 r11282 3 3 * 4 4 * Copyright (C) 2004-2006 Peter Graves 5 * $Id: MathFunctions.java,v 1.3 6 2007-02-23 21:17:34 pisoExp $5 * $Id: MathFunctions.java,v 1.37 2008-08-13 16:22:30 ehuelsmann Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 235 235 236 236 private static Method sinhMethod = null; 237 static { 238 try { 239 sinhMethod = Class.forName("java.lang.Math") 240 .getMethod("sinh", new Class[] { Double.TYPE }); 241 } 242 catch (Throwable t) { 243 Debug.trace(t); 244 } 245 } 237 246 238 247 private static LispObject sinh(LispObject arg) throws ConditionThrowable … … 244 253 im); 245 254 } 246 if (isJava15OrLater) { 247 if (arg instanceof SingleFloat) { 248 try { 249 if (sinhMethod == null) { 250 Class c = Class.forName("java.lang.Math"); 251 Class[] parameterTypes = new Class[1]; 252 parameterTypes[0] = Double.TYPE; 253 sinhMethod = c.getMethod("sinh", parameterTypes); 254 } 255 if (sinhMethod != null) { 256 Object[] args; 257 args = new Object[1]; 258 args[0] = new Double(((SingleFloat)arg).value); 259 Double d = (Double) sinhMethod.invoke(null, args); 260 return new SingleFloat((float)d.doubleValue()); 261 } 262 } 263 catch (Throwable t) { 264 Debug.trace(t); 265 // Fall through... 266 } 267 } else if (arg instanceof DoubleFloat) { 268 try { 269 if (sinhMethod == null) { 270 Class c = Class.forName("java.lang.Math"); 271 Class[] parameterTypes = new Class[1]; 272 parameterTypes[0] = Double.TYPE; 273 sinhMethod = c.getMethod("sinh", parameterTypes); 274 } 275 if (sinhMethod != null) { 276 Object[] args; 277 args = new Object[1]; 278 args[0] = new Double(((DoubleFloat)arg).value); 279 Double d = (Double) sinhMethod.invoke(null, args); 280 return new DoubleFloat(d.doubleValue()); 281 } 282 } 283 catch (Throwable t) { 284 Debug.trace(t); 285 // Fall through... 286 } 255 if (arg instanceof SingleFloat) { 256 try { 257 if (sinhMethod != null) { 258 Object[] args; 259 args = new Object[1]; 260 args[0] = new Double(((SingleFloat)arg).value); 261 Double d = (Double) sinhMethod.invoke(null, args); 262 return new SingleFloat((float)d.doubleValue()); 263 } 264 } 265 catch (Throwable t) { 266 Debug.trace(t); 267 // Fall through... 268 } 269 } else if (arg instanceof DoubleFloat) { 270 try { 271 if (sinhMethod != null) { 272 Object[] args; 273 args = new Object[1]; 274 args[0] = new Double(((DoubleFloat)arg).value); 275 Double d = (Double) sinhMethod.invoke(null, args); 276 return new DoubleFloat(d.doubleValue()); 277 } 278 } 279 catch (Throwable t) { 280 Debug.trace(t); 281 // Fall through... 287 282 } 288 283 } … … 310 305 311 306 private static Method coshMethod = null; 307 static { 308 try { 309 coshMethod = Class.forName("java.lang.Math") 310 .getMethod("cosh", new Class[] { Double.TYPE }); 311 } 312 catch (Throwable t) { 313 Debug.trace(t); 314 } 315 } 312 316 313 317 private static LispObject cosh(LispObject arg) throws ConditionThrowable … … 319 323 im); 320 324 } 321 if (isJava15OrLater) { 322 if (arg instanceof SingleFloat) { 323 try { 324 if (coshMethod == null) { 325 Class c = Class.forName("java.lang.Math"); 326 Class[] parameterTypes = new Class[1]; 327 parameterTypes[0] = Double.TYPE; 328 coshMethod = c.getMethod("cosh", parameterTypes); 329 } 330 if (coshMethod != null) { 331 Object[] args; 332 args = new Object[1]; 333 args[0] = new Double(((SingleFloat)arg).value); 334 Double d = (Double) coshMethod.invoke(null, args); 335 return new SingleFloat((float)d.doubleValue()); 336 } 337 } 338 catch (Throwable t) { 339 Debug.trace(t); 340 // Fall through... 341 } 342 } else if (arg instanceof DoubleFloat) { 343 try { 344 if (coshMethod == null) { 345 Class c = Class.forName("java.lang.Math"); 346 Class[] parameterTypes = new Class[1]; 347 parameterTypes[0] = Double.TYPE; 348 coshMethod = c.getMethod("cosh", parameterTypes); 349 } 350 if (coshMethod != null) { 351 Object[] args; 352 args = new Object[1]; 353 args[0] = new Double(((DoubleFloat)arg).value); 354 Double d = (Double) coshMethod.invoke(null, args); 355 return new DoubleFloat(d.doubleValue()); 356 } 357 } 358 catch (Throwable t) { 359 Debug.trace(t); 360 // Fall through... 361 } 325 if (arg instanceof SingleFloat) { 326 try { 327 if (coshMethod != null) { 328 Object[] args; 329 args = new Object[1]; 330 args[0] = new Double(((SingleFloat)arg).value); 331 Double d = (Double) coshMethod.invoke(null, args); 332 return new SingleFloat((float)d.doubleValue()); 333 } 334 } 335 catch (Throwable t) { 336 Debug.trace(t); 337 // Fall through... 338 } 339 } else if (arg instanceof DoubleFloat) { 340 try { 341 if (coshMethod != null) { 342 Object[] args; 343 args = new Object[1]; 344 args[0] = new Double(((DoubleFloat)arg).value); 345 Double d = (Double) coshMethod.invoke(null, args); 346 return new DoubleFloat(d.doubleValue()); 347 } 348 } 349 catch (Throwable t) { 350 Debug.trace(t); 351 // Fall through... 362 352 } 363 353 } … … 376 366 377 367 private static Method tanhMethod = null; 368 static { 369 try { 370 tanhMethod = Class.forName("java.lang.Math") 371 .getMethod("tanh", new Class[] { Double.TYPE }); 372 } 373 catch (Throwable t) { 374 Debug.trace(t); 375 } 376 } 378 377 379 378 // ### tanh … … 382 381 public LispObject execute(LispObject arg) throws ConditionThrowable 383 382 { 384 if (isJava15OrLater) { 385 if (arg instanceof SingleFloat) { 386 try { 387 if (tanhMethod == null) { 388 Class c = Class.forName("java.lang.Math"); 389 Class[] parameterTypes = new Class[1]; 390 parameterTypes[0] = Double.TYPE; 391 tanhMethod = c.getMethod("tanh", parameterTypes); 392 } 393 if (tanhMethod != null) { 394 Object[] args; 395 args = new Object[1]; 396 args[0] = new Double(((SingleFloat)arg).value); 397 Double d = (Double) tanhMethod.invoke(null, args); 398 return new SingleFloat((float)d.doubleValue()); 399 } 383 if (arg instanceof SingleFloat) { 384 try { 385 if (tanhMethod != null) { 386 Object[] args; 387 args = new Object[1]; 388 args[0] = new Double(((SingleFloat)arg).value); 389 Double d = (Double) tanhMethod.invoke(null, args); 390 return new SingleFloat((float)d.doubleValue()); 400 391 } 401 catch (Throwable t) { 402 Debug.trace(t); 403 // Fall through... 392 } 393 catch (Throwable t) { 394 Debug.trace(t); 395 // Fall through... 396 } 397 } else if (arg instanceof DoubleFloat) { 398 try { 399 if (tanhMethod != null) { 400 Object[] args; 401 args = new Object[1]; 402 args[0] = new Double(((DoubleFloat)arg).value); 403 Double d = (Double) tanhMethod.invoke(null, args); 404 return new DoubleFloat(d.doubleValue()); 404 405 } 405 } else if (arg instanceof DoubleFloat) { 406 try { 407 if (tanhMethod == null) { 408 Class c = Class.forName("java.lang.Math"); 409 Class[] parameterTypes = new Class[1]; 410 parameterTypes[0] = Double.TYPE; 411 tanhMethod = c.getMethod("tanh", parameterTypes); 412 } 413 if (tanhMethod != null) { 414 Object[] args; 415 args = new Object[1]; 416 args[0] = new Double(((DoubleFloat)arg).value); 417 Double d = (Double) tanhMethod.invoke(null, args); 418 return new DoubleFloat(d.doubleValue()); 419 } 420 } 421 catch (Throwable t) { 422 Debug.trace(t); 423 // Fall through... 424 } 406 } 407 catch (Throwable t) { 408 Debug.trace(t); 409 // Fall through... 425 410 } 426 411 } … … 615 600 616 601 private static Method log10Method = null; 602 static { 603 try { 604 log10Method = Class.forName("java.lang.Math") 605 .getMethod("log10", new Class[] { Double.TYPE }); 606 } 607 catch (Throwable t) { 608 Debug.trace(t); 609 } 610 } 617 611 618 612 // ### log … … 627 621 throws ConditionThrowable 628 622 { 629 if (isJava15OrLater) { 630 if (number.realp() && !number.minusp() && base.isEqualTo(new Fixnum(10))) { 631 double d = DoubleFloat.coerceToFloat(number).value; 632 try { 633 if (log10Method == null) { 634 Class c = Class.forName("java.lang.Math"); 635 Class[] parameterTypes = new Class[1]; 636 parameterTypes[0] = Double.TYPE; 637 log10Method = c.getMethod("log10", parameterTypes); 638 } 639 if (log10Method != null) { 640 Object[] args; 641 args = new Object[1]; 642 args[0] = new Double(d); 643 Double result = (Double) log10Method.invoke(null, args); 644 if (number instanceof DoubleFloat || base instanceof DoubleFloat) 645 return new DoubleFloat(result.doubleValue()); 646 else 647 return new SingleFloat((float)result.doubleValue()); 648 } 623 if (number.realp() && !number.minusp() && base.isEqualTo(new Fixnum(10))) { 624 double d = DoubleFloat.coerceToFloat(number).value; 625 try { 626 if (log10Method != null) { 627 Object[] args; 628 args = new Object[1]; 629 args[0] = new Double(d); 630 Double result = (Double) log10Method.invoke(null, args); 631 if (number instanceof DoubleFloat || base instanceof DoubleFloat) 632 return new DoubleFloat(result.doubleValue()); 633 else 634 return new SingleFloat((float)result.doubleValue()); 649 635 } 650 catch (Throwable t) {651 Debug.trace(t);652 // Fall through...653 }636 } 637 catch (Throwable t) { 638 Debug.trace(t); 639 // Fall through... 654 640 } 655 641 }
Note: See TracChangeset
for help on using the changeset viewer.