xref: /csrg-svn/lib/libm/README (revision 24652)
1*24652Szliu# @(#)README	1.2 (ELEFUNT) 09/08/85
224584Szliu-1.  The machine-independent Version 7 math library found in 4.2BSD
3*24652Szliu     is now "/usr/lib/libom.a".  To compile with those routines use -lom.
424584Szliu
524584SzliuK.C. Ng, March 7, 1985, with Z-S. Alex Liu, S. McDonald, P. Tang, W. Kahan.
624584SzliuRevised on 5/10/85, 5/13/85, 6/14/85, 8/20/85, 8/27/85.
724584Szliu
824584Szliu******************************************************************************
924584Szliu*  This is a description of the upgraded elementary functions (listed in 1). *
1024584Szliu*  Bessel functions (j0, j1, jn, y0, y1, yn), floor, and fabs passed over    *
1124584Szliu*  from 4.2BSD without change except perhaps for the way floating point      *
1224584Szliu*  exception is signaled on a VAX.  Three lines that contain "errno in erf.c *
1324584Szliu*  (error function erf, erfc) have been deleted to prevent overriding the    *
1424584Szliu*  system "errno".                                                           *
1524584Szliu******************************************************************************
1624584Szliu
1724584Szliu0. Total number of files: 40
1824584Szliu
1924584Szliu        IEEE/Makefile   VAX/Makefile    VAX/support.s   erf.c       lgama.c
2024584Szliu        IEEE/atan2.c    VAX/argred.s    VAX/tan.s       exp.c       log.c
2124584Szliu        IEEE/cabs.c     VAX/atan2.s     acosh.c         exp__E.c    log10.c
2224584Szliu        IEEE/cbrt.c     VAX/cabs.s      asincos.c       expm1.c     log1p.c
2324584Szliu        IEEE/support.c  VAX/cbrt.s      asinh.c         floor.c     log__L.c
2424584Szliu        IEEE/trig.c     VAX/infnan.s    atan.c          j0.c        pow.c
2524584Szliu        Makefile        VAX/sincos.s    atanh.c         j1.c        sinh.c
2624584Szliu        README          VAX/sqrt.s      cosh.c          jn.c        tanh.c
2724584Szliu
28*24652Szliu1. Functions implemented:
29*24652Szliu    (A). Standard elementary functions (total 22):
30*24652Szliu        acos(x)                 ... in file  "asincos.c"
31*24652Szliu        asin(x)                 ... in file  "asincos.c"
32*24652Szliu        atan(x)                 ... in file  "atan.c"
33*24652Szliu        atan2(x,y)              ... in files "IEEE/atan2.c", "VAX/atan2.s"
34*24652Szliu        sin(x)                  ... in files "IEEE/trig.c",  "VAX/sincos.s"
35*24652Szliu        cos(x)                  ... in files "IEEE/trig.c",  "VAX/sincos.s"
36*24652Szliu        tan(x)                  ... in files "IEEE/trig.c",  "VAX/tan.s"
37*24652Szliu        cabs(x,y)               ... in files "IEEE/cabs.c",  "VAX/cabs.s"
38*24652Szliu        hypot(x,y)              ... in files "IEEE/cabs.c",  "VAX/cabs.s"
39*24652Szliu        cbrt(x)                 ... in files "IEEE/cbrt.c",  "VAX/cbrt.s"
40*24652Szliu        exp(x)                  ... in file  "exp.c"
41*24652Szliu        expm1(x):=exp(x)-1      ... in file  "expm1.c"
42*24652Szliu        log(x)                  ... in file  "log.c"
43*24652Szliu        log10(x)                ... in file  "log10.c"
44*24652Szliu        log1p(x):=log(1+x)      ... in file  "log1p.c"
45*24652Szliu        pow(x,y)                ... in file  "pow.c"
46*24652Szliu        sinh(x)                 ... in file  "sinh.c"
47*24652Szliu        cosh(x)                 ... in file  "cosh.c"
48*24652Szliu        tanh(x)                 ... in file  "tanh.c"
49*24652Szliu        asinh(x)                ... in file  "asinh.c"
50*24652Szliu        acosh(x)                ... in file  "acosh.c"
51*24652Szliu        atanh(x)                ... in file  "atanh.c"
52*24652Szliu
5324584Szliu    (B). Kernel functions :
54*24652Szliu        exp__E(x,c) ... in file "exp__E.c", used by
55*24652Szliu		        expm1(), exp(), pow() and cosh()
56*24652Szliu        log__L(s)   ... in file "log__L.c", used by
57*24652Szliu		        log1p(), log() and pow()
58*24652Szliu        libm$argred ... in file "VAX/argred.s", used by VAX version of
59*24652Szliu		        sin(), cos() and tan()
6024584Szliu
6124584Szliu    (C). System supported functions :
62*24652Szliu        sqrt()      ... in files "IEEE/support.c", "VAX/sqrt.s"
63*24652Szliu        drem()      ... in files "IEEE/support.c", "VAX/support.s"
64*24652Szliu        finite()    ... in files "IEEE/support.c", "VAX/support.s"
65*24652Szliu        logb()      ... in files "IEEE/support.c", "VAX/support.s"
66*24652Szliu        scalb()     ... in files "IEEE/support.c", "VAX/support.s"
67*24652Szliu        copysign()  ... in files "IEEE/support.c", "VAX/support.s"
68*24652Szliu        rint()      ... in file  "floor.c"
6924584Szliu
7024584Szliu
7124584Szliu   Notes:
72*24652Szliu       i. The codes in files ending with ".s" are written in VAX assembly
7324584Szliu          language. They are intended for VAX computers.
7424584Szliu
75*24652Szliu          Files that end with ".c" are written in C. They are intended
7624584Szliu          for either a VAX or a machine that conforms to the IEEE
77*24652Szliu          standard 754 for double precision floating-point arithmetic.
7824584Szliu
7924584Szliu      ii. On other than VAX or IEEE machines, run the original math
80*24652Szliu          library, formerly "/usr/lib/libm.a", now "/usr/lib/libom.a",
81*24652Szliu	  if nothing better is available.
8224584Szliu
83*24652Szliu     iii. The trigonometric functions sin(), cos(), tan() and atan2() in files
84*24652Szliu	  "VAX/sincos.s", "VAX/tan.s" and "VAX/atan2.s" are different from
85*24652Szliu	  those in "IEEE/trig.c" and "IEEE/atan2.c".  The VAX assembler code
86*24652Szliu	  uses the true value of pi to perform argument reduction, while the
87*24652Szliu	  C code uses the machine's value of PI rounded (see "IEEE/trig.c").
8824584Szliu
8924584Szliu
9024584Szliu2. A computer system that conforms to IEEE standard 754 should provide
91*24652Szliu	  sqrt(x),
92*24652Szliu	  drem(x,p), (double precision remainder function)
93*24652Szliu	  copysign(x,y),
94*24652Szliu	  finite(x),
95*24652Szliu	  scalb(x,N),
96*24652Szliu	  logb(x) and
97*24652Szliu	  rint(x).
98*24652Szliu   These functions are either required or recommended by the standard.
9924584Szliu   For convenience, a (slow) C implementation of these functions is
100*24652Szliu   provided in the file "IEEE/support.c".
10124584Szliu
102*24652Szliu   Warning: The functions in "IEEE/support.c" are somewhat machine dependent.
10324584Szliu   Some modifications may be necessary to run them on a different machine.
104*24652Szliu   Currently, if compiled with a suitable flag, "IEEE/support.c" will work on a
10524584Szliu   National 32000, a Zilog 8000, a VAX, and a SUN (cf. the "Makefile" in
10624584Szliu   this directory). Invoke the C compiler thus:
10724584Szliu
10824584Szliu        cc -c -DVAX IEEE/support.c              ... on a VAX, D-format
109*24652Szliu        cc -c -DNATIONAL IEEE/support.c         ... on a National 32000
11024584Szliu        cc -c  IEEE/support.c                   ... on other IEEE machines,
11124584Szliu                                                    we hope.
11224584Szliu
11324584Szliu   Notes:
11424584Szliu      1. Faster versions of "drem" and "sqrt" for IEEE double precision
11524584Szliu         (coded in C but intended for assembly language) are given at the
116*24652Szliu         end of "IEEE/support.c" but commented out since they require certain
11724584Szliu         machine-dependent functions.
11824584Szliu
11924584Szliu      2. A fast VAX assembler version of the system supported functions
12024584Szliu         copysign(), logb(), scalb(), finite(), and drem() appears in file
121*24652Szliu         "VAX/support.s".  A fast VAX assembler version of sqrt() is in
122*24652Szliu         file "VAX/sqrt.s".
12324584Szliu
12424584Szliu3. Two formats are supported by all the standard elementary functions:
125*24652Szliu   the VAX D-format (56-bit precision), and the IEEE double format
126*24652Szliu   (53-bit precision).  The cbrt() in "IEEE/cbrt.c" is for IEEE machines
12724584Szliu   only. The functions in files that end with ".s" are for VAX computers
128*24652Szliu   only. The functions in files that end with ".c" (except "IEEE/cbrt.c") are
12924584Szliu   for VAX and IEEE machines. To use the VAX D-format, compile the code
13024584Szliu   with -DVAX; to use IEEE double format on various IEEE machines, see
131*24652Szliu   "Makefile" in this directory).
13224584Szliu
13324584Szliu    Example:
13424584Szliu        cc -c -DVAX sin.c               ... for VAX D-format
13524584Szliu
13624584Szliu       Warning: The values of floating-point constants used in the code are
13724584Szliu                given in both hexadecimal and decimal.  The hexadecimal values
138*24652Szliu                are the intended ones. The decimal values may be used provided
13924584Szliu                that the compiler converts from decimal to binary accurately
14024584Szliu                enough to produce the hexadecimal values shown. If the
14124584Szliu                conversion is inaccurate, then one must know the exact machine
142*24652Szliu                representation of the constants and alter the assembly
143*24652Szliu                language output from the compiler, or play tricks like
14424584Szliu                the following in a C program.
14524584Szliu
14624584Szliu                        Example: to store the floating-point constant
14724584Szliu
14824584Szliu                             p1= 2^-6 * .F83ABE67E1066A (Hexadecimal)
14924584Szliu
150*24652Szliu                        on a VAX in C, we use two longwords to store its
15124584Szliu                        machine value and define p1 to be the double constant
152*24652Szliu                        at the location of these two longwords:
15324584Szliu
154*24652Szliu                        static long  p1x[] = {0x3abe3d78, 0x066a67e1};
15524584Szliu                        #define      p1      (*(double*)p1x)
15624584Szliu
157*24652Szliu    Note:  On a VAX, some functions have two codes. For example, cabs() has
158*24652Szliu	   one implementation in "IEEE/cabs.c", and another in "VAX/cabs.s".
159*24652Szliu           In this case, the assembly language version is preferred.
16024584Szliu
16124584Szliu
16224584Szliu4. Accuracy.
16324584Szliu
16424584Szliu            The errors in expm1(), log1p(), exp(), log(), cabs(), hypot()
16524584Szliu            and cbrt() are below 1 ULP (Unit in the Last Place).
16624584Szliu
16724584Szliu            The error in pow(x,y) grows with the size of y. Nevertheless,
16824584Szliu            for integers x and y, pow(x,y) returns the correct integer value
16924584Szliu            on all tested machines (VAX, SUN, NATIONAL, ZILOG), provided that
17024584Szliu            x to the power of y is representable exactly.
17124584Szliu
172*24652Szliu            cosh(), sinh(), acosh(), asinh(), tanh(), atanh() and log10() have
173*24652Szliu	    errors below about 3 ULPs.
17424584Szliu
175*24652Szliu            For trigonometric and inverse trigonometric functions, let
176*24652Szliu	    [trig(x)] denote the value actually computed for trig(x).
17724584Szliu
17824584Szliu                1) Those codes using the machine's value PI (true pi rounded):
179*24652Szliu                   (in files "IEEE/trig.c", "IEEE/atan2.c", "asincos.c" and
180*24652Szliu		   "atan.c".)
18124584Szliu
18224584Szliu                   The errors in [sin(x)], [cos(x)], and [atan(x)] are below
18324584Szliu                   1 ULP compared with sin(x*pi/PI), cos(x*pi/PI), and
18424584Szliu                   atan(x)*PI/pi respectively, where PI is the machine's
185*24652Szliu                   value of pi rounded. [tan(x)] returns tan(x*pi/PI) within
18624584Szliu                   about 2 ULPs; [acos(x)], [asin(x)], and [atan2(y,x)]
18724584Szliu                   return acos(x)*PI/pi, asin(x)*PI/pi, and atan2(y,x)*PI/pi
18824584Szliu                   respectively to similar accuracy.
18924584Szliu
190*24652Szliu                2) Those using true pi (for VAX D-format only):
191*24652Szliu                   (in files "VAX/sincos.s", "VAX/tan.s", "VAX/atan2.s",
192*24652Szliu		   "asincos.c" and "atan.c".)
19324584Szliu
19424584Szliu                   The errors in [sin(x)], [cos(x)], and [atan(x)] are below
195*24652Szliu                   1 ULP.  [tan(x)], [atan2(y,x)], [acos(x)], and [asin(x)]
19624584Szliu                   have errors below about 2 ULPs.
19724584Szliu
19824584Szliu            Here are the results of some test runs to find worst errors on
19924584Szliu            the VAX :
20024584Szliu
20124584Szliu    tan   :  2.09 ULPs          ...1,024,000 random arguments (machine PI)
20224584Szliu    sin   :  .861 ULPs          ...1,024,000 random arguments (machine PI)
20324584Szliu    cos   :  .857 ULPs          ...1,024,000 random arguments (machine PI)
20424584Szliu    (compared with tan, sin, cos of (x*pi/PI))
20524584Szliu
20624584Szliu    acos  :  2.07 ULPs          .....200,000 random arguments (machine PI)
20724584Szliu    asin  :  2.06 ULPs          .....200,000 random arguments (machine PI)
20824584Szliu    atan2 :  1.41 ULPs          .....356,000 random arguments (machine PI)
20924584Szliu    atan  :  0.86 ULPs          ...1,536,000 random arguments (machine PI)
21024584Szliu    (compared with (PI/pi)*(atan, asin, acos, atan2 of x))
21124584Szliu
21224584Szliu    tan   :  2.15 ULPs          ...1,024,000 random arguments (true pi)
21324584Szliu    sin   :  .814 ULPs          ...1,024,000 random arguments (true pi)
21424584Szliu    cos   :  .792 ULPs          ...1,024,000 random arguments (true pi)
21524584Szliu    acos  :  2.15 ULPs          ...1,024,000 random arguments (true pi)
21624584Szliu    asin  :  1.99 ULPs          ...1,024,000 random arguments (true pi)
21724584Szliu    atan2 :  1.48 ULPs          ...1,024,000 random arguments (true pi)
21824584Szliu    atan  :  .850 ULPs          ...1,024,000 random arguments (true pi)
21924584Szliu
22024584Szliu    acosh :  3.30 ULPs          .....512,000 random arguments
22124584Szliu    asinh :  1.58 ULPs          .....512,000 random arguments
22224584Szliu    atanh :  1.71 ULPs          .....512,000 random arguments
22324584Szliu    cosh  :  1.23 ULPs          .....768,000 random arguments
22424584Szliu    sinh  :  1.93 ULPs          ...1,024,000 random arguments
22524584Szliu    tanh  :  2.22 ULPs          ...1,024,000 random arguments
22624584Szliu    log10 :  1.74 ULPs          ...1,536,000 random arguments
22724584Szliu    pow   :  1.79 ULPs          .....100,000 random arguments, 0 < x, y < 20.
22824584Szliu
22924584Szliu    exp   :  .768 ULPs          ...1,156,000 random arguments
23024584Szliu    expm1 :  .844 ULPs          ...1,166,000 random arguments
23124584Szliu    log1p :  .846 ULPs          ...1,536,000 random arguments
23224584Szliu    log   :  .826 ULPs          ...1,536,000 random arguments
23324584Szliu    cabs  :  .959 ULPs          .....500,000 random arguments
23424584Szliu    cbrt  :  .666 ULPs          ...5,120,000 random arguments
23524584Szliu
23624584Szliu
23724584Szliu5. Speed.
23824584Szliu
239*24652Szliu        Some functions coded in VAX assembly language (cabs(), hypot() and
240*24652Szliu	sqrt()) are significantly faster than the corresponding ones in 4.2BSD.
241*24652Szliu        In general, to improve performance, all functions in "IEEE/support.c"
242*24652Szliu        should be written in assembly language and, whenever possible, should
243*24652Szliu	be called via short subroutine calls.
24424584Szliu
24524584Szliu
24624584Szliu6. j0,j1,jn.
24724584Szliu
24824584Szliu        The modifications to these routines were only in how an invalid
249*24652Szliu        floating point operation is signaled on a VAX.
25024584Szliu
25124584Szliu
25224584Szliu7. Copyright notice, and Disclaimer:
25324584Szliu
25424584Szliu***************************************************************************
25524584Szliu*                                                                         *
25624584Szliu* Copyright (c) 1985 Regents of the University of California.             *
25724584Szliu*                                                                         *
25824584Szliu* Use and reproduction of this software are granted  in  accordance  with *
25924584Szliu* the terms and conditions specified in  the  Berkeley  Software  License *
26024584Szliu* Agreement (in particular, this entails acknowledgement of the programs' *
26124584Szliu* source, and inclusion of this notice) with the additional understanding *
26224584Szliu* that  all  recipients  should regard themselves as participants  in  an *
26324584Szliu* ongoing  research  project and hence should  feel  obligated  to report *
26424584Szliu* their  experiences (good or bad) with these elementary function  codes, *
26524584Szliu* using "sendbug 4bsd-bugs@BERKELEY", to the authors.                     *
26624584Szliu*                                                                         *
26724584Szliu***************************************************************************
268