Math-Libm-1.00/ 40755 1751 1751 0 7125332223 12207 5ustar lewartlewartMath-Libm-1.00/README100644 1751 1751 765 7125310730 13153 0ustar lewartlewartMath::Libm - Perl extension for the C math library, libm This module is a translation of the C math.h file. It exports the following constants and functions: M_1_PI M_2_PI M_2_SQRTPI M_E M_LN10 M_LN2 M_LOG10E M_LOG2E M_PI M_PI_2 M_PI_4 M_SQRT1_2 M_SQRT2 acos acosh asin asinh atan atanh cbrt ceil cosh erf erfc expm1 floor hypot j0 j1 jn lgamma_r log10 log1p pow rint sinh tan tanh y0 y1 yn Only tested on AIX 4.2, FreeBSD 4.0, Linux 2.2.16, and Solaris 2.5.1. Daniel Lewart d-lewart@uiuc.edu Math-Libm-1.00/Makefile.PL100644 1751 1751 661 7125310720 14237 0ustar lewartlewartuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Math::Libm', 'VERSION_FROM' => 'Libm.pm', # finds $VERSION 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 'LIBS' => ['-lm'], # e.g., '-lm' 'DEFINE' => '-D_REENTRANT', # e.g., '-DHAVE_SOMETHING' 'INC' => '', # e.g., '-I/usr/include/other' ); Math-Libm-1.00/Libm.xs100644 1751 1751 13224 7125310720 13563 0ustar lewartlewart#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include static int not_here(char *s) { croak("%s not implemented on this architecture", s); return -1; } static double constant_M_PI_(char *name, int len, int arg) { switch (name[5 + 0]) { case '2': if (strEQ(name + 5, "2")) { /* M_PI_ removed */ #ifdef M_PI_2 return M_PI_2; #else goto not_there; #endif } case '4': if (strEQ(name + 5, "4")) { /* M_PI_ removed */ #ifdef M_PI_4 return M_PI_4; #else goto not_there; #endif } } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } static double constant_M_P(char *name, int len, int arg) { if (3 + 1 > len ) { errno = EINVAL; return 0; } switch (name[3 + 1]) { case '\0': if (strEQ(name + 3, "I")) { /* M_P removed */ #ifdef M_PI return M_PI; #else goto not_there; #endif } case '_': if (!strnEQ(name + 3,"I", 1)) break; return constant_M_PI_(name, len, arg); } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } static double constant_M_2(char *name, int len, int arg) { if (3 + 1 >= len ) { errno = EINVAL; return 0; } switch (name[3 + 1]) { case 'P': if (strEQ(name + 3, "_PI")) { /* M_2 removed */ #ifdef M_2_PI return M_2_PI; #else goto not_there; #endif } case 'S': if (strEQ(name + 3, "_SQRTPI")) { /* M_2 removed */ #ifdef M_2_SQRTPI return M_2_SQRTPI; #else goto not_there; #endif } } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } static double constant_M_S(char *name, int len, int arg) { if (3 + 3 >= len ) { errno = EINVAL; return 0; } switch (name[3 + 3]) { case '1': if (strEQ(name + 3, "QRT1_2")) { /* M_S removed */ #ifdef M_SQRT1_2 return M_SQRT1_2; #else goto not_there; #endif } case '2': if (strEQ(name + 3, "QRT2")) { /* M_S removed */ #ifdef M_SQRT2 return M_SQRT2; #else goto not_there; #endif } } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } static double constant_M_LN(char *name, int len, int arg) { switch (name[4 + 0]) { case '1': if (strEQ(name + 4, "10")) { /* M_LN removed */ #ifdef M_LN10 return M_LN10; #else goto not_there; #endif } case '2': if (strEQ(name + 4, "2")) { /* M_LN removed */ #ifdef M_LN2 return M_LN2; #else goto not_there; #endif } } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } static double constant_M_LO(char *name, int len, int arg) { if (4 + 1 >= len ) { errno = EINVAL; return 0; } switch (name[4 + 1]) { case '1': if (strEQ(name + 4, "G10E")) { /* M_LO removed */ #ifdef M_LOG10E return M_LOG10E; #else goto not_there; #endif } case '2': if (strEQ(name + 4, "G2E")) { /* M_LO removed */ #ifdef M_LOG2E return M_LOG2E; #else goto not_there; #endif } } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } static double constant_M_L(char *name, int len, int arg) { switch (name[3 + 0]) { case 'N': return constant_M_LN(name, len, arg); case 'O': return constant_M_LO(name, len, arg); } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } static double constant(char *name, int len, int arg) { errno = 0; if (0 + 2 >= len ) { errno = EINVAL; return 0; } switch (name[0 + 2]) { case '1': if (strEQ(name + 0, "M_1_PI")) { /* removed */ #ifdef M_1_PI return M_1_PI; #else goto not_there; #endif } case '2': if (!strnEQ(name + 0,"M_", 2)) break; return constant_M_2(name, len, arg); case 'E': if (strEQ(name + 0, "M_E")) { /* removed */ #ifdef M_E return M_E; #else goto not_there; #endif } case 'L': if (!strnEQ(name + 0,"M_", 2)) break; return constant_M_L(name, len, arg); case 'P': if (!strnEQ(name + 0,"M_", 2)) break; return constant_M_P(name, len, arg); case 'S': if (!strnEQ(name + 0,"M_", 2)) break; return constant_M_S(name, len, arg); } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; } MODULE = Math::Libm PACKAGE = Math::Libm double constant(sv,arg) PREINIT: STRLEN len; INPUT: SV * sv char * s = SvPV(sv, len); int arg CODE: RETVAL = constant(s,len,arg); OUTPUT: RETVAL double acos(x) double x PROTOTYPE: $ double acosh(x) double x PROTOTYPE: $ double asin(x) double x PROTOTYPE: $ double asinh(x) double x PROTOTYPE: $ double atan(x) double x PROTOTYPE: $ double atanh(x) double x PROTOTYPE: $ double cbrt(x) double x PROTOTYPE: $ double ceil(x) double x PROTOTYPE: $ double cosh(x) double x PROTOTYPE: $ double erf(x) double x PROTOTYPE: $ double erfc(x) double x PROTOTYPE: $ double expm1(x) double x PROTOTYPE: $ double floor(x) double x PROTOTYPE: $ double hypot(x, y) double x double y PROTOTYPE: $$ double j0(x) double x PROTOTYPE: $ double j1(x) double x PROTOTYPE: $ double jn(n, x) int n double x PROTOTYPE: $$ double lgamma_r(x, signgamp) double x int &signgamp PROTOTYPE: $$ CODE: #ifdef _AIX RETVAL = lgamma(x); signgamp = signgam; #else RETVAL = lgamma_r(x, &signgamp); #endif OUTPUT: signgamp RETVAL double log10(x) double x PROTOTYPE: $ double log1p(x) double x PROTOTYPE: $ double pow(x, y) double x double y PROTOTYPE: $$ double rint(x) double x PROTOTYPE: $ double sinh(x) double x PROTOTYPE: $ double tan(x) double x PROTOTYPE: $ double tanh(x) double x PROTOTYPE: $ double y0(x) double x PROTOTYPE: $ double y1(x) double x PROTOTYPE: $ double yn(n, x) int n double x PROTOTYPE: $$ Math-Libm-1.00/Changes100644 1751 1751 442 7125310732 13560 0ustar lewartlewartRevision history for Perl extension Math::Libm. 0.01 Thu Jun 15 2000 - original version; created by h2xs 1.20 with options -n Math::Libm /usr/include/math.h -lm 1.00 Sun Jun 25 2000 - Tested on AIX 4.2, FreeBSD 4.0, Linux 2.2.16, and Solaris 2.5.1. - Good enough for beta release! Math-Libm-1.00/MANIFEST100644 1751 1751 74 7125310763 13403 0ustar lewartlewartChanges Libm.pm Libm.xs MANIFEST Makefile.PL README test.pl Math-Libm-1.00/Libm.pm100644 1751 1751 7112 7125310723 13527 0ustar lewartlewartpackage Math::Libm; use strict; # use warnings; use Carp; use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $AUTOLOAD); require Exporter; require DynaLoader; use AutoLoader; @ISA = qw(Exporter DynaLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use Math::Libm ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. %EXPORT_TAGS = ( 'all' => [ qw( M_1_PI M_2_PI M_2_SQRTPI M_E M_LN10 M_LN2 M_LOG10E M_LOG2E M_PI M_PI_2 M_PI_4 M_SQRT1_2 M_SQRT2 acos acosh asin asinh atan atanh cbrt ceil cosh erf erfc expm1 floor hypot j0 j1 jn lgamma_r log10 log1p pow rint sinh tan tanh y0 y1 yn ) ] ); @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); @EXPORT = qw(); $VERSION = '1.00'; sub AUTOLOAD { # This AUTOLOAD is used to 'autoload' constants from the constant() # XS function. If a constant is not found then control is passed # to the AUTOLOAD in AutoLoader. my $constname; ($constname = $AUTOLOAD) =~ s/.*:://; croak "& not defined" if $constname eq 'constant'; my $val = constant($constname, @_ ? $_[0] : 0); if ($! != 0) { if ($! =~ /Invalid/ || $!{EINVAL}) { $AutoLoader::AUTOLOAD = $AUTOLOAD; goto &AutoLoader::AUTOLOAD; } else { croak "Your vendor has not defined Math::Libm macro $constname"; } } { no strict 'refs'; # Fixed between 5.005_53 and 5.005_61 if ($] >= 5.00561) { # *$AUTOLOAD = sub () { $val }; *$AUTOLOAD = sub { $val }; } else { *$AUTOLOAD = sub { $val }; } } goto &$AUTOLOAD; } bootstrap Math::Libm $VERSION; # Preloaded methods go here. # Autoload methods go after =cut, and are processed by the autosplit program. 1; __END__ # Below is stub documentation for your module. You better edit it! =head1 NAME Math::Libm - Perl extension for the C math library, libm =head1 SYNOPSIS use Math::Libm ':all'; print "e = ", M_E, "\n"; print "pi/2 = ", M_PI_2, "\n"; print "erf(1) = ", erf(1), "\n"; print "hypot(3,4) = ", hypot(3,4), "\n"; my $signgam = 0; my $y = lgamma_r(-0.5, $signgam); print "signgam=$signgam lgamma=$y\n"; =head1 DESCRIPTION This module is a translation of the C F file. It exports the following selected constants and functions. =head2 EXPORT None by default. =head2 Exportable constants M_1_PI M_2_PI M_2_SQRTPI M_E M_LN10 M_LN2 M_LOG10E M_LOG2E M_PI M_PI_2 M_PI_4 M_SQRT1_2 M_SQRT2 =head2 Exportable functions double acos(double x) double acosh(double x) double asin(double x) double asinh(double x) double atan(double x) double atanh(double x) double cbrt(double x) double ceil(double x) double cosh(double x) double erf(double x) double erfc(double x) double expm1(double x) double floor(double x) double hypot(double x, double y) double j0(double x) double j1(double x) double jn(int n, double x) double lgamma_r(double x, int signgam) double log10(double x) double log1p(double x) double pow(double x, double y) double rint(double x) double sinh(double x) double tan(double x) double tanh(double x) double y0(double x) double y1(double x) double yn(int n, double x) =head1 AUTHOR Daniel S. Lewart, Ed-lewart@uiuc.eduE =head1 SEE ALSO L, L, L. =head1 BUGS Only tested on AIX 4.2, FreeBSD 4.0, Linux 2.2.16, and Solaris 2.5.1. May need some more functions. =cut Math-Libm-1.00/test.pl100644 1751 1751 4536 7125310720 13626 0ustar lewartlewart# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) my $loaded; BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use strict; use Math::Libm ':all'; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): my $i = 1; my $eps = 2**(-47); my $signgam = 0; while () { $i++; my ($exp, @a) = split; my @b = eval $exp; my $ok = (@b == @a); if ($ok) { my $s = 0; foreach my $i (0..$#a) { $s += ($b[$i]/$a[$i] - 1)**2; } $ok = sqrt($s) <= $eps; print "# $exp @a @b\n" if not $ok; } print $ok ? "" : "not ", "ok $i\n"; } __DATA__ M_1_PI 0.31830988618379067154 M_2_PI 0.63661977236758134308 M_2_SQRTPI 1.12837916709551257390 M_E 2.7182818284590452354 M_LN10 2.30258509299404568402 M_LN2 0.69314718055994530942 M_LOG10E 0.43429448190325182765 M_LOG2E 1.4426950408889634074 M_PI 3.14159265358979323846 M_PI_2 1.57079632679489661923 M_PI_4 0.78539816339744830962 M_SQRT1_2 0.70710678118654752440 M_SQRT2 1.41421356237309504880 acos(-1) 3.14159265358979323846 acosh(1.25) 0.69314718055994530942 asin(1) 1.57079632679489661923 asinh(0.75) 0.69314718055994530942 atan(1) 0.78539816339744830962 atanh(0.6) 0.69314718055994530942 cbrt(-8) -2 cbrt(8) 2 ceil(1.3) 2 ceil(1.7) 2 cosh(1) 1.54308063481524 erf(1) 0.842700792949715 erfc(1) 0.157299207050285 expm1(1) 1.7182818284590452354 floor(1.3) 1 floor(1.7) 1 hypot(3,4) 5 j0(1) 0.765197686557967 j1(1) 0.440050585744933 jn(2,1) 0.1149034849319 (lgamma_r(-0.5,$signgam),$signgam) 1.26551212348465 -1 (lgamma_r(0.5,$signgam),$signgam) 0.5723649429247 1 log10(10) 1 log1p(1) 0.69314718055994530942 pow(-2,3) -8 rint(1.3) 1 rint(1.7) 2 sinh(1) 1.1752011936438 tan(1) 1.5574077246549 tanh(1) 0.761594155955765 y0(1) 0.088256964215677 y1(1) -0.781212821300289 yn(2,1) -1.65068260681625