e_log2.c (226376) | e_log2.c (251024) |
---|---|
1 2/* @(#)e_log10.c 1.3 95/01/18 */ 3/* 4 * ==================================================== 5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 * 7 * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 * Permission to use, copy, modify, and distribute this 9 * software is freely granted, provided that this notice 10 * is preserved. 11 * ==================================================== 12 */ 13 14#include <sys/cdefs.h> | 1 2/* @(#)e_log10.c 1.3 95/01/18 */ 3/* 4 * ==================================================== 5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 * 7 * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 * Permission to use, copy, modify, and distribute this 9 * software is freely granted, provided that this notice 10 * is preserved. 11 * ==================================================== 12 */ 13 14#include <sys/cdefs.h> |
15__FBSDID("$FreeBSD: head/lib/msun/src/e_log2.c 226376 2011-10-15 05:23:28Z das $"); | 15__FBSDID("$FreeBSD: head/lib/msun/src/e_log2.c 251024 2013-05-27 08:50:10Z das $"); |
16 17/* 18 * Return the base 2 logarithm of x. See e_log.c and k_log.h for most 19 * comments. 20 * 21 * This reduces x to {k, 1+f} exactly as in e_log.c, then calls the kernel, 22 * then does the combining and scaling steps 23 * log2(x) = (f - 0.5*f*f + k_log1p(f)) / ln2 + k --- 5 unchanged lines hidden (view full) --- 29#include "k_log.h" 30 31static const double 32two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ 33ivln2hi = 1.44269504072144627571e+00, /* 0x3ff71547, 0x65200000 */ 34ivln2lo = 1.67517131648865118353e-10; /* 0x3de705fc, 0x2eefa200 */ 35 36static const double zero = 0.0; | 16 17/* 18 * Return the base 2 logarithm of x. See e_log.c and k_log.h for most 19 * comments. 20 * 21 * This reduces x to {k, 1+f} exactly as in e_log.c, then calls the kernel, 22 * then does the combining and scaling steps 23 * log2(x) = (f - 0.5*f*f + k_log1p(f)) / ln2 + k --- 5 unchanged lines hidden (view full) --- 29#include "k_log.h" 30 31static const double 32two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ 33ivln2hi = 1.44269504072144627571e+00, /* 0x3ff71547, 0x65200000 */ 34ivln2lo = 1.67517131648865118353e-10; /* 0x3de705fc, 0x2eefa200 */ 35 36static const double zero = 0.0; |
37static volatile double vzero = 0.0; |
|
37 38double 39__ieee754_log2(double x) 40{ 41 double f,hfsq,hi,lo,r,val_hi,val_lo,w,y; 42 int32_t i,k,hx; 43 u_int32_t lx; 44 45 EXTRACT_WORDS(hx,lx,x); 46 47 k=0; 48 if (hx < 0x00100000) { /* x < 2**-1022 */ 49 if (((hx&0x7fffffff)|lx)==0) | 38 39double 40__ieee754_log2(double x) 41{ 42 double f,hfsq,hi,lo,r,val_hi,val_lo,w,y; 43 int32_t i,k,hx; 44 u_int32_t lx; 45 46 EXTRACT_WORDS(hx,lx,x); 47 48 k=0; 49 if (hx < 0x00100000) { /* x < 2**-1022 */ 50 if (((hx&0x7fffffff)|lx)==0) |
50 return -two54/zero; /* log(+-0)=-inf */ | 51 return -two54/vzero; /* log(+-0)=-inf */ |
51 if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ 52 k -= 54; x *= two54; /* subnormal number, scale up x */ 53 GET_HIGH_WORD(hx,x); 54 } 55 if (hx >= 0x7ff00000) return x+x; 56 if (hx == 0x3ff00000 && lx == 0) 57 return zero; /* log(1) = +0 */ 58 k += (hx>>20)-1023; --- 52 unchanged lines hidden --- | 52 if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ 53 k -= 54; x *= two54; /* subnormal number, scale up x */ 54 GET_HIGH_WORD(hx,x); 55 } 56 if (hx >= 0x7ff00000) return x+x; 57 if (hx == 0x3ff00000 && lx == 0) 58 return zero; /* log(1) = +0 */ 59 k += (hx>>20)-1023; --- 52 unchanged lines hidden --- |