Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbatt!ihnp4!ptsfa!styx!ames!sri-spam!sri-unix!husc6!uwvax!oddjob!hao!noao!mcdsun!fnf From: fnf@mcdsun.UUCP Newsgroups: net.sources Subject: Portable Math Library (Part 1b of 6 REPOST) Message-ID: <307@mcdsun.UUCP> Date: Wed, 29-Apr-87 17:11:29 EDT Article-I.D.: mcdsun.307 Posted: Wed Apr 29 17:11:29 1987 Date-Received: Sat, 2-May-87 01:41:53 EDT Organization: Motorola Microcomputer Division, Tempe, Az. Lines: 1069 Keywords: was truncated It appears that Part 1 of 6 of the pml posting was truncated or lost because it exceeded 64000 characters; *NOT* 64K (???). Anyway, I've split the contents up into two postings, Part 1a and Part 1b. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh funcs/src/ctan.c <<'END_OF_funcs/src/ctan.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * ctan complex double precision tangent X * X * KEY WORDS X * X * ctan X * complex functions X * machine independent functions X * math libraries X * X * DESCRIPTION X * X * Computes double precision complex tangent of a double X * precision complex argument. X * X * USAGE X * X * COMPLEX ctan (z) X * COMPLEX z; X * X * PROGRAMMER X * X * Fred Fish X * Tempe, Az 85281 X * (602) 966-8871 X * X * INTERNALS X * X * Computes complex tangent of z = x + j y from: X * X * 1. Compute ccos(z) X * X * 2. If ccos(z) = 0 + j0 then the X * result is MAX_POS_DBLF + j0 X * X * 3. Else ctan(z) = csin(z) / ccos(z) X * X */ X X#include X#include X#include "pml.h" X X XCOMPLEX ctan (z) XCOMPLEX z; X{ X COMPLEX ccosz; X extern COMPLEX ccos (), csin (), cdiv (); X X ENTER ("ctan"); X DEBUG4 ("ctanin", "arg %le %le", z.real, z.imag); X ccosz = ccos (z); X if (ccosz.real == 0.0 && ccosz.imag == 0.0) { X/***** X z.real = MAX_POS_DBLF; X******/ X z.real = 0.0; /* TERRIBLY WRONG! */ X z.imag = 0.0; X } else { X z = csin (z); X z = cdiv (z, ccosz); X } X DEBUG4 ("ctanout", "result %le %le", z.real, z.imag); X LEAVE (); X return (z); X} END_OF_funcs/src/ctan.c if test 1942 -ne `wc -c funcs/src/ctanh.c <<'END_OF_funcs/src/ctanh.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * ctanh complex double precision hyperbolic tangent X * X * KEY WORDS X * X * ctanh X * complex functions X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Computes double precision complex hyperbolic tangent of X * a double precision complex argument. X * X * USAGE X * X * COMPLEX ctanh (z) X * COMPLEX z; X * X * PROGRAMMER X * X * Fred Fish X * Tempe, Az 85281 X * (602) 966-8871 X * X * INTERNALS X * X * Computes complex hyperbolic tangent of Z = x + j y from: X * X * ctanh(z) = (1 - cexp(-2z)) / (1 + cexp(-2z)) X * X */ X X#include X#include X#include "pml.h" X X XCOMPLEX ctanh (z) XCOMPLEX z; X{ X COMPLEX result; X extern COMPLEX cexp (), cdiv (); X X ENTER ("ctanh"); X DEBUG4 ("ctanhin", "arg %le %le", z.real, z.imag); X result.real = -2.0 * z.real; X result.imag = -2.0 * z.imag; X result = cexp (result); X z.real = 1.0 - result.real; X z.imag = -result.imag; X result.real += 1.0; X result = cdiv (z, result); X DEBUG4 ("ctanhout", "result %le %le", result.real, result.imag); X LEAVE (); X return (result); X} END_OF_funcs/src/ctanh.c if test 1898 -ne `wc -c funcs/src/dabs.c <<'END_OF_funcs/src/dabs.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * dabs,fabs double precision absolute value X * X * KEY WORDS X * X * dabs X * fabs X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Returns absolute value of double precision number. X * X * The fabs routine is supplied for compatibility with unix X * libraries where for some bizarre reason, the double precision X * absolute value routine is called fabs. X * X * USAGE X * X * double dabs (x) X * double x; X * X * double fabs (x) X * double x; X * X * PROGRAMMER X * X * Fred Fish X * X */ X X#include X#include X#include "pml.h" X Xstatic char funcname[] = "dabs"; X X Xdouble dabs (x) Xdouble x; X{ X DBUG_ENTER (funcname); X DBUG_3 ("dabsin", "arg %le", x); X if (x < 0.0) { X x = -x; X } X DBUG_3 ("dabsout", "result %le", x); X DBUG_RETURN (x); X} X X Xdouble fabs (x) Xdouble x; X{ X return (dabs(x)); X} END_OF_funcs/src/dabs.c if test 1653 -ne `wc -c funcs/src/log10.c <<'END_OF_funcs/src/log10.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * log10 double precision common log X * X * KEY WORDS X * X * log10 X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Returns double precision common log of double precision X * floating point argument. X * X * USAGE X * X * double log10 (x) X * double x; X * X * REFERENCES X * X * PDP-11 Fortran IV-plus users guide, Digital Equip. Corp., X * 1975, pp. B-3. X * X * RESTRICTIONS X * X * For precision information refer to documentation of the X * floating point library routines called. X * X * PROGRAMMER X * X * Fred Fish X * X * INTERNALS X * X * Computes log10(x) from: X * X * log10(x) = log10(e) * log(x) X * X */ X X#include X#include X#include "pml.h" X Xstatic char funcname[] = "log10"; X X Xdouble log10 (x) Xdouble x; X{ X extern double log (); X X DBUG_ENTER (funcname); X DBUG_3 ("log10in", "arg %le", x); X x = LOG10E * log (x); X DBUG_3 ("log10out", "result %le", x); X DBUG_RETURN (x); X} END_OF_funcs/src/log10.c if test 1744 -ne `wc -c funcs/src/matherr.c <<'END_OF_funcs/src/matherr.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * matherr default math error handler function X * X * KEY WORDS X * X * error handler X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Default math error handler for the math library. This routine X * may be replaced by one of the user's own handlers. The default X * is to do nothing and returns zero. If the user wishes to supply X * the return value for the function, and to suppress default X * error handling by the function, his matherr routine must return X * non-zero. X * X * USAGE X * X * int matherr (xcpt) X * struct exception *xcpt; X * X * PROGRAMMER X * X * Fred Fish X * X */ X X#include X#include X#include "pml.h" X Xstatic char funcname[] = "matherr"; X Xint matherr (xcpt) Xstruct exception *xcpt; X{ X DBUG_ENTER (funcname); X DBUG_RETURN (0); X} END_OF_funcs/src/matherr.c if test 1609 -ne `wc -c funcs/src/max.c <<'END_OF_funcs/src/max.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * max double precision maximum of two arguments X * X * KEY WORDS X * X * max X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Returns maximum value of two double precision numbers. X * X * USAGE X * X * double max (x,y) X * double x; X * double y; X * X * PROGRAMMER X * X * Fred Fish X * Tempe, Az 85281 X * X */ X X#include X#include X#include "pml.h" X X Xdouble max (x, y) Xdouble x; Xdouble y; X{ X ENTER ("max"); X DEBUG4 ("maxin", "x = %le y = %le", x, y); X if (x < y) { X x = y; X } X DEBUG3 ("maxout", "result %le", x); X LEAVE (); X return (x); X} END_OF_funcs/src/max.c if test 1411 -ne `wc -c funcs/src/min.c <<'END_OF_funcs/src/min.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * min double precision minimum of two arguments X * X * KEY WORDS X * X * min X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Returns minimum value of two double precision numbers. X * X * USAGE X * X * double min (x, y) X * double x; X * double y; X * X * PROGRAMMER X * X * Fred Fish X * Tempe, Az 85281 X * X */ X X#include X#include X#include "pml.h" X X Xdouble min (x, y) Xdouble x; Xdouble y; X{ X ENTER ("min"); X DEBUG4 ("minin", "x = %le y = %le", x, y); X if (x > y) { X x = y; X } X DEBUG3 ("minout", "result %le", x); X LEAVE (); X return (x); X} END_OF_funcs/src/min.c if test 1412 -ne `wc -c funcs/src/mod.c <<'END_OF_funcs/src/mod.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * mod double precision modulo X * X * KEY WORDS X * X * mod X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Returns double precision modulo of two double X * precision arguments. X * X * USAGE X * X * double mod (value, base) X * double value; X * double base; X * X * PROGRAMMER X * X * Fred Fish X * X */ X X X#include X#include X#include "pml.h" X Xdouble mod (value, base) Xdouble value; Xdouble base; X{ X auto double intpart; X extern double modf (); X X DBUG_ENTER ("mod"); X DBUG_4 ("modin", "args %le %le", value, base); X value /= base; X value = modf (value, &intpart); X value *= base; X DBUG_3 ("modout", "result %le", value); X DBUG_RETURN (value); X} END_OF_funcs/src/mod.c if test 1520 -ne `wc -c funcs/src/pmluser.h <<'END_OF_funcs/src/pmluser.h' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FILE X * X * pmluser.h include file for users of portable math library X * X * SYNOPSIS X * X * #include X * X * DESCRIPTION X * X * This file should be included in any user compilation module X * which accesses routines from the Portable Math Library (PML). X * X */ X X X/* X * Create the type "COMPLEX". This is an obvious extension that I X * hope becomes a part of standard C someday. X * X */ X Xtypedef struct cmplx { /* Complex structure */ X double real; /* Real part */ X double imag; /* Imaginary part */ X} COMPLEX; END_OF_funcs/src/pmluser.h if test 1332 -ne `wc -c funcs/src/sign.c <<'END_OF_funcs/src/sign.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X X/* X * FUNCTION X * X * sign transfer of sign X * X * KEY WORDS X * X * sign X * machine independent routines X * math libraries X * X * DESCRIPTION X * X * Returns first argument with same sign as second argument. X * X * USAGE X * X * double sign (x, y) X * double x; X * double y; X * X * PROGRAMMER X * X * Fred Fish X * Tempe, Az 85281 X * (602) 966-8871 X * X */ X X#include X#include X#include "pml.h" X X Xdouble sign (x, y) Xdouble x; Xdouble y; X{ X double rtnval; X X ENTER ("sign"); X DEBUG4 ("signin", "args %le %le", x, y); X if (x > 0.0) { X if (y > 0.0) { X rtnval = x; X } else { X rtnval = -x; X } X } else { X if (y < 0.0) { X rtnval = x; X } else { X rtnval = -x; X } X } X DEBUG3 ("signout", "result %le", rtnval); X LEAVE (); X return (rtnval); X} END_OF_funcs/src/sign.c if test 1580 -ne `wc -c funcs/unused/frac.c <<'END_OF_funcs/unused/frac.c' X/************************************************************************ X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * This previously copyrighted work has been placed into the * X * public domain by the author (Fred Fish) and may be freely used * X * for any purpose, private or commercial. I would appreciate * X * it, as a courtesy, if this notice is left in all copies and * X * derivative works. Thank you, and enjoy... * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of * X * merchantability or fitness for any particular purpose. * X * * X ************************************************************************ X */ X X/* X * FUNCTION X * X * frac double precision fractional portion X * X * KEY WORDS X * X * frac X * machine dependent routines X * math libraries X * X * DESCRIPTION X * X * Returns fractional portion of double precision number as double X * precision number. X * X * USAGE X * X * double frac(x) X * double x; X * X * PROGRAMMER X * X * Fred Fish X * Tempe, Az 85281 X * (602) 966-8871 X * X */ X X#include X#include X#include "pml.h" X X Xdouble frac(x) Xdouble x; X{ X double dint(); X X return (x - dint(x)); X} END_OF_funcs/unused/frac.c if test 1305 -ne `wc -c tests/Makefile <<'END_OF_tests/Makefile' XCFLAGS = -DHELP -O XLIBS = -lpml -lm -ldbg X Xall : d2d dd2d c2d c2c cc2c X Xd2d : d2d.o X cc -o d2d d2d.o $(LIBS) X Xdd2d : dd2d.o X cc -o dd2d dd2d.o $(LIBS) X Xc2d : c2d.o X cc -o c2d c2d.o $(LIBS) X Xc2c : c2c.o X cc -o c2c c2c.o $(LIBS) X Xcc2c : cc2c.o X cc -o cc2c cc2c.o $(LIBS) X X X# X# Clean up the directory. X# X Xclean: X rm -f c2c c2d cc2c d2d dd2d *.BAK *.bak *.tmp nohup.out *.o END_OF_tests/Makefile if test 388 -ne `wc -c tests/c2d.dat <<'END_OF_tests/c2d.dat' Xcabs 1.000000000000e00 2.000000000000e00 2.23606798052788e00 Xcabs 0.000000000000e00 2.000000000000e00 2.00000000000000e00 Xcabs 1.000000000000e00 0.000000000000e00 1.00000000000000e00 Xcabs -2.000000000000e00 2.000000000000e00 2.82842713594437e00 Xcabs -1.000000000000e00 -2.000000000000e00 2.23606798052788e00 Xcabs 1.000000000000e00 -2.000000000000e00 2.23606798052788e00 END_OF_tests/c2d.dat if test 401 -ne `wc -c tests/dd2d.dat <<'END_OF_tests/dd2d.dat' Xatan2 -6.000000000000e-01 -5.000000000000e-01 -2.44685437739309e00 Xatan2 0.000000000000e00 -1.000000000000e00 -1.57079632679490e00 Xatan2 6.000000000000e-01 -5.000000000000e-01 -6.94738276196703e-01 Xatan2 1.000000000000e00 0.000000000000e00 0.00000000000000e00 Xatan2 6.000000000000e-01 5.000000000000e-01 6.94738276196703e-01 Xatan2 0.000000000000e00 1.000000000000e00 1.57079632679490e00 Xatan2 -6.000000000000e-01 5.000000000000e-01 2.44685437739309e00 Xatan2 -1.000000000000e00 0.000000000000e00 -3.14159265358979e00 Xmax 6.0 5.0 6.0 Xmax 0.0 0.0 0.0 Xmax 0.1 0.2 0.2 Xmax -0.1 -0.2 -0.1 Xmax -0.1 0.2 0.2 Xmax 0.1 0.2 0.2 Xmax 0.1 -0.2 0.1 Xmax 1e10 1.1e10 1.1e10 Xmax -1e10 -1.1e10 -1e10 Xmax 1e-10 1.1e-10 1.1e-10 Xmin 6.0 5.0 5.0 Xmin 0.0 0.0 0.0 Xmin 0.1 0.2 0.1 Xmin -0.1 -0.2 -0.2 Xmin -0.1 0.2 -0.1 Xmin 0.1 0.2 0.1 Xmin 0.1 -0.2 -0.2 Xmin 1e10 1.1e10 1e10 Xmin -1e10 -1.1e10 -1.1e10 Xmin 1e-10 1.1e-10 1e-10 END_OF_tests/dd2d.dat if test 1082 -ne `wc -c tests/unused/d2i.dat <<'END_OF_tests/unused/d2i.dat' Xxexp 65536.0 16 Xxexp 256.0 8 Xxexp 4.0 2 Xxexp 2.0 1 Xxexp 1.0 0 Xxexp 0.0 0 Xxexp 0.5 -1 Xxexp 0.25 -2 Xxexp 0.125 -3 END_OF_tests/unused/d2i.dat if test 117 -ne `wc -c tests/unused/di2d.dat <<'END_OF_tests/unused/di2d.dat' Xscale 1.0 2 4.0 Xscale 1.0 -2 0.25 Xscale 0.0 10 0.0 Xscale -1.0 2 -4.0 Xscale -1.0 -2 -0.25 END_OF_tests/unused/di2d.dat if test 104 -ne `wc -c