blob: 9016b9721a58575ab59d9c03d07275871b11de36 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 */
11
12/*
13 * double logb(x)
14 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
15 * Use ilogb instead.
16 */
17
18#include "math.h"
19#include "math_private.h"
20
21double logb(double x)
22{
23 int32_t lx,ix;
24 EXTRACT_WORDS(ix,lx,x);
25 ix &= 0x7fffffff; /* high |x| */
26 if((ix|lx)==0) return -1.0/fabs(x);
27 if(ix>=0x7ff00000) return x*x;
28 if((ix>>=20)==0) /* IEEE 754 logb */
29 return -1022.0;
30 else
31 return (double) (ix-1023);
32}
33libm_hidden_def(logb)