xref: /original-bsd/lib/libm/common_source/log10.c (revision f0203ecd)
1 /*
2  * Copyright (c) 1985 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  * All recipients should regard themselves as participants in an ongoing
8  * research project and hence should feel obligated to report their
9  * experiences (good or bad) with these elementary function codes, using
10  * the sendbug(8) program, to the authors.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)log10.c	5.5 (Berkeley) 06/01/90";
15 #endif /* not lint */
16 
17 /* LOG10(X)
18  * RETURN THE BASE 10 LOGARITHM OF x
19  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
20  * CODED IN C BY K.C. NG, 1/20/85;
21  * REVISED BY K.C. NG on 1/23/85, 3/7/85, 4/16/85.
22  *
23  * Required kernel function:
24  *	log(x)
25  *
26  * Method :
27  *			     log(x)
28  *		log10(x) = ---------  or  [1/log(10)]*log(x)
29  *			    log(10)
30  *
31  *    Note:
32  *	  [log(10)]   rounded to 56 bits has error  .0895  ulps,
33  *	  [1/log(10)] rounded to 53 bits has error  .198   ulps;
34  *	  therefore, for better accuracy, in VAX D format, we divide
35  *	  log(x) by log(10), but in IEEE Double format, we multiply
36  *	  log(x) by [1/log(10)].
37  *
38  * Special cases:
39  *	log10(x) is NaN with signal if x < 0;
40  *	log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
41  *	log10(NaN) is that NaN with no signal.
42  *
43  * Accuracy:
44  *	log10(X) returns the exact log10(x) nearly rounded. In a test run
45  *	with 1,536,000 random arguments on a VAX, the maximum observed
46  *	error was 1.74 ulps (units in the last place).
47  *
48  * Constants:
49  * The hexadecimal values are the intended ones for the following constants.
50  * The decimal values may be used, provided that the compiler will convert
51  * from decimal to binary accurately enough to produce the hexadecimal values
52  * shown.
53  */
54 
55 #include "mathimpl.h"
56 
57 vc(ln10hi, 2.3025850929940456790E0 ,5d8d,4113,a8ac,ddaa, 2, .935D8DDDAAA8AC)
58 
59 ic(ivln10, 4.3429448190325181667E-1, -2, 1.BCB7B1526E50E)
60 
61 #ifdef vccast
62 #define	ln10hi	vccast(ln10hi)
63 #endif
64 
65 
66 double log10(x)
67 double x;
68 {
69 #if defined(vax)||defined(tahoe)
70 	return(log(x)/ln10hi);
71 #else	/* defined(vax)||defined(tahoe) */
72 	return(ivln10*log(x));
73 #endif	/* defined(vax)||defined(tahoe) */
74 }
75