Changeset 11730


Ignore:
Timestamp:
04/04/09 22:16:53 (15 years ago)
Author:
ehuelsmann
Message:

No longer work around absense of Math.{sinh(),cosh(),tanh()};
their initial appearance is in 1.5, our minimum target.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/MathFunctions.java

    r11729 r11730  
    3434package org.armedbear.lisp;
    3535
    36 import java.lang.reflect.Method;
    37 
    3836public final class MathFunctions extends Lisp
    3937{
     
    260258    };
    261259
    262     private static Method sinhMethod = null;
    263     static {
    264         try {
    265             sinhMethod = Class.forName("java.lang.Math")
    266                     .getMethod("sinh", new Class[] { Double.TYPE });
    267         }
    268         catch (Throwable t) {
    269             Debug.trace(t);
    270         }
    271     }
    272 
    273260    private static LispObject sinh(LispObject arg) throws ConditionThrowable
    274261    {
     
    281268        if (arg instanceof SingleFloat) {
    282269            try {
    283                 if (sinhMethod != null) {
    284                     Object[] args;
    285                     args = new Object[1];
    286                     args[0] = new Double(((SingleFloat)arg).value);
    287                     Double d = (Double) sinhMethod.invoke(null, args);
    288                     return new SingleFloat((float)d.doubleValue());
    289                 }
     270                double d = Math.sinh(((SingleFloat)arg).value);
     271                return new SingleFloat((float)d);
    290272            }
    291273            catch (Throwable t) {
     
    295277        } else if (arg instanceof DoubleFloat) {
    296278            try {
    297                 if (sinhMethod != null) {
    298                     Object[] args;
    299                     args = new Object[1];
    300                     args[0] = new Double(((DoubleFloat)arg).value);
    301                     Double d = (Double) sinhMethod.invoke(null, args);
    302                     return new DoubleFloat(d.doubleValue());
    303                 }
     279                double d = Math.sinh(((DoubleFloat)arg).value);
     280                return new DoubleFloat(d);
    304281            }
    305282            catch (Throwable t) {
     
    331308    };
    332309
    333     private static Method coshMethod = null;
    334     static {
    335         try {
    336             coshMethod = Class.forName("java.lang.Math")
    337                     .getMethod("cosh", new Class[] { Double.TYPE });
    338         }
    339         catch (Throwable t) {
    340             Debug.trace(t);
    341         }
    342     }
    343 
    344310    private static LispObject cosh(LispObject arg) throws ConditionThrowable
    345311    {
     
    352318        if (arg instanceof SingleFloat) {
    353319            try {
    354                 if (coshMethod != null) {
    355                     Object[] args;
    356                     args = new Object[1];
    357                     args[0] = new Double(((SingleFloat)arg).value);
    358                     Double d = (Double) coshMethod.invoke(null, args);
    359                     return new SingleFloat((float)d.doubleValue());
    360                 }
     320                double d = Math.cosh(((SingleFloat)arg).value);
     321                return new SingleFloat((float)d);
    361322            }
    362323            catch (Throwable t) {
     
    366327        } else if (arg instanceof DoubleFloat) {
    367328            try {
    368                 if (coshMethod != null) {
    369                     Object[] args;
    370                     args = new Object[1];
    371                     args[0] = new Double(((DoubleFloat)arg).value);
    372                     Double d = (Double) coshMethod.invoke(null, args);
    373                     return new DoubleFloat(d.doubleValue());
    374                 }
     329                double d = Math.cosh(((DoubleFloat)arg).value);
     330                return new DoubleFloat(d);
    375331            }
    376332            catch (Throwable t) {
     
    392348    }
    393349
    394     private static Method tanhMethod = null;
    395     static {
    396         try {
    397             tanhMethod = Class.forName("java.lang.Math")
    398                     .getMethod("tanh", new Class[] { Double.TYPE });
    399         }
    400         catch (Throwable t) {
    401             Debug.trace(t);
    402         }
    403     }
    404 
    405350    // ### tanh
    406351    private static final Primitive TANH = new Primitive("tanh", "number")
     
    411356            if (arg instanceof SingleFloat) {
    412357                try {
    413                     if (tanhMethod != null) {
    414                         Object[] args;
    415                         args = new Object[1];
    416                         args[0] = new Double(((SingleFloat)arg).value);
    417                         Double d = (Double) tanhMethod.invoke(null, args);
    418                         return new SingleFloat((float)d.doubleValue());
    419                     }
     358                    double d = Math.tanh(((SingleFloat)arg).value);
     359                    return new SingleFloat((float)d);
    420360                }
    421361                catch (Throwable t) {
     
    425365            } else if (arg instanceof DoubleFloat) {
    426366                try {
    427                     if (tanhMethod != null) {
    428                         Object[] args;
    429                         args = new Object[1];
    430                         args[0] = new Double(((DoubleFloat)arg).value);
    431                         Double d = (Double) tanhMethod.invoke(null, args);
    432                         return new DoubleFloat(d.doubleValue());
    433                     }
     367                    double d = Math.tanh(((DoubleFloat)arg).value);
     368                    return new DoubleFloat(d);
    434369                }
    435370                catch (Throwable t) {
Note: See TracChangeset for help on using the changeset viewer.