1 /* $OpenBSD: s_logbl.c,v 1.1 2008/12/09 20:00:35 martynas Exp $ */
3 * From: @(#)s_ilogb.c 5.1 93/09/24
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
14 #include <sys/types.h>
15 #include <machine/ieee.h>
31 if (u.bits.ext_exp == 0) {
35 #endif /* EXT_FRACLMBITS */
38 #endif /* EXT_FRACHMBITS */
39 | u.bits.ext_frach) == 0) { /* x == 0 */
44 if (u.bits.ext_frach == 0
46 && u.bits.ext_frachm == 0
49 m = 1lu << (EXT_FRACLBITS - 1);
50 for (b = EXT_FRACHBITS; !(u.bits.ext_fracl & m); m >>= 1)
52 #if defined(EXT_FRACHMBITS) && defined(EXT_FRACLMBITS)
53 m = 1lu << (EXT_FRACLMBITS - 1);
54 for (b += EXT_FRACHMBITS; !(u.bits.ext_fraclm & m);
57 #endif /* defined(EXT_FRACHMBITS) && defined(EXT_FRACLMBITS) */
59 m = 1lu << (EXT_FRACHBITS - 1);
60 for (b = 0; !(u.bits.ext_frach & m); m >>= 1)
63 m = 1lu << (EXT_FRACHMBITS - 1);
64 for (; !(u.bits.ext_frachm & m); m >>= 1)
66 #endif /* EXT_FRACHMBITS */
68 #ifdef EXT_IMPLICIT_NBIT
71 return ((long double)(LDBL_MIN_EXP - b - 1));
73 if (u.bits.ext_exp < (LDBL_MAX_EXP << 1) - 1) /* normal */
74 return ((long double)(u.bits.ext_exp - LDBL_MAX_EXP + 1));
75 else /* +/- inf or nan */