xref: /csrg-svn/lib/libm/common_source/log10.c (revision 42657)
134126Sbostic /*
224602Szliu  * Copyright (c) 1985 Regents of the University of California.
334126Sbostic  * All rights reserved.
434126Sbostic  *
5*42657Sbostic  * %sccs.include.redist.c%
634126Sbostic  *
734126Sbostic  * All recipients should regard themselves as participants in an ongoing
834126Sbostic  * research project and hence should feel obligated to report their
934126Sbostic  * experiences (good or bad) with these elementary function codes, using
1034126Sbostic  * the sendbug(8) program, to the authors.
1124602Szliu  */
1224602Szliu 
1324602Szliu #ifndef lint
14*42657Sbostic static char sccsid[] = "@(#)log10.c	5.5 (Berkeley) 06/01/90";
1534126Sbostic #endif /* not lint */
1624602Szliu 
1724602Szliu /* LOG10(X)
1824602Szliu  * RETURN THE BASE 10 LOGARITHM OF x
1924602Szliu  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
2024602Szliu  * CODED IN C BY K.C. NG, 1/20/85;
2124602Szliu  * REVISED BY K.C. NG on 1/23/85, 3/7/85, 4/16/85.
2224602Szliu  *
2324602Szliu  * Required kernel function:
2424602Szliu  *	log(x)
2524602Szliu  *
2624602Szliu  * Method :
2724602Szliu  *			     log(x)
2824602Szliu  *		log10(x) = ---------  or  [1/log(10)]*log(x)
2924602Szliu  *			    log(10)
3024602Szliu  *
3124602Szliu  *    Note:
3224602Szliu  *	  [log(10)]   rounded to 56 bits has error  .0895  ulps,
3324602Szliu  *	  [1/log(10)] rounded to 53 bits has error  .198   ulps;
3424602Szliu  *	  therefore, for better accuracy, in VAX D format, we divide
3524602Szliu  *	  log(x) by log(10), but in IEEE Double format, we multiply
3624602Szliu  *	  log(x) by [1/log(10)].
3724602Szliu  *
3824602Szliu  * Special cases:
3924602Szliu  *	log10(x) is NaN with signal if x < 0;
4024602Szliu  *	log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
4124602Szliu  *	log10(NaN) is that NaN with no signal.
4224602Szliu  *
4324602Szliu  * Accuracy:
4424602Szliu  *	log10(X) returns the exact log10(x) nearly rounded. In a test run
4524602Szliu  *	with 1,536,000 random arguments on a VAX, the maximum observed
4624602Szliu  *	error was 1.74 ulps (units in the last place).
4724602Szliu  *
4824602Szliu  * Constants:
4924602Szliu  * The hexadecimal values are the intended ones for the following constants.
5024602Szliu  * The decimal values may be used, provided that the compiler will convert
5124602Szliu  * from decimal to binary accurately enough to produce the hexadecimal values
5224602Szliu  * shown.
5324602Szliu  */
5424602Szliu 
5535679Sbostic #include "mathimpl.h"
5624602Szliu 
5735679Sbostic vc(ln10hi, 2.3025850929940456790E0 ,5d8d,4113,a8ac,ddaa, 2, .935D8DDDAAA8AC)
5835679Sbostic 
5935679Sbostic ic(ivln10, 4.3429448190325181667E-1, -2, 1.BCB7B1526E50E)
6035679Sbostic 
6135679Sbostic #ifdef vccast
6235679Sbostic #define	ln10hi	vccast(ln10hi)
6335679Sbostic #endif
6435679Sbostic 
6535679Sbostic 
6624602Szliu double log10(x)
6724602Szliu double x;
6824602Szliu {
6931853Szliu #if defined(vax)||defined(tahoe)
7024602Szliu 	return(log(x)/ln10hi);
7131853Szliu #else	/* defined(vax)||defined(tahoe) */
7224602Szliu 	return(ivln10*log(x));
7331853Szliu #endif	/* defined(vax)||defined(tahoe) */
7424602Szliu }
75