0
|
1 #//////////////////////////////////////////////////////////////////////
|
|
2 #
|
|
3 # unix_math.rb
|
1
|
4 # Copyright 2015 Tassilo Philipp
|
0
|
5 #
|
|
6 # Dyncall sample loading libm and calling functions
|
|
7 #
|
|
8 #///////////////////////////////////////////////////////////////////////
|
|
9
|
|
10 require 'rbdc'
|
|
11
|
|
12 l = Dyncall::ExtLib.new
|
|
13 if l.load('/usr/lib/libm.so') != nil and l.syms_init('/usr/lib/libm.so') != nil
|
|
14 puts 'Symbols in libm: '+l.syms_count.to_s
|
|
15 puts 'All symbol names in libm:'
|
|
16 l.syms_each { |s| puts s }
|
|
17
|
|
18 puts 'libm has sqrtf()? ' + l.exists?(:sqrtf) .to_s
|
|
19 puts 'libm has pow()? ' + l.exists?(:pow) .to_s
|
|
20 puts 'libm has not_in_libm()? ' + l.exists?(:not_in_libm).to_s
|
|
21
|
|
22 puts 'sqrtf(36.f) = ' + l.call(:sqrtf, 'f)f', 36.0) .to_s
|
|
23 puts 'pow(2.0, 10.0) = ' + l.call(:pow, 'dd)d', 2.0, 10.0).to_s
|
|
24 end
|
|
25
|