/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
*/
#include <ast.h>
#if _lib_frexpl && _lib_ldexpl
#else
#ifndef LDBL_MAX_EXP
#define LDBL_MAX_EXP DBL_MAX_EXP
#endif
#if defined(_ast_fltmax_exp_index) && defined(_ast_fltmax_exp_shift)
#else
static int
init(void)
{
register int x;
g = 1;
for (x = 0; x < elementsof(pow2tab); x++)
{
pow2tab[x] = g;
g *= 2;
}
return 0;
}
#endif
#if !_lib_frexpl
extern _ast_fltmax_t
frexpl(_ast_fltmax_t f, int* p)
{
register int k;
register int x;
INIT();
/*
* normalize
*/
x = k = LDBL_MAX_EXP / 2;
if (f < 1)
{
g = 1.0L / f;
for (;;)
{
k = (k + 1) / 2;
if (g < pow2(x))
x -= k;
break;
else
x += k;
}
if (g == pow2(x))
x--;
x = -x;
}
else if (f > 1)
{
for (;;)
{
k = (k + 1) / 2;
if (f > pow2(x))
x += k;
break;
else
x -= k;
}
if (f == pow2(x))
x++;
}
else
x = 1;
*p = x;
/*
* shift
*/
x = -x;
if (x < 0)
f /= pow2(-x);
else if (x < LDBL_MAX_EXP)
f *= pow2(x);
else
return f;
}
#endif
#if !_lib_ldexpl
extern _ast_fltmax_t
ldexpl(_ast_fltmax_t f, register int x)
{
INIT();
if (x < 0)
f /= pow2(-x);
else if (x < LDBL_MAX_EXP)
f *= pow2(x);
else
return f;
}
#endif
#endif