-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdouble-test.f
382 lines (341 loc) · 6.3 KB
/
double-test.f
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
\ double.asm library test suite.
decimal
\ 1) check for stack underflow
\ 2) check if last operation left data on stack
\ is so display stack state
: stack-check
?stack \ abort if stack underflow
depth if
cr ." ERROR: left over on stack"
.s
abort
then
;
\ display expected double integer d2 and result d1
: dresult ( d1 d2 -- )
cr
2dup 2>r
2over 2>r
." expected: " d.
." result: " d.
2r> 2r>
D= NOT IF
." TEST FAILED "
ABORT
THEN
stack-check
cr
;
\ display expected integer i2 and result i1
: iresult ( i1 i2 -- )
cr
2DUP 2>R
." expected: " .
." result: " .
2R>
= NOT IF
." TEST FAILED "
ABORT
THEN
stack-check
cr
;
: show-version
dbl-ver
;
: double?
preset
cr
." double parsing test." cr
." enter positive double: "
query
eval
d. CR stack-check
." enter negative double: "
query
eval
d. cr
." enter 0 double: "
query
eval
d. cr stack-check
;
: dabs-test
preset
." DABS test (d -- abs(d) ) " cr
." enter negative double: "
query
eval
2DUP D. ." DABS"
dabs
d.
cr stack-check
." enter positive double: "
query
eval
2DUP D. ." DABS"
dabs
d.
cr stack-check
;
: dsign-test
preset
cr ." DSIGN test ( d -- d sign )" cr
." 4134124. dsign <ROT d. ." cr
4134124. dsign <rot d. . cr stack-check
." -5467. dsign >rot d. ." cr
-5467. dsign <rot d. . cr stack-check
;
: ds/mod-test
preset
cr ." ds/mod test ( ud us -- r dq )" cr
." 3141.592 2 ds/mod"
3141592. 2 ds/mod 2>r
cr ." remainder=" 0 iresult
2r> ." quotient= " 1570796. dresult
;
: ds*-test
preset
cr
." double single product ds* ( d s -- d*s )"
cr
." 3141592. 2 ds*" cr
3141592. 2 ds* 6283.184 dresult
;
: 2swap-test
cr
." 2swap test" cr
1.
2.
.s
2SWAP
.s
d. d.
stack-check
;
: dclz-test
preset
cr
." count leading 0's test dclz ( d -- n )" cr
." 1. dclz ." cr
1. dclz 31 iresult
." $1000000. clz ." cr
$10000000. dclz 3 iresult
stack-check
;
: 2rot-test
preset
cr ." rotate doubles test" cr
." 1. 2. 3. 2ROT" cr
1. 2. 3. 2rot
2>r 2>r 2. dresult
2r> 3. dresult
2r> 1. dresult
." 2. 3. 1. <2ROT" cr
2. 3. 1. <2ROT
2>r 2>r
1. dresult
2r> 2. dresult
2r> 3. dresult
;
: d0=-test
preset
cr
." d0= test ( d -- -1|0 )" cr
." 0. D0=" CR
0. D0= -1 iresult
." 1. D0=" CR
1. D0= 0 iresult
;
: d=-test
preset
cr
." D= ( d1 d2 -- f ) test" cr
." -1. #1. D=" cr
-1. 1. D= 0 iresult
." 45. 2DUP D= " cr
45. 2DUP D= -1 iresult
;
: d>-test
preset
cr
." D> ( d1 d2 -- d1>d2 )" cr
." -33. -32. d>" cr
-33. -32. d> 0 iresult
." 33. 32. d>" cr
33. 32. d> -1 iresult
." -3. 2. d>" cr
-3. 2. d> 0 iresult
;
: d<-test
preset
cr
." D< ( d1 d2 -- d1<d2 )" cr
." -33. -32. d<" cr
-33. -32. d< -1 iresult
." 33. 32. d<" cr
33. 32. d< 0 iresult
." -3. 2. d<" cr
-3. 2. d< -1 iresult
;
: d0<-test
preset
cr
." D0< test ( d -- d<0 )" cr
." 2. d0<" cr
2. d0< 0 iresult
." -33. d0<" cr
-33. d0< -1 iresult
;
: 2>r-test
preset
cr
." 2>R test" cr
." 1. 2. 2>r d." cr
1. 2. 2>r 1. dresult
." 2r@ d." cr
2r@ 2. dresult
." 2r> d."
2r> 2. dresult
;
: 2over-test
preset
cr
." 2over test ( d1 d2 -- d1 d2 d1 )" cr
." 1. 2. 2OVER D. D. D." cr
1. 2. 2over
2>r 2>r
1. dresult
2r> 2. dresult
2r> 1. dresult
;
: d2/-test
cr ." d2/ test ( d -- d/2 )" cr
." 131.072 d2/"
131.072 d2/ 65536. dresult
;
: d2*-test
cr ." D2* test ( d -- 2*d )" cr
." 131.072 d2*"
131.072 d2* 262.144 dresult
;
: DSHIFT-TEST
cr ." shift double test ( d n -- d )" cr
." #1 4 DLSHIFT" cr
1. 4 DLSHIFT 16. dresult
." 16. 4 DRSHIFT" cr
16. 4 DRSHIFT 1. dresult
;
: d*-test
cr ." D* ( d1 d2 -- d1*d2 )" cr
." 10. 351. d*" cr
10. 351. d* 3510. dresult
." -32. 16. d*" cr
-32. 16. d* -512. dresult
." -25. -8. d*"
-25. -8. d* 200. dresult
;
: d/mod-test
cr ." D/MOD test ( d d -- dr dq )" cr
." 57.003 5. d/mod" cr
57.003 5. d/mod
2>r
." remainder=" 3. dresult
2r>
." quotient=" 11.400 dresult
." -57.003 5. d/mod" cr
-57.003 5. d/mod 2>r
." remainder=" -3. dresult
2r>
." quotient=" -11.400 dresult
." 57.003 -5. d/mod" cr
57.003 -5. d/mod
2>r
." remainder=" 3. dresult
2r>
." quotient=" -11.400 dresult
." -57.003 -5. d/mod" cr
-57.003 -5. d/mod 2>r
." remainder=" -3. dresult
2r>
." quotient=" 11.400 dresult
." -55. -5. d/mod" cr
-55. -5. d/mod 2>R
." remainder=" 0. dresult
2r>
." quotient=" 11. dresult
;
: +-test
cr ." d+ d- test" cr
." -355. -23. d+"
-355. -23. d+ -378. dresult
." 6377. 523. d-"
6377. 523. d- 5854. dresult
;
: add-spd
msec 1000 for
-253.353 979.788 d+
2drop next
msec swap -
. ." msec for 1000 double additions."
cr
;
: sub-spd
msec 1000 for
-254.232 34. d-
2drop next
msec swap -
. ." msec for 1000 double substactions."
cr
;
: mul-spd
msec 1000 for
324. 332. d*
2drop
next
msec swap -
. ." msec for 1000 double muliplications."
cr
;
: div-spd
msec 1000 for
324.333 56. d/ 2drop
next
msec swap -
. ." msec for 1000 double divisions."
cr
;
: performance
cr
." ******** Performance test ******"
cr
add-spd
sub-spd
mul-spd
div-spd
;
: all-test
show-version
double?
dabs-test
dsign-test
ds/mod-test
ds*-test
2swap-test
dclz-test
2rot-test
d0=-test
d=-test
d>-test
d<-test
d0<-test
2>r-test
2over-test
d2/-test
d2*-test
dshift-test
d*-test
d/mod-test
+-test
performance
;