home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / fp1os2.arj / OS2 / DATA / 49 / C / 0 / F_26836 / JScriptMathObject.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-15  |  3.8 KB  |  137 lines

  1. public class JScriptMathObject extends JSbxObject implements JSbxPropertyInterface {
  2.    private static final int MATH_ID_ABS = 1;
  3.    private static final int MATH_ID_ACOS = 2;
  4.    private static final int MATH_ID_ASIN = 3;
  5.    private static final int MATH_ID_ATAN = 4;
  6.    private static final int MATH_ID_CEIL = 5;
  7.    private static final int MATH_ID_COS = 6;
  8.    private static final int MATH_ID_EXP = 7;
  9.    private static final int MATH_ID_FLOOR = 8;
  10.    private static final int MATH_ID_LOG = 9;
  11.    private static final int MATH_ID_MAX = 10;
  12.    private static final int MATH_ID_MIN = 11;
  13.    private static final int MATH_ID_POW = 12;
  14.    private static final int MATH_ID_RANDOM = 13;
  15.    private static final int MATH_ID_ROUND = 14;
  16.    private static final int MATH_ID_SIN = 15;
  17.    private static final int MATH_ID_SQRT = 16;
  18.    private static final int MATH_ID_TAN = 17;
  19.    private static final int MATH_ID_ATAN2 = 18;
  20.  
  21.    public JScriptMathObject() {
  22.       try {
  23.          ((JSbxObject)this).Put(new JSbxValueProperty("E", this, new JSbxValue(Math.E), true, true));
  24.          ((JSbxObject)this).Put(new JSbxValueProperty("LN2", this, new JSbxValue(0.6931471805599453), true, true));
  25.          ((JSbxObject)this).Put(new JSbxValueProperty("LN10", this, new JSbxValue(2.302585092994046), true, true));
  26.          ((JSbxObject)this).Put(new JSbxValueProperty("LOG2E", this, new JSbxValue(1.4426950408889634), true, true));
  27.          ((JSbxObject)this).Put(new JSbxValueProperty("LOG10E", this, new JSbxValue(0.4342944819032518), true, true));
  28.          ((JSbxObject)this).Put(new JSbxValueProperty("PI", this, new JSbxValue(Math.PI), true, true));
  29.          ((JSbxObject)this).Put(new JSbxValueProperty("SQRT1_2", this, new JSbxValue(0.7071067811865476), true, true));
  30.          ((JSbxObject)this).Put(new JSbxValueProperty("SQRT2", this, new JSbxValue(1.4142135623730951), true, true));
  31.          ((JSbxObject)this).Put(new JSbxObjectProperty("abs", this, this, 1, false, true));
  32.          ((JSbxObject)this).Put(new JSbxObjectProperty("acos", this, this, 2, false, true));
  33.          ((JSbxObject)this).Put(new JSbxObjectProperty("asin", this, this, 3, false, true));
  34.          ((JSbxObject)this).Put(new JSbxObjectProperty("atan", this, this, 4, false, true));
  35.          ((JSbxObject)this).Put(new JSbxObjectProperty("ceil", this, this, 5, false, true));
  36.          ((JSbxObject)this).Put(new JSbxObjectProperty("cos", this, this, 6, false, true));
  37.          ((JSbxObject)this).Put(new JSbxObjectProperty("exp", this, this, 7, false, true));
  38.          ((JSbxObject)this).Put(new JSbxObjectProperty("floor", this, this, 8, false, true));
  39.          ((JSbxObject)this).Put(new JSbxObjectProperty("log", this, this, 9, false, true));
  40.          ((JSbxObject)this).Put(new JSbxObjectProperty("max", this, this, 10, false, true));
  41.          ((JSbxObject)this).Put(new JSbxObjectProperty("min", this, this, 11, false, true));
  42.          ((JSbxObject)this).Put(new JSbxObjectProperty("pow", this, this, 12, false, true));
  43.          ((JSbxObject)this).Put(new JSbxObjectProperty("random", this, this, 13, false, true));
  44.          ((JSbxObject)this).Put(new JSbxObjectProperty("round", this, this, 14, false, true));
  45.          ((JSbxObject)this).Put(new JSbxObjectProperty("sin", this, this, 15, false, true));
  46.          ((JSbxObject)this).Put(new JSbxObjectProperty("sqrt", this, this, 16, false, true));
  47.          ((JSbxObject)this).Put(new JSbxObjectProperty("tan", this, this, 17, false, true));
  48.          ((JSbxObject)this).Put(new JSbxObjectProperty("atan2", this, this, 18, false, true));
  49.       } catch (JSbxException var1) {
  50.       }
  51.    }
  52.  
  53.    public JSbxValue PropertyCallFunction(JSbxObjectProperty var1, JScriptCallParam var2) throws JSbxExceptionBase {
  54.       JSbxVector var3 = var2.GetParamVector();
  55.       int var4 = var1.GetID();
  56.       double var5 = (double)0.0F;
  57.       double var7 = (double)0.0F;
  58.       if (var4 != 13) {
  59.          var7 = JScriptWindowObject.GetDoubleParam(var3, 0);
  60.       }
  61.  
  62.       switch (var4) {
  63.          case 1:
  64.             var5 = Math.abs(var7);
  65.             break;
  66.          case 2:
  67.             var5 = Math.acos(var7);
  68.             break;
  69.          case 3:
  70.             var5 = Math.asin(var7);
  71.             break;
  72.          case 4:
  73.             var5 = Math.atan(var7);
  74.             break;
  75.          case 5:
  76.             var5 = Math.ceil(var7);
  77.             break;
  78.          case 6:
  79.             var5 = Math.cos(var7);
  80.             break;
  81.          case 7:
  82.             var5 = Math.exp(var7);
  83.             break;
  84.          case 8:
  85.             var5 = Math.floor(var7);
  86.             break;
  87.          case 9:
  88.             var5 = Math.log(var7);
  89.             break;
  90.          case 10:
  91.             var5 = Math.max(var7, JScriptWindowObject.GetDoubleParam(var3, 1));
  92.             break;
  93.          case 11:
  94.             var5 = Math.min(var7, JScriptWindowObject.GetDoubleParam(var3, 1));
  95.             break;
  96.          case 12:
  97.             var5 = Math.pow(var7, JScriptWindowObject.GetDoubleParam(var3, 1));
  98.             break;
  99.          case 13:
  100.             var5 = Math.random();
  101.             break;
  102.          case 14:
  103.             var5 = (double)Math.round(var7);
  104.             break;
  105.          case 15:
  106.             var5 = Math.sin(var7);
  107.             break;
  108.          case 16:
  109.             var5 = Math.sqrt(var7);
  110.             break;
  111.          case 17:
  112.             var5 = Math.tan(var7);
  113.             break;
  114.          case 18:
  115.             var5 = Math.atan2(var7, JScriptWindowObject.GetDoubleParam(var3, 1));
  116.       }
  117.  
  118.       JSbxValue var9 = new JSbxValue(var5);
  119.       var2.GetRuntimeParam().SetReturnValue(var9);
  120.       return var9;
  121.    }
  122.  
  123.    public void PropertyGet(JSbxObjectProperty var1, JSbxValue var2) throws JSbxException {
  124.    }
  125.  
  126.    public void PropertyPut(JSbxObjectProperty var1, JSbxValue var2) throws JSbxException {
  127.    }
  128.  
  129.    public String Property_GetJScript_typeofString(JSbxObjectProperty var1) {
  130.       return "function";
  131.    }
  132.  
  133.    public String GetJScriptString(boolean var1) {
  134.       return "function Math() { [native code] }";
  135.    }
  136. }
  137.