예제 #1
0
 public static void test5() {
   MathFunc f = FX.x * FX.y * FX.z + 1;
   System.out.println(f);
   System.out.println(f.getVarNames());
   System.out.println(f.apply(2, 3, 4));
   CompiledFunc cf = f.compile();
   System.out.println(cf.apply(2, 3, 4));
 }
예제 #2
0
  public static void test1() {
    MathFunc x = FX.x;
    MathFunc y = FX.y;
    MathFunc xy = x.S(y);

    FuncClassLoader<CompiledFunc> fcl = new FuncClassLoader<CompiledFunc>();
    ClassGen genClass = BytecodeUtils.genClass(xy, null, "add", true, false);
    CompiledFunc fxy = fcl.newInstance(genClass);
    System.out.println(fxy.apply(1.0, 2.0));

    System.out.println(xy.compile(new String[] {"y", "x"}).apply(1.0, 2.0));
  }
예제 #3
0
  public static void test4() {
    FSin sin = new FSin("x");
    FCos cos = new FCos("y");
    MathFunc f = sin * cos;
    System.out.println(f);
    System.out.println(f.getVarNames());
    System.out.println(f.apply(Math.PI / 2, Math.PI / 4));

    CompiledFunc cf = f.compile();
    System.out.println(cf.apply(Math.PI / 2, Math.PI / 4));
    // bug in order of args
    System.out.println(f.compile(new String[] {"y", "x"}).apply(Math.PI / 2, Math.PI / 4));
  }
예제 #4
0
  public static void test2() {
    MathFunc x = FX.x;
    MathFunc y = FX.y;
    MathFunc xy = x.M(y);
    System.out.println(xy);
    HashMap<String, MathFunc> map = new HashMap<String, MathFunc>();
    map.put(x.getVarNames().get(0), FX.r.A(FX.s));
    map.put(y.getVarNames().get(0), FX.r.S(FX.s));
    MathFunc xy2 = xy.compose(map);
    System.out.println(xy2);

    System.out.println(FX.r.A(FX.s).M(FX.r.S(FX.s)));

    FuncClassLoader<CompiledFunc> fcl = new FuncClassLoader<CompiledFunc>();
    ClassGen genClass = BytecodeUtils.genClass(xy2, null, "add2", true, false);
    CompiledFunc fxy2 = fcl.newInstance(genClass);
    System.out.println(fxy2.apply(4.0, 2.0));
  }
예제 #5
0
 public static void test3() {
   FAx fax = new FAx(2.0);
   fax.setName("fax");
   CompiledFunc cfax = fax.compile();
   System.out.println(cfax.apply(0.1));
 }