]>
Commit | Line | Data |
---|---|---|
9169c9b5 AM |
1 | From 0fafaee9bb38a3ea4b8be4009e9ce99334460ddd Mon Sep 17 00:00:00 2001 |
2 | From: "Arnold D. Robbins" <arnold@skeeve.com> | |
3 | Date: Mon, 2 Apr 2018 16:37:17 +0300 | |
4 | Subject: [PATCH] Copy MPZ/MPFR bits also, in r_dupnode. | |
5 | ||
6 | --- | |
7 | interpret.h | 27 ++++++++++++++++++--------- | |
8 | node.c | 20 ++++++++++++++++++-- | |
9 | test/Makefile.am | 12 ++++++++++-- | |
10 | test/Makefile.in | 12 ++++++++++-- | |
11 | test/mpfrfield.awk | 14 ++++++++++++++ | |
12 | test/mpfrfield.in | 10 ++++++++++ | |
13 | test/mpfrfield.ok | 1 + | |
14 | 7 files changed, 81 insertions(+), 15 deletions(-) | |
15 | create mode 100644 test/mpfrfield.awk | |
16 | create mode 100644 test/mpfrfield.in | |
17 | create mode 100644 test/mpfrfield.ok | |
18 | ||
19 | diff --git a/interpret.h b/interpret.h | |
20 | index 96e2c89..20fcb7a 100644 | |
21 | --- a/interpret.h | |
22 | +++ b/interpret.h | |
23 | @@ -32,16 +32,25 @@ | |
24 | * valref 1, that effectively means that this is an assignment like "$n = $n", | |
25 | * so a no-op, other than triggering $0 reconstitution. | |
26 | */ | |
27 | -#define UNFIELD(l, r) \ | |
28 | -{ \ | |
29 | - /* if was a field, turn it into a var */ \ | |
30 | - if ((r->flags & MALLOC) != 0 || r->valref == 1) { \ | |
31 | - l = r; \ | |
32 | - } else { \ | |
33 | - l = dupnode(r); \ | |
34 | - DEREF(r); \ | |
35 | - } \ | |
36 | + | |
37 | +// not a macro so we can step into it with a debugger | |
38 | +#ifndef UNFIELD_DEFINED | |
39 | +#define UNFIELD_DEFINED 1 | |
40 | +static inline void | |
41 | +unfield(NODE **l, NODE **r) | |
42 | +{ | |
43 | + /* if was a field, turn it into a var */ | |
44 | + if (((*r)->flags & MALLOC) != 0 || (*r)->valref == 1) { | |
45 | + (*l) = (*r); | |
46 | + } else { | |
47 | + (*l) = dupnode(*r); | |
48 | + DEREF(*r); | |
49 | + } | |
50 | } | |
51 | + | |
52 | +#define UNFIELD(l, r) unfield(& (l), & (r)) | |
53 | +#endif | |
54 | + | |
55 | int | |
56 | r_interpret(INSTRUCTION *code) | |
57 | { | |
58 | diff --git a/node.c b/node.c | |
59 | index add959f..fcd2bf3 100644 | |
60 | --- a/node.c | |
61 | +++ b/node.c | |
62 | @@ -306,8 +306,24 @@ r_dupnode(NODE *n) | |
63 | } | |
64 | #endif | |
65 | ||
66 | - getnode(r); | |
67 | - *r = *n; | |
68 | +#ifdef HAVE_MPFR | |
69 | + if ((n->flags & MPZN) != 0) { | |
70 | + r = mpg_integer(); | |
71 | + mpz_set(r->mpg_i, n->mpg_i); | |
72 | + r->flags = n->flags; | |
73 | + } else if ((n->flags & MPFN) != 0) { | |
74 | + r = mpg_float(); | |
75 | + int tval = mpfr_set(r->mpg_numbr, n->mpg_numbr, ROUND_MODE); | |
76 | + IEEE_FMT(r->mpg_numbr, tval); | |
77 | + r->flags = n->flags; | |
78 | + } else { | |
79 | +#endif | |
80 | + getnode(r); | |
81 | + *r = *n; | |
82 | +#ifdef HAVE_MPFR | |
83 | + } | |
84 | +#endif | |
85 | + | |
86 | r->flags |= MALLOC; | |
87 | r->valref = 1; | |
88 | /* | |
89 | diff --git a/test/Makefile.am b/test/Makefile.am | |
90 | index 40e25b2..93a6ee5 100644 | |
91 | --- a/test/Makefile.am | |
92 | +++ b/test/Makefile.am | |
93 | @@ -655,6 +655,9 @@ EXTRA_DIST = \ | |
94 | mpfrbigint.ok \ | |
95 | mpfrexprange.awk \ | |
96 | mpfrexprange.ok \ | |
97 | + mpfrfield.awk \ | |
98 | + mpfrfield.in \ | |
99 | + mpfrfield.ok \ | |
100 | mpfrieee.awk \ | |
101 | mpfrieee.ok \ | |
102 | mpfrmemok1.awk \ | |
103 | @@ -1302,8 +1305,8 @@ INET_TESTS = inetdayu inetdayt inetechu inetecht | |
104 | ||
105 | MACHINE_TESTS = double1 double2 fmtspcl intformat | |
106 | ||
107 | -MPFR_TESTS = mpfrbigint mpfrexprange mpfrieee mpfrmemok1 mpfrnegzero \ | |
108 | - mpfrnr mpfrrem mpfrrnd mpfrrndeval mpfrsort mpfrsqrt \ | |
109 | +MPFR_TESTS = mpfrbigint mpfrexprange mpfrfield mpfrieee mpfrmemok1 \ | |
110 | + mpfrnegzero mpfrnr mpfrrem mpfrrnd mpfrrndeval mpfrsort mpfrsqrt \ | |
111 | mpfrstrtonum mpgforcenum mpfruplus | |
112 | ||
113 | LOCALE_CHARSET_TESTS = \ | |
114 | @@ -2148,6 +2151,11 @@ mpfrmemok1: | |
115 | @$(AWK) -p- -M -f "$(srcdir)"/$@.awk 2>&1 | sed 1d > _$@ | |
116 | @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ | |
117 | ||
118 | +mpfrfield: | |
119 | + @echo $@ | |
120 | + @$(AWK) -M -f "$(srcdir)"/$@.awk "$(srcdir)"/$@.in > _$@ 2>&1 | |
121 | + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ | |
122 | + | |
123 | jarebug:: | |
124 | @echo $@ | |
125 | @"$(srcdir)"/$@.sh "$(AWKPROG)" "$(srcdir)"/$@.awk "$(srcdir)"/$@.in "_$@" | |
126 | diff --git a/test/Makefile.in b/test/Makefile.in | |
127 | index 74405f8..2358988 100644 | |
128 | --- a/test/Makefile.in | |
129 | +++ b/test/Makefile.in | |
130 | @@ -913,6 +913,9 @@ EXTRA_DIST = \ | |
131 | mpfrbigint.ok \ | |
132 | mpfrexprange.awk \ | |
133 | mpfrexprange.ok \ | |
134 | + mpfrfield.awk \ | |
135 | + mpfrfield.in \ | |
136 | + mpfrfield.ok \ | |
137 | mpfrieee.awk \ | |
138 | mpfrieee.ok \ | |
139 | mpfrmemok1.awk \ | |
140 | @@ -1555,8 +1558,8 @@ ARRAYDEBUG_TESTS = arrdbg | |
141 | EXTRA_TESTS = inftest regtest ignrcas3 | |
142 | INET_TESTS = inetdayu inetdayt inetechu inetecht | |
143 | MACHINE_TESTS = double1 double2 fmtspcl intformat | |
144 | -MPFR_TESTS = mpfrbigint mpfrexprange mpfrieee mpfrmemok1 mpfrnegzero \ | |
145 | - mpfrnr mpfrrem mpfrrnd mpfrrndeval mpfrsort mpfrsqrt \ | |
146 | +MPFR_TESTS = mpfrbigint mpfrexprange mpfrfield mpfrieee mpfrmemok1 \ | |
147 | + mpfrnegzero mpfrnr mpfrrem mpfrrnd mpfrrndeval mpfrsort mpfrsqrt \ | |
148 | mpfrstrtonum mpgforcenum mpfruplus | |
149 | ||
150 | LOCALE_CHARSET_TESTS = \ | |
151 | @@ -2588,6 +2591,11 @@ mpfrmemok1: | |
152 | @$(AWK) -p- -M -f "$(srcdir)"/$@.awk 2>&1 | sed 1d > _$@ | |
153 | @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ | |
154 | ||
155 | +mpfrfield: | |
156 | + @echo $@ | |
157 | + @$(AWK) -M -f "$(srcdir)"/$@.awk "$(srcdir)"/$@.in > _$@ 2>&1 | |
158 | + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ | |
159 | + | |
160 | jarebug:: | |
161 | @echo $@ | |
162 | @"$(srcdir)"/$@.sh "$(AWKPROG)" "$(srcdir)"/$@.awk "$(srcdir)"/$@.in "_$@" | |
163 | diff --git a/test/mpfrfield.awk b/test/mpfrfield.awk | |
164 | new file mode 100644 | |
165 | index 0000000..35a97b7 | |
166 | --- /dev/null | |
167 | +++ b/test/mpfrfield.awk | |
168 | @@ -0,0 +1,14 @@ | |
169 | +#! /bin/gawk -Mf | |
170 | + | |
171 | +NR == 1 { | |
172 | + min = $1 | |
173 | +} | |
174 | + | |
175 | +{ | |
176 | + if ($1 < min) | |
177 | + min = $1 | |
178 | +} | |
179 | + | |
180 | +END { | |
181 | + print "min", min | |
182 | +} | |
183 | diff --git a/test/mpfrfield.in b/test/mpfrfield.in | |
184 | new file mode 100644 | |
185 | index 0000000..05d3344 | |
186 | --- /dev/null | |
187 | +++ b/test/mpfrfield.in | |
188 | @@ -0,0 +1,10 @@ | |
189 | +7 | |
190 | +9 | |
191 | +1 | |
192 | +3 | |
193 | +9 | |
194 | +1 | |
195 | +9 | |
196 | +5 | |
197 | +0 | |
198 | +8 | |
199 | diff --git a/test/mpfrfield.ok b/test/mpfrfield.ok | |
200 | new file mode 100644 | |
201 | index 0000000..3736de4 | |
202 | --- /dev/null | |
203 | +++ b/test/mpfrfield.ok | |
204 | @@ -0,0 +1 @@ | |
205 | +min 0 | |
206 | -- | |
207 | 2.14.4 | |
208 |