annotate java/jdc/examples/UnixMathExample.java @ 27:18e1f1bb1945

- 1.1 update
author Tassilo Philipp
date Sun, 12 Jan 2020 12:10:38 +0100
parents 4ee8d6aa7721
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
1 import org.dyncall.DC;
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
2
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
3 class UnixMathExample
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
4 {
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
5 public static void main(String args[])
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
6 {
22
4ee8d6aa7721 - java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents: 21
diff changeset
7 long lib = DC.loadLibrary("/usr/lib/libm.so");
21
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
8 System.out.format("libm.so handle: %x\n", lib);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
9
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
10 long f0 = DC.find(lib, "sqrtf");
22
4ee8d6aa7721 - java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents: 21
diff changeset
11 System.out.format("found sqrtf at: %x\n", f0);
21
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
12
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
13 long f1 = DC.find(lib, "pow");
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
14 System.out.format("found pow at: %x\n", f1);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
15
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
16 long vm = DC.newCallVM(4096);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
17 DC.argFloat(vm, 36.f);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
18 float r0 = DC.callFloat(vm, f0);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
19 System.out.format("sqrtf(36.f) = %f\n", r0);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
20
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
21 DC.reset(vm);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
22 DC.argDouble(vm, 2.);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
23 DC.argDouble(vm, 10.);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
24 double r1 = DC.callDouble(vm, f1);
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
25 System.out.format("pow(2., 10.) = %f\n", r1);
22
4ee8d6aa7721 - java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents: 21
diff changeset
26
4ee8d6aa7721 - java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents: 21
diff changeset
27 // Done, cleanup.
4ee8d6aa7721 - java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents: 21
diff changeset
28 DC.freeCallVM(vm);
4ee8d6aa7721 - java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents: 21
diff changeset
29 DC.freeLibrary(lib);
21
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
30 }
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
31 }
40a2c4198016 - working jdc (but with memleaks, currently)
cslag
parents:
diff changeset
32