xref: /csrg-svn/lib/libm/README (revision 61281)
134116Sbostic/*
2*61281Sbostic * Copyright (c) 1985, 1993
3*61281Sbostic *	The Regents of the University of California.  All rights reserved.
434116Sbostic *
545299Sbostic * %sccs.include.redist.c%
634116Sbostic *
734116Sbostic * K.C. Ng, with Z-S. Alex Liu, S. McDonald, P. Tang, W. Kahan.
834116Sbostic * Revised on 5/10/85, 5/13/85, 6/14/85, 8/20/85, 8/27/85, 9/11/85.
934116Sbostic *
10*61281Sbostic *	@(#)README	8.1 (Berkeley) 06/04/93
1134116Sbostic */
1224584Szliu
1324584Szliu******************************************************************************
1424584Szliu*  This is a description of the upgraded elementary functions (listed in 1). *
1524584Szliu*  Bessel functions (j0, j1, jn, y0, y1, yn), floor, and fabs passed over    *
1624584Szliu*  from 4.2BSD without change except perhaps for the way floating point      *
1724715Selefunt*  exception is signaled on a VAX.  Three lines that contain "errno" in erf.c*
1824715Selefunt*  (error functions erf, erfc) have been deleted to prevent overriding the   *
1924584Szliu*  system "errno".                                                           *
2024584Szliu******************************************************************************
2124584Szliu
2224584Szliu0. Total number of files: 40
2324584Szliu
2424715Selefunt        IEEE/Makefile   VAX/Makefile    VAX/support.s   erf.c       lgamma.c
2524584Szliu        IEEE/atan2.c    VAX/argred.s    VAX/tan.s       exp.c       log.c
2624584Szliu        IEEE/cabs.c     VAX/atan2.s     acosh.c         exp__E.c    log10.c
2724584Szliu        IEEE/cbrt.c     VAX/cabs.s      asincos.c       expm1.c     log1p.c
2824584Szliu        IEEE/support.c  VAX/cbrt.s      asinh.c         floor.c     log__L.c
2924584Szliu        IEEE/trig.c     VAX/infnan.s    atan.c          j0.c        pow.c
3024584Szliu        Makefile        VAX/sincos.s    atanh.c         j1.c        sinh.c
3124584Szliu        README          VAX/sqrt.s      cosh.c          jn.c        tanh.c
3224584Szliu
3324715Selefunt1. Functions implemented :
3424715Selefunt    (A). Standard elementary functions (total 22) :
3524715Selefunt        acos(x)                 ...in file  asincos.c
3624715Selefunt        asin(x)                 ...in file  asincos.c
3724715Selefunt        atan(x)                 ...in file  atan.c
3824715Selefunt        atan2(x,y)              ...in files IEEE/atan2.c, VAX/atan2.s
3924715Selefunt        sin(x)                  ...in files IEEE/trig.c,  VAX/sincos.s
4024715Selefunt        cos(x)                  ...in files IEEE/trig.c,  VAX/sincos.s
4124715Selefunt        tan(x)                  ...in files IEEE/trig.c,  VAX/tan.s
4224715Selefunt        cabs(x,y)               ...in files IEEE/cabs.c,  VAX/cabs.s
4324715Selefunt        hypot(x,y)              ...in files IEEE/cabs.c,  VAX/cabs.s
4424715Selefunt        cbrt(x)                 ...in files IEEE/cbrt.c,  VAX/cbrt.s
4524715Selefunt        exp(x)                  ...in file  exp.c
4624715Selefunt        expm1(x):=exp(x)-1      ...in file  expm1.c
4724715Selefunt        log(x)                  ...in file  log.c
4824715Selefunt        log10(x)                ...in file  log10.c
4924715Selefunt        log1p(x):=log(1+x)      ...in file  log1p.c
5024715Selefunt        pow(x,y)                ...in file  pow.c
5124715Selefunt        sinh(x)                 ...in file  sinh.c
5224715Selefunt        cosh(x)                 ...in file  cosh.c
5324715Selefunt        tanh(x)                 ...in file  tanh.c
5424715Selefunt        asinh(x)                ...in file  asinh.c
5524715Selefunt        acosh(x)                ...in file  acosh.c
5624715Selefunt        atanh(x)                ...in file  atanh.c
5724715Selefunt
5824584Szliu    (B). Kernel functions :
5924715Selefunt        exp__E(x,c) ...in file exp__E.c, used by expm1/exp/pow/cosh
6024715Selefunt        log__L(s)   ...in file log__L.c, used by log1p/log/pow
6124715Selefunt        libm$argred ...in file VAX/argred.s, used by VAX version of sin/cos/tan
6224584Szliu
6324584Szliu    (C). System supported functions :
6424715Selefunt        sqrt()      ...in files IEEE/support.c, VAX/sqrt.s
6524715Selefunt        drem()      ...in files IEEE/support.c, VAX/support.s
6624715Selefunt        finite()    ...in files IEEE/support.c, VAX/support.s
6724715Selefunt        logb()      ...in files IEEE/support.c, VAX/support.s
6824715Selefunt        scalb()     ...in files IEEE/support.c, VAX/support.s
6924715Selefunt        copysign()  ...in files IEEE/support.c, VAX/support.s
7024715Selefunt        rint()      ...in file  floor.c
7124584Szliu
7224584Szliu
7324584Szliu   Notes:
7424652Szliu       i. The codes in files ending with ".s" are written in VAX assembly
7524584Szliu          language. They are intended for VAX computers.
7624584Szliu
7724652Szliu          Files that end with ".c" are written in C. They are intended
7824584Szliu          for either a VAX or a machine that conforms to the IEEE
7924652Szliu          standard 754 for double precision floating-point arithmetic.
8024584Szliu
8124584Szliu      ii. On other than VAX or IEEE machines, run the original math
8224715Selefunt          library, formerly "/usr/lib/libm.a", now "/usr/lib/libom.a", if
8324715Selefunt	  nothing better is available.
8424584Szliu
8524715Selefunt     iii. The trigonometric functions sin/cos/tan/atan2 in files "VAX/sincos.s",
8624715Selefunt          "VAX/tan.s" and "VAX/atan2.s" are different from those in
8724715Selefunt          "IEEE/trig.c" and "IEEE/atan2.c".  The VAX assembler code uses the
8824715Selefunt          true value of pi to perform argument reduction, while the C code uses
8924715Selefunt          a machine value of PI (see "IEEE/trig.c").
9024584Szliu
9124584Szliu
9224584Szliu2. A computer system that conforms to IEEE standard 754 should provide
9324715Selefunt                sqrt(x),
9424715Selefunt                drem(x,p), (double precision remainder function)
9524715Selefunt                copysign(x,y),
9624715Selefunt                finite(x),
9724715Selefunt                scalb(x,N),
9824715Selefunt                logb(x) and
9924715Selefunt                rint(x).
10024652Szliu   These functions are either required or recommended by the standard.
10124584Szliu   For convenience, a (slow) C implementation of these functions is
10224652Szliu   provided in the file "IEEE/support.c".
10324584Szliu
10424715Selefunt   Warning: The functions in IEEE/support.c are somewhat machine dependent.
10524584Szliu   Some modifications may be necessary to run them on a different machine.
10624715Selefunt   Currently, if compiled with a suitable flag, "IEEE/support.c" will work
10724715Selefunt   on a National 32000, a Zilog 8000, a VAX, and a SUN (cf. the "Makefile"
10824715Selefunt   in this directory). Invoke the C compiler thus:
10924584Szliu
11024584Szliu        cc -c -DVAX IEEE/support.c              ... on a VAX, D-format
11124652Szliu        cc -c -DNATIONAL IEEE/support.c         ... on a National 32000
11224584Szliu        cc -c  IEEE/support.c                   ... on other IEEE machines,
11324584Szliu                                                    we hope.
11424584Szliu
11524584Szliu   Notes:
11624584Szliu      1. Faster versions of "drem" and "sqrt" for IEEE double precision
11724584Szliu         (coded in C but intended for assembly language) are given at the
11824652Szliu         end of "IEEE/support.c" but commented out since they require certain
11924584Szliu         machine-dependent functions.
12024584Szliu
12124584Szliu      2. A fast VAX assembler version of the system supported functions
12224584Szliu         copysign(), logb(), scalb(), finite(), and drem() appears in file
12324652Szliu         "VAX/support.s".  A fast VAX assembler version of sqrt() is in
12424652Szliu         file "VAX/sqrt.s".
12524584Szliu
12624584Szliu3. Two formats are supported by all the standard elementary functions:
12724652Szliu   the VAX D-format (56-bit precision), and the IEEE double format
12824652Szliu   (53-bit precision).  The cbrt() in "IEEE/cbrt.c" is for IEEE machines
12924584Szliu   only. The functions in files that end with ".s" are for VAX computers
13024715Selefunt   only. The functions in files that end with ".c" (except "IEEE/cbrt.c")
13124715Selefunt   are for VAX and IEEE machines. To use the VAX D-format, compile the code
13224584Szliu   with -DVAX; to use IEEE double format on various IEEE machines, see
13324652Szliu   "Makefile" in this directory).
13424584Szliu
13524584Szliu    Example:
13624584Szliu        cc -c -DVAX sin.c               ... for VAX D-format
13724584Szliu
13824584Szliu       Warning: The values of floating-point constants used in the code are
13924584Szliu                given in both hexadecimal and decimal.  The hexadecimal values
14024652Szliu                are the intended ones. The decimal values may be used provided
14124584Szliu                that the compiler converts from decimal to binary accurately
14224584Szliu                enough to produce the hexadecimal values shown. If the
14324584Szliu                conversion is inaccurate, then one must know the exact machine
14424652Szliu                representation of the constants and alter the assembly
14524715Selefunt                language output from the compiler, or play tricks like
14624584Szliu                the following in a C program.
14724584Szliu
14824584Szliu                        Example: to store the floating-point constant
14924584Szliu
15024584Szliu                             p1= 2^-6 * .F83ABE67E1066A (Hexadecimal)
15124584Szliu
15224652Szliu                        on a VAX in C, we use two longwords to store its
15324584Szliu                        machine value and define p1 to be the double constant
15424652Szliu                        at the location of these two longwords:
15524584Szliu
15624715Selefunt                        static long  p1x[] = { 0x3abe3d78, 0x066a67e1};
15724584Szliu                        #define      p1      (*(double*)p1x)
15824584Szliu
15924652Szliu    Note:  On a VAX, some functions have two codes. For example, cabs() has
16024715Selefunt	   one implementation in "IEEE/cabs.c", and another in "VAX/cabs.s".
16124652Szliu           In this case, the assembly language version is preferred.
16224584Szliu
16324584Szliu
16424584Szliu4. Accuracy.
16524584Szliu
16624584Szliu            The errors in expm1(), log1p(), exp(), log(), cabs(), hypot()
16724584Szliu            and cbrt() are below 1 ULP (Unit in the Last Place).
16824584Szliu
16924584Szliu            The error in pow(x,y) grows with the size of y. Nevertheless,
17024584Szliu            for integers x and y, pow(x,y) returns the correct integer value
17124584Szliu            on all tested machines (VAX, SUN, NATIONAL, ZILOG), provided that
17224584Szliu            x to the power of y is representable exactly.
17324584Szliu
17424715Selefunt            cosh, sinh, acosh, asinh, tanh, atanh and log10 have errors below
17524715Selefunt            about 3 ULPs.
17624584Szliu
17724715Selefunt            For trigonometric and inverse trigonometric functions:
17824584Szliu
17924715Selefunt                Let [trig(x)] denote the value actually computed for trig(x),
18024715Selefunt
18124584Szliu                1) Those codes using the machine's value PI (true pi rounded):
18224715Selefunt                   (source codes: IEEE/{trig.c,atan2.c}, asincos.c and atan.c)
18324584Szliu
18424584Szliu                   The errors in [sin(x)], [cos(x)], and [atan(x)] are below
18524584Szliu                   1 ULP compared with sin(x*pi/PI), cos(x*pi/PI), and
18624584Szliu                   atan(x)*PI/pi respectively, where PI is the machine's
18724652Szliu                   value of pi rounded. [tan(x)] returns tan(x*pi/PI) within
18824584Szliu                   about 2 ULPs; [acos(x)], [asin(x)], and [atan2(y,x)]
18924584Szliu                   return acos(x)*PI/pi, asin(x)*PI/pi, and atan2(y,x)*PI/pi
19024584Szliu                   respectively to similar accuracy.
19124584Szliu
19224715Selefunt
19324652Szliu                2) Those using true pi (for VAX D-format only):
19424715Selefunt                   (source codes: VAX/{sincos.s,tan.s,atan2.s}, asincos.c and
19524715Selefunt                   atan.c)
19624584Szliu
19724584Szliu                   The errors in [sin(x)], [cos(x)], and [atan(x)] are below
19824715Selefunt                   1 ULP. [tan(x)], [atan2(y,x)], [acos(x)], and [asin(x)]
19924584Szliu                   have errors below about 2 ULPs.
20024584Szliu
20124715Selefunt
20224584Szliu            Here are the results of some test runs to find worst errors on
20324584Szliu            the VAX :
20424584Szliu
20524584Szliu    tan   :  2.09 ULPs          ...1,024,000 random arguments (machine PI)
20624584Szliu    sin   :  .861 ULPs          ...1,024,000 random arguments (machine PI)
20724584Szliu    cos   :  .857 ULPs          ...1,024,000 random arguments (machine PI)
20824584Szliu    (compared with tan, sin, cos of (x*pi/PI))
20924584Szliu
21024584Szliu    acos  :  2.07 ULPs          .....200,000 random arguments (machine PI)
21124584Szliu    asin  :  2.06 ULPs          .....200,000 random arguments (machine PI)
21224584Szliu    atan2 :  1.41 ULPs          .....356,000 random arguments (machine PI)
21324584Szliu    atan  :  0.86 ULPs          ...1,536,000 random arguments (machine PI)
21424584Szliu    (compared with (PI/pi)*(atan, asin, acos, atan2 of x))
21524584Szliu
21624584Szliu    tan   :  2.15 ULPs          ...1,024,000 random arguments (true pi)
21724584Szliu    sin   :  .814 ULPs          ...1,024,000 random arguments (true pi)
21824584Szliu    cos   :  .792 ULPs          ...1,024,000 random arguments (true pi)
21924584Szliu    acos  :  2.15 ULPs          ...1,024,000 random arguments (true pi)
22024584Szliu    asin  :  1.99 ULPs          ...1,024,000 random arguments (true pi)
22124584Szliu    atan2 :  1.48 ULPs          ...1,024,000 random arguments (true pi)
22224584Szliu    atan  :  .850 ULPs          ...1,024,000 random arguments (true pi)
22324584Szliu
22424584Szliu    acosh :  3.30 ULPs          .....512,000 random arguments
22524584Szliu    asinh :  1.58 ULPs          .....512,000 random arguments
22624584Szliu    atanh :  1.71 ULPs          .....512,000 random arguments
22724584Szliu    cosh  :  1.23 ULPs          .....768,000 random arguments
22824584Szliu    sinh  :  1.93 ULPs          ...1,024,000 random arguments
22924584Szliu    tanh  :  2.22 ULPs          ...1,024,000 random arguments
23024584Szliu    log10 :  1.74 ULPs          ...1,536,000 random arguments
23124584Szliu    pow   :  1.79 ULPs          .....100,000 random arguments, 0 < x, y < 20.
23224584Szliu
23324584Szliu    exp   :  .768 ULPs          ...1,156,000 random arguments
23424584Szliu    expm1 :  .844 ULPs          ...1,166,000 random arguments
23524584Szliu    log1p :  .846 ULPs          ...1,536,000 random arguments
23624584Szliu    log   :  .826 ULPs          ...1,536,000 random arguments
23724584Szliu    cabs  :  .959 ULPs          .....500,000 random arguments
23824584Szliu    cbrt  :  .666 ULPs          ...5,120,000 random arguments
23924584Szliu
24024584Szliu
24124584Szliu5. Speed.
24224584Szliu
24324652Szliu        Some functions coded in VAX assembly language (cabs(), hypot() and
24424652Szliu	sqrt()) are significantly faster than the corresponding ones in 4.2BSD.
24524652Szliu        In general, to improve performance, all functions in "IEEE/support.c"
24624652Szliu        should be written in assembly language and, whenever possible, should
24724652Szliu	be called via short subroutine calls.
24824584Szliu
24924584Szliu
25024715Selefunt6. j0, j1, jn.
25124584Szliu
25224584Szliu        The modifications to these routines were only in how an invalid
25324715Selefunt        floating point operations is signaled.
254