xref: /csrg-svn/lib/libm/common_source/log10.c (revision 61309)
134126Sbostic /*
2*61309Sbostic  * Copyright (c) 1985, 1993
3*61309Sbostic  *	The Regents of the University of California.  All rights reserved.
434126Sbostic  *
542657Sbostic  * %sccs.include.redist.c%
624602Szliu  */
724602Szliu 
824602Szliu #ifndef lint
9*61309Sbostic static char sccsid[] = "@(#)log10.c	8.1 (Berkeley) 06/04/93";
1034126Sbostic #endif /* not lint */
1124602Szliu 
1224602Szliu /* LOG10(X)
1324602Szliu  * RETURN THE BASE 10 LOGARITHM OF x
1424602Szliu  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
1524602Szliu  * CODED IN C BY K.C. NG, 1/20/85;
1624602Szliu  * REVISED BY K.C. NG on 1/23/85, 3/7/85, 4/16/85.
1724602Szliu  *
1824602Szliu  * Required kernel function:
1924602Szliu  *	log(x)
2024602Szliu  *
2124602Szliu  * Method :
2224602Szliu  *			     log(x)
2324602Szliu  *		log10(x) = ---------  or  [1/log(10)]*log(x)
2424602Szliu  *			    log(10)
2524602Szliu  *
2624602Szliu  *    Note:
2724602Szliu  *	  [log(10)]   rounded to 56 bits has error  .0895  ulps,
2824602Szliu  *	  [1/log(10)] rounded to 53 bits has error  .198   ulps;
2924602Szliu  *	  therefore, for better accuracy, in VAX D format, we divide
3024602Szliu  *	  log(x) by log(10), but in IEEE Double format, we multiply
3124602Szliu  *	  log(x) by [1/log(10)].
3224602Szliu  *
3324602Szliu  * Special cases:
3424602Szliu  *	log10(x) is NaN with signal if x < 0;
3524602Szliu  *	log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
3624602Szliu  *	log10(NaN) is that NaN with no signal.
3724602Szliu  *
3824602Szliu  * Accuracy:
3924602Szliu  *	log10(X) returns the exact log10(x) nearly rounded. In a test run
4024602Szliu  *	with 1,536,000 random arguments on a VAX, the maximum observed
4124602Szliu  *	error was 1.74 ulps (units in the last place).
4224602Szliu  *
4324602Szliu  * Constants:
4424602Szliu  * The hexadecimal values are the intended ones for the following constants.
4524602Szliu  * The decimal values may be used, provided that the compiler will convert
4624602Szliu  * from decimal to binary accurately enough to produce the hexadecimal values
4724602Szliu  * shown.
4824602Szliu  */
4924602Szliu 
5035679Sbostic #include "mathimpl.h"
5124602Szliu 
5235679Sbostic vc(ln10hi, 2.3025850929940456790E0 ,5d8d,4113,a8ac,ddaa, 2, .935D8DDDAAA8AC)
5335679Sbostic 
5435679Sbostic ic(ivln10, 4.3429448190325181667E-1, -2, 1.BCB7B1526E50E)
5535679Sbostic 
5635679Sbostic #ifdef vccast
5735679Sbostic #define	ln10hi	vccast(ln10hi)
5835679Sbostic #endif
5935679Sbostic 
6035679Sbostic 
6124602Szliu double log10(x)
6224602Szliu double x;
6324602Szliu {
6431853Szliu #if defined(vax)||defined(tahoe)
6524602Szliu 	return(log(x)/ln10hi);
6631853Szliu #else	/* defined(vax)||defined(tahoe) */
6724602Szliu 	return(ivln10*log(x));
6831853Szliu #endif	/* defined(vax)||defined(tahoe) */
6924602Szliu }
70