134126Sbostic /* 224602Szliu * Copyright (c) 1985 Regents of the University of California. 334126Sbostic * All rights reserved. 434126Sbostic * 534126Sbostic * Redistribution and use in source and binary forms are permitted 634931Sbostic * provided that the above copyright notice and this paragraph are 734931Sbostic * duplicated in all such forms and that any documentation, 834931Sbostic * advertising materials, and other materials related to such 934931Sbostic * distribution and use acknowledge that the software was developed 1034931Sbostic * by the University of California, Berkeley. The name of the 1134931Sbostic * University may not be used to endorse or promote products derived 1234931Sbostic * from this software without specific prior written permission. 1334931Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434931Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534931Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1634126Sbostic * 1734126Sbostic * All recipients should regard themselves as participants in an ongoing 1834126Sbostic * research project and hence should feel obligated to report their 1934126Sbostic * experiences (good or bad) with these elementary function codes, using 2034126Sbostic * the sendbug(8) program, to the authors. 2124602Szliu */ 2224602Szliu 2324602Szliu #ifndef lint 24*35679Sbostic static char sccsid[] = "@(#)log10.c 5.4 (Berkeley) 09/22/88"; 2534126Sbostic #endif /* not lint */ 2624602Szliu 2724602Szliu /* LOG10(X) 2824602Szliu * RETURN THE BASE 10 LOGARITHM OF x 2924602Szliu * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 3024602Szliu * CODED IN C BY K.C. NG, 1/20/85; 3124602Szliu * REVISED BY K.C. NG on 1/23/85, 3/7/85, 4/16/85. 3224602Szliu * 3324602Szliu * Required kernel function: 3424602Szliu * log(x) 3524602Szliu * 3624602Szliu * Method : 3724602Szliu * log(x) 3824602Szliu * log10(x) = --------- or [1/log(10)]*log(x) 3924602Szliu * log(10) 4024602Szliu * 4124602Szliu * Note: 4224602Szliu * [log(10)] rounded to 56 bits has error .0895 ulps, 4324602Szliu * [1/log(10)] rounded to 53 bits has error .198 ulps; 4424602Szliu * therefore, for better accuracy, in VAX D format, we divide 4524602Szliu * log(x) by log(10), but in IEEE Double format, we multiply 4624602Szliu * log(x) by [1/log(10)]. 4724602Szliu * 4824602Szliu * Special cases: 4924602Szliu * log10(x) is NaN with signal if x < 0; 5024602Szliu * log10(+INF) is +INF with no signal; log10(0) is -INF with signal; 5124602Szliu * log10(NaN) is that NaN with no signal. 5224602Szliu * 5324602Szliu * Accuracy: 5424602Szliu * log10(X) returns the exact log10(x) nearly rounded. In a test run 5524602Szliu * with 1,536,000 random arguments on a VAX, the maximum observed 5624602Szliu * error was 1.74 ulps (units in the last place). 5724602Szliu * 5824602Szliu * Constants: 5924602Szliu * The hexadecimal values are the intended ones for the following constants. 6024602Szliu * The decimal values may be used, provided that the compiler will convert 6124602Szliu * from decimal to binary accurately enough to produce the hexadecimal values 6224602Szliu * shown. 6324602Szliu */ 6424602Szliu 65*35679Sbostic #include "mathimpl.h" 6624602Szliu 67*35679Sbostic vc(ln10hi, 2.3025850929940456790E0 ,5d8d,4113,a8ac,ddaa, 2, .935D8DDDAAA8AC) 68*35679Sbostic 69*35679Sbostic ic(ivln10, 4.3429448190325181667E-1, -2, 1.BCB7B1526E50E) 70*35679Sbostic 71*35679Sbostic #ifdef vccast 72*35679Sbostic #define ln10hi vccast(ln10hi) 73*35679Sbostic #endif 74*35679Sbostic 75*35679Sbostic 7624602Szliu double log10(x) 7724602Szliu double x; 7824602Szliu { 7931853Szliu #if defined(vax)||defined(tahoe) 8024602Szliu return(log(x)/ln10hi); 8131853Szliu #else /* defined(vax)||defined(tahoe) */ 8224602Szliu return(ivln10*log(x)); 8331853Szliu #endif /* defined(vax)||defined(tahoe) */ 8424602Szliu } 85