3
# Example of how to use callext() - also see callext.c
7
BEGIN { plan tests => 1 }
11
use PDL::Core ':Internal'; # For topdl()
16
kill 'INT',$$ if $ENV{UNDER_DEBUGGER}; # Useful for debugging.
25
# Create the filenames
26
my $cfile = File::Spec->catfile('t', 'callext.c');
27
my $inc = File::Spec->catdir('Basic', 'Core');
28
my $out = File::Spec->catfile('t', 'callext.'.$Config{dlext});
32
callext_cc($cfile, "-I$inc", '', $out);
34
my $y = sequence(5,4)+2; # Create PDL
35
my $x = $y*20+100; # Another
37
my $try = loglog($x,$y);
38
my $correct = log(float($x))/log(float($y));
41
print "Correct = $correct\n";
42
ok( tapprox($try, $correct) );
44
# Return log $x to base $y using callext() routine -
45
# perl wrapper makes this nice and easy to use.
49
die 'Usage: loglog($x,$y)' if scalar(@_)!=2;
53
# (i) topdl() forces arguments to be pdl vars even
54
# if ordinary numbers are passed
56
# (ii) float() forces the pdl vars to be float precision
57
# thus matching the C routine.
59
my $x = float(topdl(shift));
60
my $y = float(topdl(shift));
62
my $ret = $x->copy; # Make copy of $x to return
68
callext($out, "loglog_ext", $ret, $y);