s_logb.c revision 117912
195821Sphk/* @(#)s_logb.c 5.1 93/09/24 */
258377Sphk/*
358377Sphk * ====================================================
458377Sphk * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
558377Sphk *
658377Sphk * Developed at SunPro, a Sun Microsystems, Inc. business.
758377Sphk * Permission to use, copy, modify, and distribute this
8227723Slstewart * software is freely granted, provided that this notice
9227723Slstewart * is preserved.
10227723Slstewart * ====================================================
11227723Slstewart */
12227723Slstewart
13227723Slstewart#ifndef lint
141541Srgrimesstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_logb.c 117912 2003-07-23 04:53:47Z peter $";
151541Srgrimes#endif
16116182Sobrien
17116182Sobrien/*
18116182Sobrien * double logb(x)
19237433Skib * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
2044666Sphk * Use ilogb instead.
21227723Slstewart */
2244666Sphk
231541Srgrimes#include "math.h"
2458377Sphk#include "math_private.h"
25227723Slstewart
26227723Slstewartdouble
27227723Slstewartlogb(double x)
28227723Slstewart{
2958377Sphk	int32_t lx,ix;
30124812Sphk	EXTRACT_WORDS(ix,lx,x);
311541Srgrimes	ix &= 0x7fffffff;			/* high |x| */
32227723Slstewart	if((ix|lx)==0) return -1.0/fabs(x);
3395976Sphk	if(ix>=0x7ff00000) return x*x;
34237433Skib	if((ix>>=20)==0) 			/* IEEE 754 logb */
3595821Sphk		return -1022.0;
362858Swollman	else
37237433Skib		return (double) (ix-1023);
381541Srgrimes}
3940609Sphk