Back to index

glibc  2.9
e_log10f.c
Go to the documentation of this file.
00001 /* e_log10f.c -- float version of e_log10.c.
00002  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: e_log10f.c,v 1.5 1995/05/10 20:45:53 jtc Exp $";
00018 #endif
00019 
00020 #include "math.h"
00021 #include "math_private.h"
00022 
00023 #ifdef __STDC__
00024 static const float
00025 #else
00026 static float
00027 #endif
00028 two25      =  3.3554432000e+07, /* 0x4c000000 */
00029 ivln10     =  4.3429449201e-01, /* 0x3ede5bd9 */
00030 log10_2hi  =  3.0102920532e-01, /* 0x3e9a2080 */
00031 log10_2lo  =  7.9034151668e-07; /* 0x355427db */
00032 
00033 #ifdef __STDC__
00034 static const float zero   =  0.0;
00035 #else
00036 static float zero   =  0.0;
00037 #endif
00038 
00039 #ifdef __STDC__
00040        float __ieee754_log10f(float x)
00041 #else
00042        float __ieee754_log10f(x)
00043        float x;
00044 #endif
00045 {
00046        float y,z;
00047        int32_t i,k,hx;
00048 
00049        GET_FLOAT_WORD(hx,x);
00050 
00051         k=0;
00052         if (hx < 0x00800000) {                   /* x < 2**-126  */
00053             if ((hx&0x7fffffff)==0)
00054                 return -two25/(x-x);             /* log(+-0)=-inf */
00055             if (hx<0) return (x-x)/(x-x); /* log(-#) = NaN */
00056             k -= 25; x *= two25; /* subnormal number, scale up x */
00057            GET_FLOAT_WORD(hx,x);
00058         }
00059        if (hx >= 0x7f800000) return x+x;
00060        k += (hx>>23)-127;
00061        i  = ((u_int32_t)k&0x80000000)>>31;
00062         hx = (hx&0x007fffff)|((0x7f-i)<<23);
00063         y  = (float)(k+i);
00064        SET_FLOAT_WORD(x,hx);
00065        z  = y*log10_2lo + ivln10*__ieee754_logf(x);
00066        return  z+y*log10_2hi;
00067 }