Now I forgot to attach the files :)
On Sun, 6 Jan 2002, Boris Tschirschwitz wrote:
> Hi.
>
> I just implemented some opcodes for the 'GNU Scientific Library'.
> The opcodes are in the file 'gsl.ops', and tests are in 'gsl.t'
> These are very few and rather uninteresting ops, I was mostly checking if
> I know how to do it.
> I submit them already because:
>
> * I'd like to hear if you think that this is totally useless.
> * I'd like to know if something should be done completely diffently
> * I'll be away for a week, and I wanted to get something out, after
> bugging you so often.
>
> There are perldoc instructions in gls.ops.
>
> Boris.
>
>
>
/*
** GNU Scientific Library ops
*/
#include <gsl/gsl_math.h>
VERSION = PARROT_VERSION;
=head1 NAME
gsl.ops
=cut
=head1 DESCRIPTION
Parrot's library of GNU Scientific Library Opcodes
The opcode explanations are taken (with minor changes) from
'GNU Scentific Library: Reference Mamual'
To use these functions you'll have to configure parrot with the following two
additional libraries, to be added before -lm:
-lgsl -lgslcblas
These Libraries are build with GSL
GSL is availabe from the GSL homepage on www.gnu.org (it's a project on
savannha.gnu.org)
=cut
###############################################################################
=head2 GSL Basic ops
Reference:
GSL Reference Manual
=over 4
=cut
########################################
=item B<gsl_log1p>(n, n)
This function computes the value of log(1 + x) in a way that is accurate for small x.
It provides an alternative to the BSD math function log1p(x).
=cut
inline op gsl_log1p(n, n) {
$1 = (FLOATVAL)gsl_log1p((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_expm1>(n, n)
This function computes the value of exp(x)-1 in a way that is accurate for small x.
It provides an alternative to the BSD math function expm1(x).
=cut
inline op gsl_expm1(n, n) {
$1 = (FLOATVAL)gsl_expm1((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_hypot>(n, n, n)
This function computes the value of sqrt(x^2 + y^2) in a way that avoids overflow. It
provides an alternative to the BSD math function hypot(x,y).
=cut
inline op gsl_hypot(n, n, n) {
$1 = (FLOATVAL)gsl_hypot((double)$2,(double)$3);
goto NEXT();
}
# ########################################
=item B<gsl_acosh>(n, n)
This function computes the value of arccosh(x). It provides an alternative to the
standard math function acosh(x).
=cut
inline op gsl_acosh(n, n) {
$1 = (FLOATVAL)gsl_acosh((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_asinh>(n, n)
This function computes the value of arcsinh(x). It provides an alternative to the
standard math function acosh(x).
=cut
inline op gsl_asinh(n, n) {
$1 = (FLOATVAL)gsl_asinh((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_atanh>(n, n)
This function computes the value of arctanh(x). It provides an alternative to the
standard math function acosh(x).
=cut
inline op gsl_atanh(n, n) {
$1 = (FLOATVAL)gsl_atanh((double)$2);
goto NEXT();
}
=back
###############################################################################
=head2 GSL Small Integer Powers ops
Reference:
GSL Reference Manual
=over 4
=cut
# ########################################
=item B<gsl_pow_int>(n, n, i)
This routine computes the power x n for integer n. The power is computed using
the minimum number of multiplications. For example, x 8 is computed as ((x 2 ) 2 ) 2 ,
requiring only 3 multiplications. A version of this function which also computes the
numerical error in the result is available as gsl_sf_pow_int_e(Not implemented).
=cut
inline op gsl_pow_int(n, n, i) {
$1 = (FLOATVAL)gsl_pow_int((double)$2,(int)$3);
goto NEXT();
}
# ########################################
=item B<gsl_pow_2>(n, n)
gsl_pow_int(n, n, 2)
=cut
inline op gsl_pow_2(n, n) {
$1 = (FLOATVAL)gsl_pow_2((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_pow_3>(n, n)
gsl_pow_int(n, n, 3)
=cut
inline op gsl_pow_3(n, n) {
$1 = (FLOATVAL)gsl_pow_3((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_pow_4>(n, n)
gsl_pow_int(n, n, 4)
=cut
inline op gsl_pow_4(n, n) {
$1 = (FLOATVAL)gsl_pow_4((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_pow_5>(n, n)
gsl_pow_int(n,n, 5)
=cut
inline op gsl_pow_5(n, n) {
$1 = (FLOATVAL)gsl_pow_5((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_pow_6>(n, n)
gsl_pow_int(n, n, 6)
=cut
inline op gsl_pow_6(n, n) {
$1 = (FLOATVAL)gsl_pow_6((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_pow_7>(n, n)
gsl_pow_int(n, n, 7)
=cut
inline op gsl_pow_7(n, n) {
$1 = (FLOATVAL)gsl_pow_7((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_pow_8>(n, n)
gsl_pow_int(n, n, 8)
=cut
inline op gsl_pow_8(n, n) {
$1 = (FLOATVAL)gsl_pow_8((double)$2);
goto NEXT();
}
# ########################################
=item B<gsl_pow_9>(n, n)
gsl_pow_int(n, n, 9)
=cut
inline op gsl_pow_9(n, n) {
$1 = (FLOATVAL)gsl_pow_9((double)$2);
goto NEXT();
}
# ########################################
=back
=cut
###############################################################################
=head1 COPYRIGHT
Copyright (C) 2001-2002 Yet Another Society. All rights reserved.
=head1 LICENSE
This program is free software. It is subject to the same license
as the Parrot interpreter itself.
=cut
#! perl -w
use Parrot::Test tests => 15;
# GNU Scientific Library Opcodes
# The opcode explanations are taken directly (with minor changes) from
# "GNU Scentific Library: Reference Mamual"
# To use these functions you'll have to configure parrot with the following two
# additional libraries, to be added before -lm:
# -lgsl -lgslcblas
#
# These Libraries are build with GSL
# GSL is availabe from the GSL homepage on www.gnu.org (it's a project on
savannha.gnu.org)
# Elementary Functions
output_is(<<'CODE', '0.000000', "log(1+0)");
set N1,0
gsl_log1p N2,N1
print N2
end
CODE
output_is(<<'CODE', '0.000000', "exp(0)-1");
set N1,0
gsl_expm1 N2,N1
print N2
end
CODE
output_is(<<'CODE', "5.000000" ,"sqrt(3^2+4^2)");
set N1,3
set N2,4
gsl_hypot N3,N1,N2
print N3
end
CODE
output_is(<<'CODE', "0.000000","arccosh(1)");
set N1,1
gsl_acosh N2,N1
print N2
end
CODE
output_is(<<'CODE', "0.000000","arcsinh(0)");
set N1,0
gsl_asinh N2,N1
print N2
end
CODE
output_is(<<'CODE', "0.000000","arctanh(0)");
set N1,0
gsl_atanh N2,N1
print N2
end
CODE
# Small Integer Powers
output_is(<<'CODE', "1048576.000000","gsl_pow_int(2,20)");
set I1,20
set N1,2
gsl_pow_int N2,N1,I1
print N2
end
CODE
output_is(<<'CODE', "4.000000","gsl_pow_2(2)");
set N1,2
gsl_pow_2 N2,N1
print N2
end
CODE
output_is(<<'CODE', "8.000000","gsl_pow_3(2)");
set N1,2
gsl_pow_3 N2,N1
print N2
end
CODE
output_is(<<'CODE', "16.000000","gsl_pow_4(2)");
set N1,2
gsl_pow_4 N2,N1
print N2
end
CODE
output_is(<<'CODE', "32.000000","gsl_pow_5(2)");
set N1,2
gsl_pow_5 N2,N1
print N2
end
CODE
output_is(<<'CODE', "64.000000","gsl_pow_6(2)");
set N1,2
gsl_pow_6 N2,N1
print N2
end
CODE
output_is(<<'CODE', "128.000000","gsl_pow_7(2)");
set N1,2
gsl_pow_7 N2,N1
print N2
end
CODE
output_is(<<'CODE', "256.000000","gsl_pow_8(2)");
set N1,2
gsl_pow_8 N2,N1
print N2
end
CODE
output_is(<<'CODE', "512.000000","gsl_pow_9(2)");
set N1,2
gsl_pow_9 N2,N1
print N2
end
CODE
1; # HONK