Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/banzaiman/jni-gamma
A simple JNI example to get gamma function values
https://github.com/banzaiman/jni-gamma
Last synced: 9 days ago
JSON representation
A simple JNI example to get gamma function values
- Host: GitHub
- URL: https://github.com/banzaiman/jni-gamma
- Owner: BanzaiMan
- Created: 2011-11-10T14:51:20.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2011-11-13T01:15:22.000Z (about 13 years ago)
- Last Synced: 2024-11-08T09:51:22.513Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.txt
Awesome Lists containing this project
README
This is a simple example of the use of JNI. This shows how Java can call
the native function tgamma() to get the Gamma function value.To use:
1. Generate Example.h:
javah Example.java
2. Generate shared object from gamma.c. For example (on a Mac):
cc -shared gamma.c -o libgamma.dylib \
-I /Library/Java/JavaVirtualMachines/1.6.0_29-b11-397.jdk/Contents/Headers/
3. Compile Example.java:
javac Example.java
4. Execute!
java ExampleNote: if you want to be sure that tgamma() is returning a reasonable
value, try tgamma(5.0) = 4! = 24, tgamma(0.5)**2 = Math.Pi()For comparison, we do the same with (J)Ruby, using FFI. For MRI, you
would need to require 'rubygems' as well.Note: In Ruby 1.9, the gamma function is available as 'Math::gamma'.
bench_gamma.rb compares the performance of 3 methods. Be sure to run it
in the 1.9 mode.