-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdouble.tex
More file actions
795 lines (617 loc) · 25.6 KB
/
Copy pathdouble.tex
File metadata and controls
795 lines (617 loc) · 25.6 KB
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
% !TeX root = forth.tex
% !TeX spellcheck = en_US
% !TeX program = pdflatex
\chapter{The optional Double-Number word set} % 8
\wordlist{double}
\section{Introduction} % 8.1
Sixteen-bit Forth systems often use double-length numbers. However,
many Forths on small embedded systems do not, and many users of Forth
on systems with a cell size of 32 bits or more find that the use of
double-length numbers is much diminished. Therefore, the words that
manipulate double-length entities have been placed in this optional
word set.
\section{Additional terms and notation} % 8.2
None.
\section{Additional usage requirements} % 8.3
\subsection{Text interpreter input number conversion} % 8.3.2
When the text interpreter processes a number, except a \arg{cnum},
that is immediately followed by a decimal point and is not found
as a definition name, the text interpreter shall convert it to a
double-cell number.
For example, entering \word[core]{DECIMAL} \texttt{1234} leaves the
single-cell number \texttt{1234} on the stack, and entering
\word[core]{DECIMAL} \texttt{1234.} leaves the double-cell number
\texttt{1234} \texttt{0} on the stack.
See: \xref[3.4.1.3 Text interpreter input number conversion]{usage:numbers}.
\section{Additional documentation requirements} % 8.4
\subsection{System documentation} % 8.4.1
\subsubsection{Implementation-defined options} % 8.4.1.1
\begin{itemize}
\item no additional requirements.
\end{itemize}
\subsubsection{Ambiguous conditions} % 8.4.1.2
\begin{itemize}
\item \param{d} outside range of \param{n} in \wref{double:DtoS}{D>S}.
\end{itemize}
\subsubsection{Other system documentation} % 8.4.1.3
\begin{itemize}
\item no additional requirements.
\end{itemize}
\subsection{Program documentation} % 8.4.2
\begin{itemize}
\item no additional requirements.
\end{itemize}
\section{Compliance and labeling} % 8.5
\subsection{Forth-\snapshot{} systems} % 8.5.1
The phrase ``Providing the Double-Number word set'' shall be
appended to the label of any Standard System that provides all
of the Double-Number word set.
The phrase ``Providing \emph{name(s)} from the Double-Number
Extensions word set'' shall be appended to the label of any
Standard System that provides portions of the Double-Number
Extensions word set.
The phrase ``Providing the Double-Number Extensions word set''
shall be appended to the label of any Standard System that
provides all of the Double-Number and Double-Number Extensions
word sets.
\subsection{Forth-\snapshot{} programs} % 8.5.2
The phrase ``Requiring the Double-Number word set'' shall be
appended to the label of Standard Programs that require the
system to provide the Double-Number word set.
The phrase ``Requiring \emph{name(s)} from the Double-Number
Extensions word set'' shall be appended to the label of Standard
Programs that require the system to provide portions of the
Double-Number Extensions word set.
The phrase ``Requiring the Double-Number Extensions word set''
shall be appended to the label of Standard Programs that require
the system to provide all of the Double-Number and Double-Number
Extensions word sets.
\section{Glossary} % 8.6
\subsection{Double-Number words} % 8.6.1
\begin{worddef}{0360}{2CONSTANT}[two-constant]
\item \stack{x_1 x_2 "<spaces>name"}{}
Skip leading space delimiters. Parse \param{name} delimited by
a space. Create a definition for \param{name} with the execution
semantics defined below.
\param{name} is referred to as a ``two-constant''.
\execute[name]
\stack{}{x_1 x_2}
Place cell pair \param{x_1 x_2} on the stack.
\see \xref[3.4.1 Parsing]{usage:parsing},
\rref{double:2CONSTANT}{}.
\begin{rationale} % A.8.6.1.0360 2CONSTANT
Typical use:
\texttt{x1} \texttt{x2} \word{2CONSTANT} \emph{name}
\end{rationale}
\begin{testing}
\test{1 2 \word{2CONSTANT} 2c1}{} \\
\test{2c1}{1 2}
\test{\word{:} cd1 2c1 \word{;}}{} \\
\test{cd1}{1 2}
\test{\word{:} cd2 \word{2CONSTANT} \word{;}}{} \\
\test{-1 -2 cd2 2c2}{} \\
\test{2c2}{-1 -2}
\test{4 5 \word{2CONSTANT} 2c3 \word{IMMEDIATE} 2c3}{4 5} \\
\test{\word{:} cd6 2c3 \word{2LITERAL} \word{;} cd6}{4 5}
\end{testing}
\end{worddef}
\vspace*{-3ex}
\begin{worddef}{0390}{2LITERAL}[two-literal]
\interpret
Interpretation semantics for this word are undefined.
\compile
\stack{x_1 x_2}{}
Append the run-time semantics below to the current definition.
\runtime
\stack{}{x_1 x_2}
Place cell pair \param{x_1 x_2} on the stack.
\see \rref{double:2LITERAL}{}.
\begin{rationale} % A.8.6.1.0390 2LITERAL
\setwordlist{core}
Typical use:
\word{:} \texttt{X} {\ldots}
\word{[} \texttt{x1} \texttt{x2} \word{]} \word[double]{2LITERAL}
{\ldots} \word{;}
\setwordlist{double}
\end{rationale}
\begin{testing}
\test{\word{:} cd1 \word{[} MAX-2INT \word{]} \word{2LITERAL} \word{;}}{}\\
\test{cd1}{MAX-2INT}
\test{\word{2VARIABLE} 2v4 \word{IMMEDIATE} 5 6 2v4 \word{2!}}{} \\
\test{\word{:} cd7 2v4 \word{[} \word{2@} \word{]} \word{2LITERAL} \word{;} cd7}{5 6} \\
\test{\word{:} cd8 \word{[} 6 7 \word{]} 2v4 \word{[} \word{2!} \word{]} \word{;} 2v4 \word{2@}}{6 7}
\end{testing}
\end{worddef}
\vspace*{-3ex}
\enlargethispage{8ex}
\begin{worddef}{0440}{2VARIABLE}[two-variable]
\item \stack{"<spaces>name"}{}
Skip leading space delimiters. Parse \param{name} delimited by a
space. Create a definition for \param{name} with the execution
semantics defined below. Reserve two consecutive cells of data
space.
\param{name} is referred to as a ``two-variable''.
\execute[name]
\stack{}{a-addr}
\param{a-addr} is the address of the first (lowest address)
cell of two consecutive cells in data space reserved by
\word{2VARIABLE} when it defined \param{name}. A program is
responsible for initializing the contents.
\see \xref[3.4.1 Parsing]{usage:parsing},
\wref{core:VARIABLE}{VARIABLE},
\rref{double:2VARIABLE}{}.
\begin{rationale} % A.8.6.1.0440 2VARIABLE
Typical use:
\word{2VARIABLE} \param{name}
\end{rationale}
\begin{testing}
\test{\word{2VARIABLE} 2v1}{} \\
\test{0. 2v1 \word{2!}}{ } \\
\test{ 2v1 \word{2@}}{0.} \\
\test{-1 -2 2v1 \word{2!}}{ } \\
\test{ 2v1 \word{2@}}{-1 -2}
\test{\word{:} cd2 \word{2VARIABLE} \word{;}}{} \\
\test{cd2 2v2}{} \\
\test{\word{:} cd3 2v2 \word{2!} \word{;}}{} \\
\test{-2 -1 cd3}{} \\
\test{2v2 \word{2@}}{-2 -1}
\test{\word{2VARIABLE} 2v3 \word{IMMEDIATE} 5 6 2v3 \word{2!}}{} \\
\test{2v3 \word{2@}}{5 6}
\end{testing}
\end{worddef}
\begin{worddef}{1040}{D+}[d-plus]
\item \stack{d_1|ud_1 d_2|ud_2}{d_3|ud_3}
Add \param{d_2|ud_2} to \param{d_1|ud_1}, giving the sum
\param{d_3|ud_3}.
\begin{testing}
\test{ 0. 5. \word{D+}}{ 5.} \tab[11.5] \word{bs} small integers \\
\test{-5. 0. \word{D+}}{-5.} \\
\test{ 1. 2. \word{D+}}{ 3.} \\
\test{ 1. -2. \word{D+}}{-1.} \\
\test{-1. 2. \word{D+}}{ 1.} \\
\test{-1. -2. \word{D+}}{-3.} \\
\test{-1. 1. \word{D+}}{ 0.}
\test{ 0 0 0 5 \word{D+}}{ 0 5} \tab[8] \word{bs} mid range integers \\
\test{-1 5 0 0 \word{D+}}{-1 5} \\
\test{ 0 0 0 -5 \word{D+}}{ 0 -5} \\
\test{ 0 -5 -1 0 \word{D+}}{-1 -5} \\
\test{ 0 1 0 2 \word{D+}}{ 0 3} \\
\test{-1 1 0 -2 \word{D+}}{-1 -1} \\
\test{ 0 -1 0 2 \word{D+}}{ 0 1} \\
\test{ 0 -1 -1 -2 \word{D+}}{-1 -3} \\
\test{-1 -1 0 1 \word{D+}}{-1 0}
\test{MIN-INT 0 \word{2DUP} \word{D+}}{0 1} \\
\test{MIN-INT \word{StoD} MIN-INT 0 \word{D+}}{0 0}
\test{ HI-2INT 1.\ \word{D+}}{0 HI-INT \word{1+}} \tab \word{bs} large double integers \\
\test{ HI-2INT \word{2DUP} \word{D+}}{1S \word{1-} MAX-INT} \\
\test{MAX-2INT MIN-2INT \word{D+}}{-1.} \\
\test{MAX-2INT LO-2INT \word{D+}}{HI-2INT} \\
\test{ LO-2INT \word{2DUP} \word{D+}}{MIN-2INT} \\
\test{ HI-2INT MIN-2INT \word{D+} 1.\ \word{D+}}{LO-2INT}
\end{testing}
\end{worddef}
\begin{worddef}{1050}{D-}[d-minus]
\item \stack{d_1|ud_1 d_2|ud_2}{d_3|ud_3}
Subtract \param{d_2|ud_2} from \param{d_1|ud_1}, giving the
difference \param{d_3|ud_3}.
\begin{testing}
\test{ 0. 5. \word{D-}}{-5.} \tab[6] \word{bs} small integers \\
\test{ 5. 0. \word{D-}}{ 5.} \\
\test{ 0. -5. \word{D-}}{ 5.} \\
\test{ 1. 2. \word{D-}}{-1.} \\
\test{ 1. -2. \word{D-}}{ 3.} \\
\test{-1. 2. \word{D-}}{-3.} \\
\test{-1. -2. \word{D-}}{ 1.} \\
\test{-1. -1. \word{D-}}{ 0.} \\
\test{ 0 0 0 5 \word{D-}}{ 0 -5} \tab[2.5] \word{bs} mid-range integers \\
\test{-1 5 0 0 \word{D-}}{-1 5} \\
\test{ 0 0 -1 -5 \word{D-}}{ 1 4} \\
\test{ 0 -5 0 0 \word{D-}}{ 0 -5} \\
\test{-1 1 0 2 \word{D-}}{-1 -1} \\
\test{ 0 1 -1 -2 \word{D-}}{ 1 2} \\
\test{ 0 -1 0 2 \word{D-}}{ 0 -3} \\
\test{ 0 -1 0 -2 \word{D-}}{ 0 1} \\
\test{ 0 0 0 1 \word{D-}}{ 0 -1}
\test{MIN-INT 0 \word{2DUP} \word{D-}}{0.} \\
\test{MIN-INT \word{StoD} MAX-INT 0\word{D-}}{1 1s} \\
\test{MAX-2INT max-2INT \word{D-}}{0.} \tab \word{bs} large integers \\
\test{MIN-2INT min-2INT \word{D-}}{0.} \\
\test{MAX-2INT hi-2INT \word{D-}}{lo-2INT \word{DNEGATE}} \\
\test{ HI-2INT lo-2INT \word{D-}}{max-2INT} \\
\test{ LO-2INT hi-2INT \word{D-}}{min-2INT 1. \word{D+}} \\
\test{MIN-2INT min-2INT \word{D-}}{0.} \\
\test{MIN-2INT lo-2INT \word{D-}}{lo-2INT}
\end{testing}
\end{worddef}
\begin{worddef}[Dd]{1060}{D.{}}[d-dot]
\item \stack{d}{}
Display \param{d} in free field format.
\begin{testing}
See \tref{double:D.R}{}.
\end{testing}
\end{worddef}
\begin{worddef}{1070}{D.R}[d-dot-r]
\item \stack{d n}{}
Display \param{d} right aligned in a field \param{n} characters
wide. If the number of characters required to display \param{d}
is greater than \param{n}, all digits are displayed with no
leading spaces in a field as wide as necessary.
\see \rref{double:D.R}{}.
\begin{rationale} % A.8.6.1.1070 D.R
In \word{D.R}, the ``R'' is short for RIGHT.
\end{rationale}
\begin{testing}\ttfamily\obeyspaces
MAX-2INT 71 73 \word{M*/} \word{2CONSTANT} dbl1 \\
MIN-2INT 73 79 \word{M*/} \word{2CONSTANT} dbl2
\word{:} d>ascii \word{p} d -{}- caddr u ) \\
\tab \word{DUP} \word{toR} \word{num-start} \word{DABS} \word{numS} \word{Rfrom} \word{SIGN} \word{num-end} \tab \word{p} -{}- caddr1 u ) \\
\tab \word{HERE} \word{SWAP} \word{2DUP} \word{2toR} \word{CHARS} \word{DUP} \word{ALLOT} \word{MOVE} \word{2Rfrom} \\
\word{;}
dbl1 d>ascii \word{2CONSTANT} "dbl1" \\
dbl2 d>ascii \word{2CONSTANT} "dbl2"
\word{:} DoubleOutput \\
\tab \word{CR} \word{.q} You should see lines duplicated:" \word{CR} \\
\tab 5 \word{SPACES} "dbl1" \word{TYPE} \word{CR} \\
\tab 5 \word{SPACES} dbl1 \word{Dd} \word{CR} \\
\tab 8 \word{SPACES} "dbl1" \word{DUP} \word{toR} \word{TYPE} \word{CR} \\
\tab 5 \word{SPACES} dbl1 \word{Rfrom} 3 \word{+} \word{D.R} \word{CR} \\
\tab 5 \word{SPACES} "dbl2" \word{TYPE} \word{CR} \\
\tab 5 \word{SPACES} dbl2 \word{Dd} \word{CR} \\
\tab 10 \word{SPACES} "dbl2" \word{DUP} \word{toR} \word{TYPE} \word{CR} \\
\tab 5 \word{SPACES} dbl2 \word{Rfrom} 5 \word{+} \word{D.R} \word{CR} \\
\word{;}
\test{DoubleOutput}{}
\end{testing}
\end{worddef}
\begin{worddef}[D0less]{1075}{D0<}[d-zero-less]
\item \stack{d}{flag}
\param{flag} is true if and only if \param{d} is less than zero.
\begin{testing}
\test{ 0. \word{D0less}}{<FALSE>} \\
\test{ 1. \word{D0less}}{<FALSE>} \\
\test{ MIN-INT 0 \word{D0less}}{<FALSE>} \\
\test{ 0 MAX-INT \word{D0less}}{<FALSE>} \\
\test{ MAX-2INT \word{D0less}}{<FALSE>} \\
\test{ -1. \word{D0less}}{<TRUE> } \\
\test{ MIN-2INT \word{D0less}}{<TRUE> }
\end{testing}
\end{worddef}
\begin{worddef}{1080}{D0=}[d-zero-equals]
\item \stack{xd}{flag}
\param{flag} is true if and only if \param{xd} is equal to zero.
\begin{testing}
\test{ 1. \word{D0=}}{<FALSE>} \\
\test{MIN-INT 0 \word{D0=}}{<FALSE>} \\
\test{ MAX-2INT \word{D0=}}{<FALSE>} \\
\test{ -1 MAX-INT \word{D0=}}{<FALSE>} \\
\test{ 0. \word{D0=}}{<TRUE> } \\
\test{ -1. \word{D0=}}{<FALSE>} \\
\test{ 0 MIN-INT \word{D0=}}{<FALSE>}
\end{testing}
\end{worddef}
\begin{worddef}{1090}{D2*}[d-two-star]
\item \stack{xd_1}{xd_2}
\param{xd_2} is the result of shifting \param{xd_1} one bit
toward the most-significant bit, filling the vacated
least-significant bit with zero.
\begin{testing}
\test{ 0. \word{D2*}}{0. \word{D2*}} \\
\test{MIN-INT 0 \word{D2*}}{0 1} \\
\test{ HI-2INT \word{D2*}}{MAX-2INT 1. \word{D-}} \\
\test{ LO-2INT \word{D2*}}{MIN-2INT}
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}{1100}{D2/}[d-two-slash]
\item \stack{xd_1}{xd_2}
\param{xd_2} is the result of shifting \param{xd_1} one bit
toward the least-significant bit, leaving the most-significant
bit unchanged.
\begin{testing}
\test{ 0. \word{D2/}}{0. } \\
\test{ 1. \word{D2/}}{0. } \\
\test{ 0 1 \word{D2/}}{MIN-INT 0} \\
\test{MAX-2INT \word{D2/}}{HI-2INT } \\
\test{ -1. \word{D2/}}{-1. } \\
\test{MIN-2INT \word{D2/}}{LO-2INT }
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}[Dless]{1110}{D<}[d-less-than]
\item \stack{d_1 d_2}{flag}
\param{flag} is true if and only if \param{d_1} is less than
\param{d_2}.
\begin{testing}
\test{ 0. 1. \word{Dless}}{<TRUE> } \\
\test{ 0. 0. \word{Dless}}{<FALSE>} \\
\test{ 1. 0. \word{Dless}}{<FALSE>} \\
\test{ -1. 1. \word{Dless}}{<TRUE> } \\
\test{ -1. 0. \word{Dless}}{<TRUE> } \\
\test{ -2. -1. \word{Dless}}{<TRUE> } \\
\test{ -1. -2. \word{Dless}}{<FALSE>} \\
\test{ -1. MAX-2INT \word{Dless}}{<TRUE> } \\
\test{MIN-2INT MAX-2INT \word{Dless}}{<TRUE> } \\
\test{MAX-2INT -1. \word{Dless}}{<FALSE>} \\
\test{MAX-2INT MIN-2INT \word{Dless}}{<FALSE>}
\test{MAX-2INT \word{2DUP} -1. \word{D+} \word{Dless}}{<FALSE>} \\
\test{MIN-2INT \word{2DUP} 1. \word{D+} \word{Dless}}{<TRUE> }
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}{1120}{D=}[d-equals]
\item \stack{xd_1 xd_2}{flag}
\param{flag} is true if and only if \param{xd_1} is bit-for-bit
the same as \param{xd_2}.
\begin{testing}
\test{ -1. -1. \word{D=}}{<TRUE> } \\
\test{ -1. 0. \word{D=}}{<FALSE>} \\
\test{ -1. 1. \word{D=}}{<FALSE>} \\
\test{ 0. -1. \word{D=}}{<FALSE>} \\
\test{ 0. 0. \word{D=}}{<TRUE> } \\
\test{ 0. 1. \word{D=}}{<FALSE>} \\
\test{ 1. -1. \word{D=}}{<FALSE>} \\
\test{ 1. 0. \word{D=}}{<FALSE>} \\
\test{ 1. 1. \word{D=}}{<TRUE> }
\test{ 0 -1 0 -1 \word{D=}}{<TRUE> } \\
\test{ 0 -1 0 0 \word{D=}}{<FALSE>} \\
\test{ 0 -1 0 1 \word{D=}}{<FALSE>} \\
\test{ 0 0 0 -1 \word{D=}}{<FALSE>} \\
\test{ 0 0 0 0 \word{D=}}{<TRUE> } \\
\test{ 0 0 0 1 \word{D=}}{<FALSE>} \\
\test{ 0 1 0 -1 \word{D=}}{<FALSE>} \\
\test{ 0 1 0 0 \word{D=}}{<FALSE>} \\
\test{ 0 1 0 1 \word{D=}}{<TRUE> }
\test{MAX-2INT MIN-2INT \word{D=}}{<FALSE>} \\
\test{MAX-2INT 0. \word{D=}}{<FALSE>} \\
\test{MAX-2INT MAX-2INT \word{D=}}{<TRUE> } \\
\test{MAX-2INT HI-2INT \word{D=}}{<FALSE>} \\
\test{MAX-2INT MIN-2INT \word{D=}}{<FALSE>} \\
\test{MIN-2INT MIN-2INT \word{D=}}{<TRUE> } \\
\test{MIN-2INT LO-2INT \word{D=}}{<FALSE>} \\
\test{MIN-2INT MAX-2INT \word{D=}}{<FALSE>}
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}[DtoS]{1140}{D>S}[d-to-s]
\item \stack{d}{n}
\param{n} is the equivalent of \param{d}. An ambiguous condition
exists if \param{d} lies outside the range of a signed single-cell
number.
\see \rref{double:DtoS}{}.
\begin{rationale} % A.8.6.1.1140 D>S
An alias for \word[core]{DROP} that conveys the intent to convert
a double-cell to a single-cell integer. The original intention of this
word was to support signed-number representations other than
two's complement.
\end{rationale}
\begin{implement} % I.8.6.1.1140 D>S
\word{:} \word{DtoS} \word{p} d -{}- n ) \\
\tab \word{DROP} \\
\word{;} \\[1ex]
\end{implement}
\begin{testing} % T.8.6.1.1140 D>S
\test{ 1234 0 \word{DtoS}}{ 1234 } \\
\test{ -1234 -1 \word{DtoS}}{-1234 } \\
\test{MAX-INT 0 \word{DtoS}}{MAX-INT} \\
\test{MIN-INT -1 \word{DtoS}}{MIN-INT}
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}{1160}{DABS}[d-abs]
\item \stack{d}{ud}
\param{ud} is the absolute value of \param{d}.
\begin{testing}
\test{ 1. \word{DABS}}{1. } \\
\test{ -1. \word{DABS}}{1. } \\
\test{MAX-2INT \word{DABS}}{MAX-2INT} \\
\test{MIN-2INT 1. \word{D+} \word{DABS}}{MAX-2INT}
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}{1210}{DMAX}[d-max]
\item \stack{d_1 d_2}{d_3}
\param{d_3} is the greater of \param{d_1} and \param{d_2}.
\begin{testing}
\test{ 1. 2. \word{DMAX}}{ 2. } \\
\test{ 1. 0. \word{DMAX}}{ 1. } \\
\test{ 1. -1. \word{DMAX}}{ 1. } \\
\test{ 1. 1. \word{DMAX}}{ 1. } \\
\test{ 0. 1. \word{DMAX}}{ 1. } \\
\test{ 0. -1. \word{DMAX}}{ 0. } \\
\test{ -1. 1. \word{DMAX}}{ 1. } \\
\test{ -1. -2. \word{DMAX}}{-1. }
\test{MAX-2INT HI-2INT \word{DMAX}}{MAX-2INT} \\
\test{MAX-2INT MIN-2INT \word{DMAX}}{MAX-2INT} \\
\test{MIN-2INT MAX-2INT \word{DMAX}}{MAX-2INT} \\
\test{MIN-2INT LO-2INT \word{DMAX}}{LO-2INT }
\test{MAX-2INT 1. \word{DMAX}}{MAX-2INT} \\
\test{MAX-2INT -1. \word{DMAX}}{MAX-2INT} \\
\test{MIN-2INT 1. \word{DMAX}}{ 1. } \\
\test{MIN-2INT -1. \word{DMAX}}{-1. }
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}{1220}{DMIN}[d-min]
\item \stack{d_1 d_2}{d_3}
\param{d_3} is the lesser of \param{d_1} and \param{d_2}.
\begin{testing}
\test{ 1. 2. \word{DMIN}}{ 1. } \\
\test{ 1. 0. \word{DMIN}}{ 0. } \\
\test{ 1. -1. \word{DMIN}}{-1. } \\
\test{ 1. 1. \word{DMIN}}{ 1. } \\
\test{ 0. 1. \word{DMIN}}{ 0. } \\
\test{ 0. -1. \word{DMIN}}{-1. } \\
\test{ -1. 1. \word{DMIN}}{-1. } \\
\test{ -1. -2. \word{DMIN}}{-2. }
\test{MAX-2INT HI-2INT \word{DMIN}}{HI-2INT } \\
\test{MAX-2INT MIN-2INT \word{DMIN}}{MIN-2INT} \\
\test{MIN-2INT MAX-2INT \word{DMIN}}{MIN-2INT} \\
\test{MIN-2INT LO-2INT \word{DMIN}}{MIN-2INT}
\test{MAX-2INT 1. \word{DMIN}}{ 1. } \\
\test{MAX-2INT -1. \word{DMIN}}{-1. } \\
\test{MIN-2INT 1. \word{DMIN}}{MIN-2INT} \\
\test{MIN-2INT -1. \word{DMIN}}{MIN-2INT}
\end{testing}
\end{worddef}
\vspace*{-2ex}
\begin{worddef}{1230}{DNEGATE}[d-negate]
\item \stack{d_1}{d_2}
\param{d_2} is the negation of \param{d_1}.
\begin{testing}
\test{ 0.\ \word{DNEGATE}}{ 0.} \\
\test{ 1.\ \word{DNEGATE}}{-1.} \\
\test{ -1.\ \word{DNEGATE}}{ 1.} \\
\test{max-2int \word{DNEGATE}}{min-2int \word{SWAP} \word{1+} \word{SWAP}} \\
\test{min-2int \word{SWAP} \word{1+} \word{SWAP} \word{DNEGATE}}{max-2int}
\end{testing}
\end{worddef}
\begin{worddef}{1820}{M*/}[m-star-slash]
\item \stack{d_1 n_1 +n_2}{d_2}
Multiply \param{d_1} by \param{n_1} producing the triple-cell
intermediate result $t$. Divide $t$ by \param{+n_2} giving the
double-cell quotient \param{d_2}. An ambiguous condition exists
if \param{+n_2} is zero or negative, or the quotient lies outside
of the range of a double-precision signed integer.
\see \rref{double:M*/}{}.
\begin{rationale} % A.8.6.1.1820 M*/
\word{M*/} was once described by Chuck Moore as the most
useful arithmetic operator in Forth. It is the main workhorse
in most computations involving double-cell numbers. Note that
some systems allow signed divisors. This can cost a lot in
performance on some CPUs. The requirement for a positive
divisor has not proven to be a problem.
\end{rationale}
\begin{testing}\ttfamily
\textdf{To correct the result if the division is floored,
only used when necessary, i.e., negative quotient and
remainder $\not=$ 0.}
\word{:} ?floored \word{[} -3 2 \word{/} -2 \word{=} \word{]} \word{LITERAL} \word{IF} 1.\ \word{D-} \word{THEN} \word{;}
\small
\test{ 5. 7 11 \word{M*/}}{ 3.} \\
\test{ 5. -7 11 \word{M*/}}{-3. ?floored} \\ %\tab \word{bs} \textdf{floored -4.} \\
\test{ -5. 7 11 \word{M*/}}{-3. ?floored} \\ %\tab \word{bs} \textdf{floored -4.} \\
\test{ -5. -7 11 \word{M*/}}{ 3.} \\
\test{MAX-2INT 8 16 \word{M*/}}{HI-2INT} \\
\test{MAX-2INT -8 16 \word{M*/}}{HI-2INT \word{DNEGATE} ?floored} \\ %\tab \word{bs} \textdf{floored subtract 1} \\
\test{MIN-2INT 8 16 \word{M*/}}{LO-2INT} \\
\test{MIN-2INT -8 16 \word{M*/}}{LO-2INT \word{DNEGATE}}
\test{MAX-2INT MAX-INT MAX-INT \word{M*/}}{MAX-2INT} \\
\test{MAX-2INT MAX-INT \word{2/} MAX-INT \word{M*/}}{MAX-INT 1- HI-2INT \word{NIP}} \\
\test{MIN-2INT LO-2INT \word{NIP} \word{DUP} \word{NEGATE} \word{M*/}}{MIN-2INT} \\
\test{MIN-2INT LO-2INT \word{NIP} \word{1-} MAX-INT \word{M*/}}{MIN-INT 3 + HI-2INT \word{NIP} 2 \word{+}} \\
\test{MAX-2INT LO-2INT \word{NIP} \word{DUP} \word{NEGATE} \word{M*/}}{MAX-2INT \word{DNEGATE}} \\
\test{MIN-2INT MAX-INT \word{DUP} \word{M*/}}{MIN-2INT}
\end{testing}
\end{worddef}
\begin{worddef}{1830}{M+}[m-plus]
\item \stack{d_1|ud_1 n}{d_2|ud_2}
Add \param{n} to \param{d_1|ud_1}, giving the sum \param{d_2|ud_2}.
\see \rref{double:M+}{}.
\begin{rationale} % A.8.6.1.1830 M+
\word{M+} is the classical method for integrating.
\end{rationale}
\begin{testing}
\test{HI-2INT 1 \word{M+}}{HI-2INT 1. \word{D+}} \\
\test{MAX-2INT -1 \word{M+}}{MAX-2INT -1. \word{D+}} \\
\test{MIN-2INT 1 \word{M+}}{MIN-2INT 1. \word{D+}} \\
\test{LO-2INT -1 \word{M+}}{LO-2INT -1. \word{D+}}
\end{testing}
\end{worddef}
\subsection{Double-Number extension words} % 8.6.2
\extended
\begin{worddef}{0420}{2ROT}[two-rote]
\item \stack{x_1 x_2 x_3 x_4 x_5 x_6}{x_3 x_4 x_5 x_6 x_1 x_2}
Rotate the top three cell pairs on the stack bringing cell pair
\param{x_1 x_2} to the top of the stack.
\begin{testing}
\test{ 1. 2. 3. \word{2ROT}}{ 2. 3. 1.} \\
\test{MAX-2INT MIN-2INT 1. \word{2ROT}}{MIN-2INT 1. MAX-2INT}
\end{testing}
\end{worddef}
% ---------------------------------------------------------
\enlargethispage{6ex}
\begin{worddef}{0435}{2VALUE}[two-value]%[X:2value]
\item \stack{x_1 x_2 "<spaces>name"}{}
Skip leading space delimiters. Parse \param{name} delimited by a
space. Create a definition for \param{name} with the execution
semantics defined below, with an initial value of \param{x_1 x_2}.
\param{name} is referred to as a ``two-value''.
\execute[name]
\stack{}{x_1 x_2}
Place cell pair \param{x_1 x_2} on the stack. The value of
\param{x_1 x_2} is that given when \param{name} was created,
until the phrase ``\param{x_1 x_2} \word{TO} \param{name}'' is
executed, causing a new cell pair \param{x_1 x_2} to be assigned
to \param{name}.
\runtime[\word{TO} \param{name}]
\stack{x_1 x_2}{}
Assign the cell pair \param{x_1 x_2} to \param{name}.
\see \xref{usage:parsing} and \wref{core:TO}{},
\rref{double:2VALUE}{}.
\begin{rationale} % R.8.6.2.0435 2VALUE
Typical use:
\begin{quote}\ttfamily
\word{:} fn1 \word{Sq} filename" \word{;} \\
fn1 \word{2VALUE} myfile \\
myfile \word[file]{INCLUDED} \\[2ex]
\word{:} fn2 \word{Sq} filename2" \word{;} \\
fn2 \word{TO} myfile \\
myfile \word[file]{INCLUDED}
\end{quote}
\end{rationale}
\begin{implement} % I.8.6.2.0435 2VALUE
\dffamily
The implementation of \word{TO} to include \word{2VALUE}s
requires detailed knowledge of the host implementation of
\word{VALUE} and \word{TO}, which is the main reason why
\word{2VALUE} should be standardized. The order in which
the two cells are stored in memory is not specified in the
definition for \word{2VALUE} but this reference implementation
has to assume one ordering --- this is not intended to be
definitive.
\begin{quote}\ttfamily
\word{:} \word{2VALUE} \word{p} x1 x2 -{}- ) \\
\tab \word{CREATE} \word{,} \word{,} \\
\tab \word{DOES} \word{2@} \word{p} -{}- x1 x2 ) \\
\word{;}
\end{quote}
The corresponding implementation of \word{TO} disregards the
issue that \word{TO} must also work for integer \word{VALUE}s
and locals.
\begin{quote}\ttfamily
\word{:} \word{TO} \word{p} x1 x2 "<spaces>name" -{}- ) \\
\tab \word{'} \word{toBODY} \\
\tab \word{STATE} \word{@} \word{IF} \\
\tab[2] \word{POSTPONE} \word{2LITERAL} \word{POSTPONE} \word{2!} \\
\tab \word{ELSE} \\
\tab[2] \word{2!} \\
\tab \word{THEN} \\
\word{;} \word{IMMEDIATE}
\end{quote}
\end{implement}
\begin{testing}\ttfamily % T.8.6.2.0435 2VALUE
\test{1 2 \word{2VALUE} t2val}{} \\
\test{t2val}{1 2} \\[2ex]
\test{3 4 \word{TO} t2val}{} \\
\test{t2val}{3 4} \\[2ex]
\word{:} sett2val t2val \word{2SWAP} \word{TO} t2val \word{;} \\
\test{5 6 sett2val t2val}{3 4 5 6}
\end{testing}
\end{worddef}
% ---------------------------------------------------------
\begin{worddef}[DUless]{1270}{DU<}[d-u-less]
\item \stack{ud_1 ud_2}{flag}
\param{flag} is true if and only if \param{ud_1} is less than
\param{ud_2}.
\begin{testing}
\test{ 1. 1. \word{DUless}}{<FALSE>} \\
\test{ 1. -1. \word{DUless}}{<TRUE> } \\
\test{ -1. 1. \word{DUless}}{<FALSE>} \\
\test{ -1. -2. \word{DUless}}{<FALSE>}
\test{MAX-2INT HI-2INT \word{DUless}}{<FALSE>} \\
\test{ HI-2INT MAX-2INT \word{DUless}}{<TRUE> } \\
\test{MAX-2INT MIN-2INT \word{DUless}}{<TRUE> } \\
\test{MIN-2INT MAX-2INT \word{DUless}}{<FALSE>} \\
\test{MIN-2INT LO-2INT \word{DUless}}{<TRUE> }
\end{testing}
\end{worddef}