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 * frexp/ldexp implementation
30 #include "FEATURE/float"
32 #if _lib_frexp && _lib_ldexp
38 #if defined(_ast_dbl_exp_index) && defined(_ast_dbl_exp_shift)
40 #define INIT() _ast_dbl_exp_t _pow_
41 #define pow2(i) (_pow_.f=1,_pow_.e[_ast_dbl_exp_index]+=((i)<<_ast_dbl_exp_shift),_pow_.f)
45 static double pow2tab
[DBL_MAX_EXP
+ 1];
54 for (x
= 0; x
< elementsof(pow2tab
); x
++)
62 #define INIT() (pow2tab[0]?0:init())
64 #define pow2(i) pow2tab[i]
71 frexp(double f
, int* p
)
83 x
= k
= DBL_MAX_EXP
/ 2;
92 else if (k
== 1 && g
< pow2(x
+1))
108 else if (k
== 1 && f
> pow2(x
-1))
127 else if (x
< DBL_MAX_EXP
)
130 f
= (f
* pow2(DBL_MAX_EXP
- 1)) * pow2(x
- (DBL_MAX_EXP
- 1));
139 ldexp(double f
, register int x
)
144 else if (x
< DBL_MAX_EXP
)
147 f
= (f
* pow2(DBL_MAX_EXP
- 1)) * pow2(x
- (DBL_MAX_EXP
- 1));