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