date and time created 86/03/04 16:50:29 by elefunt
[unix-history] / usr / src / lib / libm / README.txt
CommitLineData
a62df508 1.\" @(#)README.txt 1.2 (ucb.elefunt) %G%
079afbd6
ZAL
2.\" troff -ms README.txt
3.de Pi
4.if n \
5pi
6.if t \
7\\(*p
8..
9.ND
10.ds CH
11.if t \
12.KS
13.IP \fB...\fR
14The machine-independent Version 7 math library found in 4.2BSD
15is now \*Q/usr/lib/libom.a\*U. To compile with those routines use \-lom.
16.LP
17.nf
18K.C. Ng, March 7, 1985, with Z-S. Alex Liu, S. McDonald, P. Tang, W. Kahan.
a62df508 19Revised on 5/10/85, 5/13/85, 6/14/85, 8/20/85, 8/27/85, 9/11/85.
079afbd6
ZAL
20.fi
21.if n \{\
22.LP
23.nf
24*******************************************************************************
25* This is a description of the upgraded elementary functions (listed in 1). *
26* Bessel functions (j0, j1, jn, y0, y1, yn), floor, and fabs passed over *
27* from 4.2BSD without change except perhaps for the way floating point *
28* exception is signaled on a VAX. Three lines that contain "errno" in erf.c *
29* (error function erf, erfc) have been deleted to prevent overriding the *
30* system "errno". *
31*******************************************************************************
32.fi \}
33.if t \{\
34.sp 0.5
35\fB\l'6i'\fR
36.QP
37\fIThis is a description of the upgraded elementary functions (listed in \fB\(sc1\fP).
38Bessel functions (j0, j1, jn, y0, y1, yn), floor, and fabs passed over
39from 4.2BSD without change except perhaps for the way floating point
40exception is signaled on a VAX. Three lines that contain \*Qerrno\*U in erf.c
41(the error functions erf, erfc) have been deleted to prevent overriding the
42system \*Qerrno\*U.
43.LP
44.sp -0.5
45\fB\l'6i'\fR
46.sp 0.5 \}
47.IP \fB\(sc0.\fR
48Total number of files: 40
49.sp 0.5
50.nf
51.ta +\w'IEEE/support.c'u+2n +\w'VAX/Makefile'u+2n +\w'VAX/support.s'u+2n +\w'exp__E.c'u+2n \w'log__L.c'u+2n
a62df508 52IEEE/Makefile VAX/Makefile VAX/support.s erf.c lgamma.c
079afbd6
ZAL
53IEEE/atan2.c VAX/argred.s VAX/tan.s exp.c log.c
54IEEE/cabs.c VAX/atan2.s acosh.c exp__E.c log10.c
55IEEE/cbrt.c VAX/cabs.s asincos.c expm1.c log1p.c
56IEEE/support.c VAX/cbrt.s asinh.c floor.c log__L.c
57IEEE/trig.c VAX/infnan.s atan.c j0.c pow.c
58Makefile VAX/sincos.s atanh.c j1.c sinh.c
59README VAX/sqrt.s cosh.c jn.c tanh.c
60.ta
61.fi
62.sp 0.5
63.IP \fB\(sc1.\fR
64Functions implemented:
65.RS
66.IP (A).
67Standard elementary functions (total 22):
68.nf
69.ta +\w'expm1(x):=exp(x)\-1'u+4n +\w'... in files'u+1n +\w'\0IEEE/atan2.c\0,'u+1n +\w'\0VAX/sincos.s\0'u+1n
70acos(x) ... in file \*Qasincos.c\*U
71asin(x) ... in file \*Qasincos.c\*U
72atan(x) ... in file \*Qatan.c\*U
73atan2(x,y) ... in files \*QIEEE/atan2.c\*U, \*QVAX/atan2.s\*U
74sin(x) ... in files \*QIEEE/trig.c\*U, \*QVAX/sincos.s\*U
75cos(x) ... in files \*QIEEE/trig.c\*U, \*QVAX/sincos.s\*U
76tan(x) ... in files \*QIEEE/trig.c\*U, \*QVAX/tan.s\*U
77cabs(x,y) ... in files \*QIEEE/cabs.c\*U, \*QVAX/cabs.s\*U
78hypot(x,y) ... in files \*QIEEE/cabs.c\*U, \*QVAX/cabs.s\*U
79cbrt(x) ... in files \*QIEEE/cbrt.c\*U, \*QVAX/cbrt.s\*U
80exp(x) ... in file \*Qexp.c\*U
81expm1(x):=exp(x)\-1 ... in file \*Qexpm1.c\*U
82log(x) ... in file \*Qlog.c\*U
83log10(x) ... in file \*Qlog10.c\*U
84log1p(x):=log(1+x) ... in file \*Qlog1p.c\*U
85pow(x,y) ... in file \*Qpow.c\*U
86sinh(x) ... in file \*Qsinh.c\*U
87cosh(x) ... in file \*Qcosh.c\*U
88tanh(x) ... in file \*Qtanh.c\*U
89asinh(x) ... in file \*Qasinh.c\*U
90acosh(x) ... in file \*Qacosh.c\*U
91atanh(x) ... in file \*Qatanh.c\*U
92.ta
93.fi
94.sp 0.25
95.IP (B).
96Kernel functions:
97.nf
98.ta +\w'libm$argred 'u+2n
99exp__E(x,c) ... in file \*Qexp__E.c\*U, used by expm1(), exp(), pow() and cosh()
100log__L(s) ... in file \*Qlog__L.c\*U, used by log1p(), log() and pow()
101libm$argred ... in file \*QVAX/argred.s\*U, used by VAX version of sin(), cos() and tan()
102.ta
103.fi
104.if t \{\
105.RE
106.KE
107.bp
108.KS
109.RS \}
110.if n \
111.sp 0.25
112.IP (C).
113System supported functions:
114.nf
115.ta +\w'copysign()'u+4n +\w'... in files'u+1n
116sqrt() ... in files \*QIEEE/support.c\*U, \*QVAX/sqrt.s\*U
117drem() ... in files \*QIEEE/support.c\*U, \*QVAX/support.s\*U
118finite() ... in files \*QIEEE/support.c\*U, \*QVAX/support.s\*U
119logb() ... in files \*QIEEE/support.c\*U, \*QVAX/support.s\*U
120scalb() ... in files \*QIEEE/support.c\*U, \*QVAX/support.s\*U
121copysign() ... in files \*QIEEE/support.c\*U, \*QVAX/support.s\*U
122rint() ... in file \*Qfloor.c\*U
123.ta
124.fi
125.sp 0.25
126.LP
127Notes:
128.IP \fBi\fR.
129The codes in files ending with \*Q.s\*U are written in VAX assembly
130language. They are intended for VAX computers.
131.IP
132Files that end with \*Q.c\*U are written in C. They are intended
133for either a VAX or a machine that conforms to the IEEE
134standard 754 for double precision floating-point arithmetic.
135.IP \fBii\fR.
136On other than VAX or IEEE machines, run the original math
137library, formerly \*Q/usr/lib/libm.a\*U, now \*Q/usr/lib/libom.a\*U,
138if nothing better is available.
139.IP \fBiii\fR.
140The trigonometric functions sin(), cos(), tan() and atan2() in files
141\*QVAX/sincos.s\*U, \*QVAX/tan.s\*U and \*QVAX/atan2.s\*U are different
142from those in \*QIEEE/trig.c\*U and \*QIEEE/atan2.c\*U.
143The VAX assembler code uses the true value of
144.Pi
145to perform argument reduction, while the C code uses
146the machine's value of PI rounded (see \*QIEEE/trig.c\*U).
147.RE
148.sp 0.5
149.IP \fB\(sc2.\fR
150A computer system that conforms to IEEE standard 754 should provide
151.LP
152.RS
153.RS
154.nf
155sqrt(x),
156drem(x,p), (double precision remainder function)
157copysign(x,y),
158finite(x),
159scalb(x,N),
160logb(x) and
161rint(x).
162.fi
163.RE
164.LP
165These functions are either required or recommended by the standard.
166.LP
167For convenience, a (slow) C implementation of these functions is
168provided in the file \*QIEEE/support.c\*U.
169.LP
170\fBWarning\fR: The functions in \*QIEEE/support.c\*U are somewhat machine
171dependent.
172Some modifications may be necessary to run them on a different machine.
173Currently, if compiled with a suitable flag, \*QIEEE/support.c\*U will work
174on a National 32000, a Zilog 8000, a VAX, and a SUN (cf. the \*QMakefile\*U in
175this directory). Invoke the C compiler thus:
176.RS
177.nf
178.ta +\w'cc \-c \-DNATIONAL IEEE/support.c'u+4n +\w'...'u+1n
179cc \-c \-DVAX IEEE/support.c ... on a VAX, D-format
180cc \-c \-DNATIONAL IEEE/support.c ... on a National 32000
181cc \-c IEEE/support.c ... on other IEEE machines, we hope.
182.ta
183.fi
184.RE
185.LP
186Notes:
187.IP \fBi\fR.
188Faster versions of drem() and sqrt() for IEEE double precision
189(coded in C but intended for assembly language) are given at the
190end of \*QIEEE/support.c\*U but commented out since they require certain
191machine-dependent functions.
192.IP \fBii\fR.
193A fast VAX assembler version of the system supported functions
194copysign(), logb(), scalb(), finite(), and drem() appears in file
195\*QVAX/support.s\*U. A fast VAX assembler version of sqrt() is in
196file \*QVAX/sqrt.s\*U.
197.RE
198.if n \
199.sp
200.if t \{\
201.RE
202.KE
203.bp
204.KS \}
205.IP \fB\(sc3.\fR
206Two formats are supported by all the standard elementary functions:
207.RS
208.LP
209the VAX D-format (56-bit precision), and the IEEE double format
210(53-bit precision). The cbrt() in \*QIEEE/cbrt.c\*U is for IEEE machines
211only. The functions in files that end with \*Q.s\*U are for VAX computers
212only. The functions in files that end with \*Q.c\*U (except \*QIEEE/cbrt.c\*U)
213are for VAX and IEEE machines. To use the VAX D-format, compile the code
214with \-DVAX; to use IEEE double format on various IEEE machines, see
215\*QMakefile\*U in this directory).
216.LP
217Example:
218.RS
219.nf
220cc \-c \-DVAX sin.c ... for VAX D-format
221.fi
222.RE
223.sp 0.25
224.LP
225\fBWarning\fR:
226The values of floating-point constants used in the code are
227given in both hexadecimal and decimal. The hexadecimal values
228are the intended ones. The decimal values may be used provided
229that the compiler converts from decimal to binary accurately
230enough to produce the hexadecimal values shown. If the
231conversion is inaccurate, then one must know the exact machine
232representation of the constants and alter the
233assembly-language output from the compiler, or play tricks like
234the following in a C program.
235.sp 0.25
236.RS
237Example: to store the floating-point constant
238.sp 0.25
239.RS
240.if n \
241p1 = 2**\-6 \(** .F83ABE67E1066A (hexadecimal)
242.if t \
243p1 = 2\u\s-2\-6\s+2\d \(** .F83ABE67E1066A (hexadecimal)
244.RE
245on a VAX in C, we use two longwords to store its
246machine value and define p1 to be the double constant
247at the location of these two longwords:
248.sp 0.25
249.nf
250.ta +\w'static long'u+1n +\w'p1x[] ='u+1n
251static long p1x[] = {0x3abe3d78, 0x066a67e1};
252#define p1 (\(**(double\(**)p1x)
253.ta
254.fi
255.RE
256.IP Note: \w'Note:'u
257\0On a VAX, some functions have two codes. For example, cabs()
258has one implementation in \*QIEEE/cabs.c\*U, and the other in
259\*QVAX/cabs.s\*U.
260In this case, the assembly language version is preferred.
261.RE
262.sp 0.5
263.IP \fB\(sc4.\fR
264Accuracy.
265.RS
266.LP
267The errors in expm1(), log1p(), exp(), log(), cabs(), hypot()
268and cbrt() are below 1 ULP (Unit in the Last Place).
269.LP
270The error in pow(x,y) grows with the size of y. Nevertheless,
271for integers x and y, pow(x,y) returns the correct integer value
272on all tested machines (VAX, SUN, National 32000, Zilog 8000), provided that
273x to the power of y is representable exactly.
274.LP
275cosh(), sinh(), acosh(), asinh(), tanh(), atanh() and log10() have errors
276below about 3 ULPs.
277.LP
278For trigonometric and inverse trigonometric functions,
279let [trig(x)] denote the value actually computed for trig(x).
280.IP 1)
281Those codes using PI, the machine's value of
282.Pi
283rounded):
284.nf
285(in files \*QIEEE/trig.c\*U, \*QIEEE/atan2.c\*U, \*Qasincos.c\*U and \*Qatan.c\*U.)
286.fi
287.IP
288The errors in [sin(x)], [cos(x)], and [atan(x)] are below
2891 ULP compared with
290.if n \
291sin(x\(**pi/PI), cos(x\(**pi/PI), and atan(x)\(**PI/pi
292.if t \
293sin(x\(**\(*p/PI), cos(x\(**\(*p/PI), and atan(x)\(**PI/\(*p
294respectively, where PI is the machine's
295value of
296.Pi
297rounded. [tan(x)] returns
298.if n \
299tan(x\(**pi/PI)
300.if t \
301tan(x\(**\(*p/PI)
302within about 2 ULPs; [acos(x)], [asin(x)], and [atan2(y,x)] return
303.if n \
304acos(x)\(**PI/pi, asin(x)\(**PI/pi, and atan2(y,x)\(**PI/pi
305.if t \
306acos(x)\(**PI/\(*p, asin(x)\(**PI/\(*p, and atan2(y,x)\(**PI/\(*p
307respectively to similar accuracy.
308.IP 2)
309Those using true
310.Pi
311(for VAX D-format only):
312.br
313.nf
314(in files \*QVAX/sincos.s\*U, \*QVAX/tan.s\*U, \*QVAX/atan2.s\*U, \*Qasincos.c\*U and \*Qatan.c\*U.)
315.fi
316.IP
317The errors in [sin(x)], [cos(x)], and [atan(x)] are below
3181 ULP. [tan(x)], [atan2(y,x)], [acos(x)] and [asin(x)]
319have errors below about 2 ULPs.
320.RE
321.if t \{\
322.KE
323.bp
324.KS \}
325.IP
326Here are the results of some test runs to find worst errors on a VAX:
327.nf
328.ta +\w'expm1'u+1n +\w':'u+2n +\w'2.09'u+1n +\w'ULPs'u+4n +\w'... 1,024,000'uR +1n
329.sp 0.25
330tan : 2.09 ULPs ... 1,024,000 random arguments (machine PI)
331sin : .861 ULPs ... 1,024,000 random arguments (machine PI)
332cos : .857 ULPs ... 1,024,000 random arguments (machine PI)
333.if n \
334(compared with tan, sin, cos of (x\(**pi/PI))
335.if t \
336 (compared with tan, sin, cos of (x\(**\(*p/PI))
337.sp 0.25
338atan : 0.86 ULPs ... 1,536,000 random arguments (machine PI)
339asin : 2.06 ULPs ... 200,000 random arguments (machine PI)
340acos : 2.07 ULPs ... 200,000 random arguments (machine PI)
341atan2 : 1.41 ULPs ... 356,000 random arguments (machine PI)
342.if n \
343(compared with (PI/pi)\(**(atan, asin, acos, atan2 of x))
344.if t \
345 (compared with (PI/\(*p)\(**(atan, asin, acos, atan2 of x))
346.sp 0.25
347.if n \
348tan : 2.15 ULPs ... 1,024,000 random arguments (true pi)
349.if t \
350tan : 2.15 ULPs ... 1,024,000 random arguments (true \(*p)
351.if n \
352sin : .814 ULPs ... 1,024,000 random arguments (true pi)
353.if t \
354sin : .814 ULPs ... 1,024,000 random arguments (true \(*p)
355.if n \
356cos : .792 ULPs ... 1,024,000 random arguments (true pi)
357.if t \
358cos : .792 ULPs ... 1,024,000 random arguments (true \(*p)
359.if n \
360acos : 2.15 ULPs ... 1,024,000 random arguments (true pi)
361.if t \
362acos : 2.15 ULPs ... 1,024,000 random arguments (true \(*p)
363.if n \
364asin : 1.99 ULPs ... 1,024,000 random arguments (true pi)
365.if t \
366asin : 1.99 ULPs ... 1,024,000 random arguments (true \(*p)
367.if n \
368atan2 : 1.48 ULPs ... 1,024,000 random arguments (true pi)
369.if t \
370atan2 : 1.48 ULPs ... 1,024,000 random arguments (true \(*p)
371.if n \
372atan : .850 ULPs ... 1,024,000 random arguments (true pi)
373.if n \
374atan : .850 ULPs ... 1,024,000 random arguments (true \(*p)
375.sp 0.25
376acosh : 3.30 ULPs ... 512,000 random arguments
377asinh : 1.58 ULPs ... 512,000 random arguments
378atanh : 1.71 ULPs ... 512,000 random arguments
379cosh : 1.23 ULPs ... 768,000 random arguments
380sinh : 1.93 ULPs ... 1,024,000 random arguments
381tanh : 2.22 ULPs ... 1,024,000 random arguments
382log10 : 1.74 ULPs ... 1,536,000 random arguments
383pow : 1.79 ULPs ... 100,000 random arguments, 0 < x, y < 20.
384.sp 0.25
385exp : .768 ULPs ... 1,156,000 random arguments
386expm1 : .844 ULPs ... 1,166,000 random arguments
387log1p : .846 ULPs ... 1,536,000 random arguments
388log : .826 ULPs ... 1,536,000 random arguments
389cabs : .959 ULPs ... 500,000 random arguments
390cbrt : .666 ULPs ... 5,120,000 random arguments
391.ta
392.fi
393.sp 0.5
394.IP \fB\(sc5.\fR
395Speed.
396.IP
397Some functions coded in VAX assembly language (cabs(), hypot() and sqrt())
398are significantly faster than the corresponding ones in 4.2BSD.
399In general, to improve performance, all functions in \*QIEEE/support.c\*U
400should be written in assembly language and, whenever possible, should be
401called via short subroutine calls.
402.sp 0.5
403.IP \fB\(sc6.\fR
404j0, j1, jn.
405.IP
406The modifications to these routines were only in how an invalid
407floating point operation is signaled on a VAX.
408.sp 0.5
409.if n \
410.KS
411.LP
412.nf
413\fB\(sc7.\fR Copyright notice, and Disclaimer:
414.fi
415.if n \{\
416.LP
417.nf
418***************************************************************************
419* *
420* Copyright (c) 1985 Regents of the University of California. *
421* *
422* Use and reproduction of this software are granted in accordance with *
423* the terms and conditions specified in the Berkeley Software License *
424* Agreement (in particular, this entails acknowledgement of the programs' *
425* source, and inclusion of this notice) with the additional understanding *
426* that all recipients should regard themselves as participants in an *
427* ongoing research project and hence should feel obligated to report *
428* their experiences (good or bad) with these elementary function codes, *
429* using "sendbug 4bsd-bugs@BERKELEY", to the authors. *
430* *
431***************************************************************************
432.fi \}
433.if t \{\
434.sp 0.25
435\fB\l'6i'\fR
436.QP
437\fICopyright (c) 1985 Regents of the University of California.\fR
438.QP
439\fIUse and reproduction of this software are granted in accordance with
440the terms and conditions specified in the Berkeley Software License
441Agreement (in particular, this entails acknowledgement of the programs'
442source, and inclusion of this notice) with the additional understanding
443that all recipients should regard themselves as participants in an
444ongoing research project and hence should feel obligated to report
445their experiences (good or bad) with these elementary function codes,
446using \*Qsendbug 4bsd-bugs@BERKELEY\*U, to the authors.\fR
447.LP
448.sp -0.5
449\fB\l'6i'\fR \}
450.KE