s_logb.c revision 2116
12116Sjkh/* @(#)s_logb.c 5.1 93/09/24 */ 22116Sjkh/* 32116Sjkh * ==================================================== 42116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 52116Sjkh * 62116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 72116Sjkh * Permission to use, copy, modify, and distribute this 82116Sjkh * software is freely granted, provided that this notice 92116Sjkh * is preserved. 102116Sjkh * ==================================================== 112116Sjkh */ 122116Sjkh 132116Sjkh#ifndef lint 142116Sjkhstatic char rcsid[] = "$Id: s_logb.c,v 1.6 1994/08/18 23:07:04 jtc Exp $"; 152116Sjkh#endif 162116Sjkh 172116Sjkh/* 182116Sjkh * double logb(x) 192116Sjkh * IEEE 754 logb. Included to pass IEEE test suite. Not recommend. 202116Sjkh * Use ilogb instead. 212116Sjkh */ 222116Sjkh 232116Sjkh#include "math.h" 242116Sjkh#include "math_private.h" 252116Sjkh 262116Sjkh#ifdef __STDC__ 272116Sjkh double logb(double x) 282116Sjkh#else 292116Sjkh double logb(x) 302116Sjkh double x; 312116Sjkh#endif 322116Sjkh{ 332116Sjkh int32_t lx,ix; 342116Sjkh EXTRACT_WORDS(ix,lx,x); 352116Sjkh ix &= 0x7fffffff; /* high |x| */ 362116Sjkh if((ix|lx)==0) return -1.0/fabs(x); 372116Sjkh if(ix>=0x7ff00000) return x*x; 382116Sjkh if((ix>>=20)==0) /* IEEE 754 logb */ 392116Sjkh return -1022.0; 402116Sjkh else 412116Sjkh return (double) (ix-1023); 422116Sjkh} 43