1/* s_ilogbf.c -- float version of s_ilogb.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
4
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
14 */
15
16#include <sys/cdefs.h>
17#if defined(LIBM_SCCS) && !defined(lint)
18__RCSID("$NetBSD: s_ilogbf.c,v 1.10 2016/08/26 08:20:31 christos Exp $");
19#endif
20
21#include <math.h>
22#define __TEST_FENV
23#include <fenv.h>
24#ifndef __HAVE_FENV
25#define feraiseexcept(a)
26#endif
27#include "math_private.h"
28
29int
30ilogbf(float x)
31{
32	int32_t hx, ix;
33
34	GET_FLOAT_WORD(hx, x);
35	hx &= 0x7fffffff;
36	if (hx < 0x00800000) {
37		if (hx == 0) {
38			feraiseexcept(FE_INVALID);
39			return FP_ILOGB0;	/* ilogb(0) = 0x80000001 */
40		}
41		for (ix = -126, hx <<= 8; hx > 0; hx <<= 1) ix -= 1;
42		return ix;
43	}
44
45	if (hx < 0x7f800000) {
46		return (hx >> 23) - 127;
47	}
48
49	feraiseexcept(FE_INVALID);
50	return isnan(x) ? FP_ILOGBNAN : INT_MAX;
51}
52