e_log10f.c revision 226375
155714Skris/* 255714Skris * ==================================================== 355714Skris * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 455714Skris * 555714Skris * Developed at SunPro, a Sun Microsystems, Inc. business. 655714Skris * Permission to use, copy, modify, and distribute this 755714Skris * software is freely granted, provided that this notice 855714Skris * is preserved. 955714Skris * ==================================================== 1055714Skris */ 1155714Skris 1255714Skris#include <sys/cdefs.h> 1355714Skris__FBSDID("$FreeBSD: head/lib/msun/src/e_log10f.c 226375 2011-10-15 05:00:56Z das $"); 1455714Skris 1555714Skris/* 1655714Skris * Float version of e_log10.c. See the latter for most comments. 1755714Skris */ 1855714Skris 1955714Skris#include "math.h" 2055714Skris#include "math_private.h" 2155714Skris#include "k_logf.h" 2255714Skris 2355714Skrisstatic const float 2455714Skristwo25 = 3.3554432000e+07, /* 0x4c000000 */ 2555714Skrisivln10hi = 4.3432617188e-01, /* 0x3ede6000 */ 2655714Skrisivln10lo = -3.1689971365e-05, /* 0xb804ead9 */ 2755714Skrislog10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ 2855714Skrislog10_2lo = 7.9034151668e-07; /* 0x355427db */ 2955714Skris 3055714Skrisstatic const float zero = 0.0; 3155714Skris 3255714Skrisfloat 3355714Skris__ieee754_log10f(float x) 3455714Skris{ 3555714Skris float f,hi,lo,y,z; 3655714Skris int32_t i,k,hx; 3755714Skris 3855714Skris GET_FLOAT_WORD(hx,x); 3955714Skris 4055714Skris k=0; 4155714Skris if (hx < 0x00800000) { /* x < 2**-126 */ 4255714Skris if ((hx&0x7fffffff)==0) 4355714Skris return -two25/zero; /* log(+-0)=-inf */ 4455714Skris if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ 4555714Skris k -= 25; x *= two25; /* subnormal number, scale up x */ 4655714Skris GET_FLOAT_WORD(hx,x); 4755714Skris } 4855714Skris if (hx >= 0x7f800000) return x+x; 4955714Skris k += (hx>>23)-127; 5055714Skris hx &= 0x007fffff; 5155714Skris i = (hx+(0x4afb0d))&0x800000; 5255714Skris SET_FLOAT_WORD(x,hx|(i^0x3f800000)); /* normalize x or x/2 */ 5355714Skris k += (i>>23); 5455714Skris y = (float)k; 5555714Skris f = __kernel_logf(x); 5655714Skris x = x - (float)1.0; 5755714Skris GET_FLOAT_WORD(hx,x); 5855714Skris SET_FLOAT_WORD(hi,hx&0xfffff000); 5955714Skris lo = x - hi; 6055714Skris z = y*log10_2lo + (x+f)*ivln10lo + (lo+f)*ivln10hi + hi*ivln10hi; 6155714Skris return z+y*log10_2hi; 6255714Skris} 6355714Skris