/
ISI.c,v
133 lines (115 loc) · 2.32 KB
/
ISI.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
head 1.1;
access;
symbols;
locks
saclib:1.1; strict;
comment @ * @;
1.1
date 2000.01.02.16.29.05; author George; state init;
branches;
next ;
desc
@Integer to software interval.
@
1.1
log
@Initial revision
@
text
@/*======================================================================
ISI(I,p,A)
Integer to software interval.
Inputs
I : an integer.
p : a beta digit, the desired precision.
A : an array of size at least 2 p + 6.
Effect
The smallest p-precision software floating point interval containing
I is placed in A.
======================================================================*/
#include "floats.h"
void ISI(I,p,A)
Word I;
BDigit p,*A;
{
BDigit a,*B,*C,e,i,k,m,n,s,t;
Word J;
Step1: /* I = 0. */
if (I == 0) {
A[0] = 0;
A[1] = 0;
A[2] = p;
A[p + 3] = 0;
A[p + 4] = 0;
A[p + 5] = p;
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 an array B. */
s = SIGN(FIRST(J));
B = GETARRAY(p + 1);
k = p;
while (J != NIL && k >= 0) {
ADV(J, &a,&J);
B[k] = ABS(a);
k = k - 1; }
if (k >= 0) {
for (i = k; i >= 0; i--)
B[i] = 0; }
Step4: /* Normalize. */
n = ZETA - PDLOG2(B[p]);
if (n > 0)
ILSA(B,p + 1,n);
e = (p - k) * ZETA - n;
Step5:/* Exact conversion. */
m = LENGTH(J);
if (m > 0)
e = e + m * ZETA;
A[0] = e;
A[1] = s;
A[2] = p;
A[p + 3] = e;
A[p + 4] = s;
A[p + 5] = p;
t = 0;
while (t == 0 && J != NIL) {
t = FIRST(J);
if (t == 0)
J = RED(J); }
if (t == 0 && B[0] == 0) {
AWCOPY(B + 1,p,A + 3);
AWCOPY(B + 1,p,A + p + 6);
goto Step7; }
Step6: /* Round. */
C = GETARRAY(p);
AWCOPY(B + 1,p,C);
t = 1;
i = 1;
while (t > 0 && i <= p) {
B[i] = B[i] + 1;
if (B[i] == BETA)
B[i] = 0;
else
t = 0;
i = i + 1; }
if (B[p] == 0) {
B[p] = BETA2;
e = e + 1; }
if (s > 0) {
AWCOPY(B + 1,p,A + p + 6);
AWCOPY(C,p,A + 3);
A[p + 3] = e; }
else {
AWCOPY(B + 1,p,A + 3);
AWCOPY(C,p,A + p + 6);
A[0] = e; }
FREEARRAY(C);
Step7: /* Free array B. */
FREEARRAY(B);
Return: /* return. */
return;
}
@