1 /* $OpenBSD: s_ilogbl.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>
23 struct ieee_ext
*p
= (struct ieee_ext
*)&x
;
27 if (p
->ext_exp
== 0) {
31 #endif /* EXT_FRACLMBITS */
34 #endif /* EXT_FRACHMBITS */
43 m
= 1lu << (EXT_FRACLBITS
- 1);
44 for (b
= EXT_FRACHBITS
; !(p
->ext_fracl
& m
); m
>>= 1)
46 #if defined(EXT_FRACHMBITS) && defined(EXT_FRACLMBITS)
47 m
= 1lu << (EXT_FRACLMBITS
- 1);
48 for (b
+= EXT_FRACHMBITS
; !(p
->ext_fraclm
& m
); m
>>= 1)
50 #endif /* defined(EXT_FRACHMBITS) && defined(EXT_FRACLMBITS) */
52 m
= 1lu << (EXT_FRACHBITS
- 1);
53 for (b
= 0; !(p
->ext_frach
& m
); m
>>= 1)
56 m
= 1lu << (EXT_FRACHMBITS
- 1);
57 for (; !(p
->ext_frachm
& m
); m
>>= 1)
59 #endif /* EXT_FRACHMBITS */
61 #ifdef EXT_IMPLICIT_NBIT
64 return (LDBL_MIN_EXP
- b
- 1);
65 } else if (p
->ext_exp
< (LDBL_MAX_EXP
<< 1) - 1)
66 return (p
->ext_exp
- LDBL_MAX_EXP
+ 1);
67 else if (p
->ext_fracl
!= 0
70 #endif /* EXT_FRACLMBITS */
73 #endif /* EXT_FRACHMBITS */