6.1.
Signal and unsigned
values
Let the interpreter enter the following command line:
65535.
The
answer is: -1
And we did not put -1 on the stack.
Or is it?
On the 65535 16 bits:
1111 1111 1111 1111
The . the number found in the vermine is considered to be signed, ie the first bit is a sign bit, and if it is 1 then the number is negative. Negative numbers are used to represent the sum of the two binary series representing the number and its opposite. This takes 16 bits so that the sum of the numbers -1 and 1 is 2 ^ 16, i.e.,
1 0000 0000 0000 0000
(the high-ranking 1 is already out of sixteen bits, the 0 tickets remain). And really:
1111 1111 1111 1111+ 1 1 0000 0000 0000 0000
or to stay at the more homely tithing number system:
65535 + 1 = 65536 = 2 ^ 16
We can play the same thing backwards; we need to know the word that considers the number at the top of the stack as unsigned, and so write it out.
U. (u ---)
U
is the abbreviation for the "unsigned" word in the name of the word and in
the mark of the stack.
THE
-2 U.
the answer to the command line is 65534. (As 2 is added to 65534 for 2 ^ 16).
6.2.
What about too many numbers?
We can see that 16 bits of 2 ^ 16-1 = 65535 can not exist.
The first digits of the higher
values simply "leak" and are lost.
THE
65536.
response
to the command prompt: 0. (Binary representation: 1 0000 0000 0000 0000).
THE
35537.
response
to the command prompt: 1. (binary representation: 1 0000 0000 0000 0001)
Similarly,
35537 30000 +.
1 is the response. FORTH does not handle overflow, we have to pay attention to ourselves.
6.3.
Duplications
If a number does not fit in one word, it can be represented in two, that
is, in a 32-bit duplicate.
The
duplicate word is located in the worm, with its higher-value word (the "front")
above.
|
So, for example, the
1 0
we put a 1 doubled word in the stack. About this
D. (d ---)
can be verified; it prints the double word on the screen that consists of two top elements of the stack:
1 0 D. (the answer is 1)
-1 -1 D. (the answer is -1)
-1 0 D. (the answer is 65535)
The dictated duplicates are shown binary in the figure below.
In
the name of D. and in the case of the bump effect, the word doubleword is
an abbreviation for the English word, although it could even be the Hungarian
"double word" version.
It can also be foolish to double the dice in the stack.
In fact:
the
numbers that have a decimal point are translated by the interpreter into
a duplicate.
|
For example:
100. D.
10.0 D.
10 D.
431567 D.
We see that
the
doubling value on the stack is not affected by the location of the decimal
point.
|
We
will be able to determine where the decimal point was (11.2).
Double words can be either signatory or unsigned as words.
Marking the unsigned double
word in the description of the stack effect: ud.
In
the description of the dowel effect, a doubling clause, i.e., represents
two elements.
|
At the end of this chapter are the words of double word and mixed arithmetic, here we only mention that a few one-word operations have the duplicate equivalent, which is missing from the fig-forth vocabulary, in the examples we make some.
one word: double word: . D. + D + ABS DABS MINUS DMINUS DUP 2DUP .R DR
6.4.
A disguised duplicate action
Combines the
splitting and division with the following word:
* / (n1 n2 n3 --- n4)
where n4 = (n1 * n2) / n3. The product n1 * n2 is stored in * / doubled, so that multiplication does not result in overflow. It does the same thing
* / MOD (n1 n2 n3 --- residual ratio)
even if we get the dividing quotient.
What was that about?
Summary
of Chapter 6
Words for unsigned, double-word and unsigned double-word values:
U. | (u ---) | Prints the unsigned value found on the screen on the screen, followed by a space. |
U * | (u1 u2 --- ud) | Adds unsigned values on the vermin; double-word, unsigned product. |
U / | (u1 u2 --- u2 u3) | Defines a tuple word with a single value, the returned u2 is the remainder of the division, u3 is the quotient. All values are unsigned. |
U < | (u1 u2 --- f) | Compare unsigned values. f is true if u1 <u2. |
D. | (d ---) | He prints the double word found on the vermin and then a space. |
DR | (dn ---) | Write the double word found in the vermin in a n width field. |
D + | (d1 d2 --- d) | Duplicate words (double-blind). |
DABS | (d --- d1) | Defines the absolute value of a double word. |
DMINUS | (d --- -d) | Deny a double word. |
M * | (n1 n2 --- d) | Multiplies multiple words, giving a double result. |
M / | (d n1 --- n2 n3) | It shares a double word with a single word value; the returned n2 is the remainder of the division, n3 is the quotient. All values are signed. (U / Signed Version.) |
M / MOD | (ud1 u2 --- u3 ud4) | It shares a double word with a single word value; ud4 is the duplicate ratio, u3 is the remainder of the division. |
Symbols in the description of the stack effect:
The latter two mark two elements in the vermin.
Examples
6.1. Write the duplicate version of the stack handling operations:
2DROP (n1 n2 ---) or (d ---) : 2DROP DROP DROP;
2SWAP (n1 n2 n3 n4 --- n3 n4 n1 n2) or (d1 d2 --- d2 d1)
: 2SWAP (n1 n2 n3 n4 n3 n4 --- n1 n2)
> R (n1 n2 n3)
ROT (n1 n2 n3)
ROT (n1 n2 n3)
R> (n1 n2 n3 n4)
ROT (n2 n3 n4 n1)
ROT (n3 n4 n1 n2)
;2OVER (d1 d2 --- d1 d2 d1)
: 2OVER (d1 --- d2 d1 d2 d1)
> R> R (d1)
2DUP (d1 d1)
R> R> (d1 d1 d2)
2SWAP (d1 d2 d1)
;2ROT (d1 d2 d3 --- d2 d3 d1)
: 2ROT (d1 d2 d3 --- d2 d3 d1)
> R> R (d1 d2)
2SWAP (d2 d1)
R> R> (d2 d1 d3)
2SWAP (d2 d3 d1)
;
6.2. Write more duplicate actions using existing ones.
D- (d1 d2 --- d-coefficient): D- DMINUS D +;
D = (d1 d2 --- f), f is true if d1 = d2
: D = DMINUS 0 = SWAP 0 = AND;
or, taking advantage of the OR to give zero only if both operands were 0:
: D = DMINUS OR 0 =;
D < (d1 d2 --- f), f is true if d1 <d2
: D- 0 <SWAP DROP;
Here, let us use the double-word difference to be negative if the sign word 1 is in the upper word, so we can ask this 0 <.
file: /Techref/language/FORTH/z80fig-Forth1_1g_files/datatypes.htm, 29KB, , updated: 2018/11/8 20:29, local time: 2024/11/5 08:04,
44.211.34.178:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.ecomorder.com/techref/language/FORTH/z80fig-Forth1_1g_files/datatypes.htm"> 6. More data types </A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to www.ecomorder.com! |
.