1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
25 * frexpl/ldexpl implementation
30 #include "FEATURE/float"
32 #if _lib_frexpl && _lib_ldexpl
39 #define LDBL_MAX_EXP DBL_MAX_EXP
42 #if defined(_ast_fltmax_exp_index) && defined(_ast_fltmax_exp_shift)
44 #define INIT() _ast_fltmax_exp_t _pow_
45 #define pow2(i) (_pow_.f=1,_pow_.e[_ast_fltmax_exp_index]+=((i)<<_ast_fltmax_exp_shift),_pow_.f)
49 static _ast_fltmax_t pow2tab
[LDBL_MAX_EXP
+ 1];
58 for (x
= 0; x
< elementsof(pow2tab
); x
++)
66 #define INIT() (pow2tab[0]?0:init())
68 #define pow2(i) (pow2tab[i])
77 frexpl(_ast_fltmax_t f
, int* p
)
89 x
= k
= LDBL_MAX_EXP
/ 2;
98 else if (k
== 1 && g
< pow2(x
+1))
114 else if (k
== 1 && f
> pow2(x
-1))
133 else if (x
< LDBL_MAX_EXP
)
136 f
= (f
* pow2(LDBL_MAX_EXP
- 1)) * pow2(x
- (LDBL_MAX_EXP
- 1));
147 ldexpl(_ast_fltmax_t f
, register int x
)
152 else if (x
< LDBL_MAX_EXP
)
155 f
= (f
* pow2(LDBL_MAX_EXP
- 1)) * pow2(x
- (LDBL_MAX_EXP
- 1));