/
IFEC.c,v
100 lines (83 loc) · 1.79 KB
/
IFEC.c,v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
head 1.1;
access;
symbols;
locks
saclib:1.1; strict;
comment @ * @;
1.1
date 2000.01.02.16.26.43; author George; state init;
branches;
next ;
desc
@Integer to floating, exact conversion.
@
1.1
log
@Initial revision
@
text
@/*======================================================================
t <- IFEC(I,p,A)
Integer to floating, exact conversion.
Inputs
I : an integer.
p : a positive beta digit, the desired precision.
A : an array of size at least p + 3.
Output
t : 0 or 1.
Effect
If t = 0, I could not be exactly converted to a p-precision software
float and the content of A is undefined. If t = 1, the p-precision
software float equal to I is placed in A.
========================================================================*/
#include "floats.h"
BDigit IFEC(I,p,A)
Word I;
BDigit p,*A;
{
BDigit a,e,i,k,n,s,t;
Word J;
Step1: /* I = 0. */
if (I == 0) {
A[0] = 0;
A[1] = 0;
A[2] = p;
t = 1;
goto Return; }
Step2: /* Invert the list for I. */
if (I < BETA)
J = LIST1(I);
else
J = CINV(I);
Step3: /* Put the leading p + 1 digits in array A. */
s = SIGN(FIRST(J));
k = p + 2;
while (J != NIL && k >= 2) {
ADV(J, &a,&J);
A[k] = ABS(a);
k = k - 1; }
for (i = k; i >= 2; i--)
A[i] = 0;
Step4: /* Normalize. */
n = ZETA - PDLOG2(A[p+2]);
if (n > 0)
ILSA(A + 2,p + 1,n);
e = (p + 2 - k) * ZETA - n;
Step5:/* Exact conversion? */
t = 0;
if (A[2] != 0 )
goto Return;
while (J != NIL) {
a = FIRST(J);
if (a != 0)
goto Return;
e = e + ZETA;
J = RED(J); }
t = 1;
A[0] = e;
A[1] = s;
A[2] = p;
Return: /* Return t. */
return(t);
}
@