comparison java/jdc/examples/UnixMathExample.java @ 22:4ee8d6aa7721

- java binding cleanup, exposed free functions (not very oo, this entire binding) - java binding examples
author cslag
date Sat, 09 Apr 2016 18:18:34 -0500
parents 40a2c4198016
children
comparison
equal deleted inserted replaced
21:40a2c4198016 22:4ee8d6aa7721
2 2
3 class UnixMathExample 3 class UnixMathExample
4 { 4 {
5 public static void main(String args[]) 5 public static void main(String args[])
6 { 6 {
7 long lib = DC.load("/usr/lib/libm.so"); 7 long lib = DC.loadLibrary("/usr/lib/libm.so");
8 System.out.format("libm.so handle: %x\n", lib); 8 System.out.format("libm.so handle: %x\n", lib);
9 9
10 long f0 = DC.find(lib, "sqrtf"); 10 long f0 = DC.find(lib, "sqrtf");
11 System.out.format("found sqrft at: %x\n", f0); 11 System.out.format("found sqrtf at: %x\n", f0);
12 12
13 long f1 = DC.find(lib, "pow"); 13 long f1 = DC.find(lib, "pow");
14 System.out.format("found pow at: %x\n", f1); 14 System.out.format("found pow at: %x\n", f1);
15 15
16 long vm = DC.newCallVM(4096); 16 long vm = DC.newCallVM(4096);
21 DC.reset(vm); 21 DC.reset(vm);
22 DC.argDouble(vm, 2.); 22 DC.argDouble(vm, 2.);
23 DC.argDouble(vm, 10.); 23 DC.argDouble(vm, 10.);
24 double r1 = DC.callDouble(vm, f1); 24 double r1 = DC.callDouble(vm, f1);
25 System.out.format("pow(2., 10.) = %f\n", r1); 25 System.out.format("pow(2., 10.) = %f\n", r1);
26
27 // Done, cleanup.
28 DC.freeCallVM(vm);
29 DC.freeLibrary(lib);
26 } 30 }
27 } 31 }
28 32