e_log10f.c revision 219361
167754Smsmith/*
267754Smsmith * ====================================================
367754Smsmith * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
467754Smsmith *
567754Smsmith * Developed at SunPro, a Sun Microsystems, Inc. business.
667754Smsmith * Permission to use, copy, modify, and distribute this
7217365Sjkim * software is freely granted, provided that this notice
8298714Sjkim * is preserved.
970243Smsmith * ====================================================
1067754Smsmith */
11217365Sjkim
12217365Sjkim#include <sys/cdefs.h>
13217365Sjkim__FBSDID("$FreeBSD: head/lib/msun/src/e_log10f.c 219361 2011-03-07 03:12:08Z das $");
14217365Sjkim
15217365Sjkim/*
16217365Sjkim * Return the base 10 logarithm of x. See k_log.c for details on the algorithm.
17217365Sjkim */
18217365Sjkim
19217365Sjkim#include "math.h"
20217365Sjkim#include "math_private.h"
21217365Sjkim#include "k_logf.h"
22217365Sjkim
23217365Sjkimstatic const float
24217365Sjkimtwo25      =  3.3554432000e+07, /* 0x4c000000 */
2567754Smsmithivln10hi   =  4.3432617188e-01, /* 0x3ede6000 */
26217365Sjkimivln10lo   = -3.1689971365e-05, /* 0xb804ead9 */
27217365Sjkimlog10_2hi  =  3.0102920532e-01, /* 0x3e9a2080 */
28217365Sjkimlog10_2lo  =  7.9034151668e-07; /* 0x355427db */
2967754Smsmith
30217365Sjkimstatic const float zero   =  0.0;
31217365Sjkim
32217365Sjkimfloat
33217365Sjkim__ieee754_log10f(float x)
34217365Sjkim{
35217365Sjkim	float f,hi,lo,y,z;
36217365Sjkim	int32_t i,k,hx;
37217365Sjkim
38217365Sjkim	GET_FLOAT_WORD(hx,x);
39217365Sjkim
40217365Sjkim        k=0;
41217365Sjkim        if (hx < 0x00800000) {                  /* x < 2**-126  */
42217365Sjkim            if ((hx&0x7fffffff)==0)
4367754Smsmith                return -two25/zero;             /* log(+-0)=-inf */
44193341Sjkim            if (hx<0) return (x-x)/zero;        /* log(-#) = NaN */
45193341Sjkim            k -= 25; x *= two25; /* subnormal number, scale up x */
46193341Sjkim	    GET_FLOAT_WORD(hx,x);
4767754Smsmith        }
4877424Smsmith	if (hx >= 0x7f800000) return x+x;
4991116Smsmith	k += (hx>>23)-127;
5067754Smsmith	hx &= 0x007fffff;
51231844Sjkim	i = (hx+(0x4afb0d))&0x800000;
52231844Sjkim	SET_FLOAT_WORD(x,hx|(i^0x3f800000));	/* normalize x or x/2 */
53151937Sjkim	k += (i>>23);
5467754Smsmith	y = (float)k;
55151937Sjkim	f = __kernel_logf(x);
56151937Sjkim	x = x - (float)1.0;
57151937Sjkim	GET_FLOAT_WORD(hx,x);
58193267Sjkim	SET_FLOAT_WORD(hi,hx&0xfffff000);
59193267Sjkim	lo = x - hi;
60151937Sjkim	z = y*log10_2lo + (x+f)*ivln10lo + (lo+f)*ivln10hi + hi*ivln10hi;
61278970Sjkim	return  z+y*log10_2hi;
62278970Sjkim}
63278970Sjkim