1f9f848faSopenharmony_ci/****************************************************************
2f9f848faSopenharmony_ci
3f9f848faSopenharmony_ciThe author of this software is David M. Gay.
4f9f848faSopenharmony_ci
5f9f848faSopenharmony_ciCopyright (C) 1998, 1999 by Lucent Technologies
6f9f848faSopenharmony_ciAll Rights Reserved
7f9f848faSopenharmony_ci
8f9f848faSopenharmony_ciPermission to use, copy, modify, and distribute this software and
9f9f848faSopenharmony_ciits documentation for any purpose and without fee is hereby
10f9f848faSopenharmony_cigranted, provided that the above copyright notice appear in all
11f9f848faSopenharmony_cicopies and that both that the copyright notice and this
12f9f848faSopenharmony_cipermission notice and warranty disclaimer appear in supporting
13f9f848faSopenharmony_cidocumentation, and that the name of Lucent or any of its entities
14f9f848faSopenharmony_cinot be used in advertising or publicity pertaining to
15f9f848faSopenharmony_cidistribution of the software without specific, written prior
16f9f848faSopenharmony_cipermission.
17f9f848faSopenharmony_ci
18f9f848faSopenharmony_ciLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19f9f848faSopenharmony_ciINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20f9f848faSopenharmony_ciIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21f9f848faSopenharmony_ciSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22f9f848faSopenharmony_ciWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23f9f848faSopenharmony_ciIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24f9f848faSopenharmony_ciARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25f9f848faSopenharmony_ciTHIS SOFTWARE.
26f9f848faSopenharmony_ci
27f9f848faSopenharmony_ci****************************************************************/
28f9f848faSopenharmony_ci
29f9f848faSopenharmony_ci/* Please send bug reports to David M. Gay (dmg at acm dot org,
30f9f848faSopenharmony_ci * with " at " changed at "@" and " dot " changed to ".").	*/
31f9f848faSopenharmony_ci
32f9f848faSopenharmony_ci#include "gdtoaimp.h"
33f9f848faSopenharmony_ci
34f9f848faSopenharmony_ci double
35f9f848faSopenharmony_ciulp
36f9f848faSopenharmony_ci#ifdef KR_headers
37f9f848faSopenharmony_ci	(x) U *x;
38f9f848faSopenharmony_ci#else
39f9f848faSopenharmony_ci	(U *x)
40f9f848faSopenharmony_ci#endif
41f9f848faSopenharmony_ci{
42f9f848faSopenharmony_ci	Long L;
43f9f848faSopenharmony_ci	U a;
44f9f848faSopenharmony_ci
45f9f848faSopenharmony_ci	L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
46f9f848faSopenharmony_ci#ifndef Sudden_Underflow
47f9f848faSopenharmony_ci	if (L > 0) {
48f9f848faSopenharmony_ci#endif
49f9f848faSopenharmony_ci#ifdef IBM
50f9f848faSopenharmony_ci		L |= Exp_msk1 >> 4;
51f9f848faSopenharmony_ci#endif
52f9f848faSopenharmony_ci		word0(&a) = L;
53f9f848faSopenharmony_ci		word1(&a) = 0;
54f9f848faSopenharmony_ci#ifndef Sudden_Underflow
55f9f848faSopenharmony_ci		}
56f9f848faSopenharmony_ci	else {
57f9f848faSopenharmony_ci		L = -L >> Exp_shift;
58f9f848faSopenharmony_ci		if (L < Exp_shift) {
59f9f848faSopenharmony_ci			word0(&a) = 0x80000 >> L;
60f9f848faSopenharmony_ci			word1(&a) = 0;
61f9f848faSopenharmony_ci			}
62f9f848faSopenharmony_ci		else {
63f9f848faSopenharmony_ci			word0(&a) = 0;
64f9f848faSopenharmony_ci			L -= Exp_shift;
65f9f848faSopenharmony_ci			word1(&a) = L >= 31 ? 1 : 1 << (31 - L);
66f9f848faSopenharmony_ci			}
67f9f848faSopenharmony_ci		}
68f9f848faSopenharmony_ci#endif
69f9f848faSopenharmony_ci	return dval(&a);
70f9f848faSopenharmony_ci	}
71