# 6. More data types

6.1. Signal and unsigned values
Let the interpreter enter the following command line:

65535.

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

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.

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

Symbols in the description of the stack effect:

• n - Signed one-word value (number),
• u - unsigned number without sign,
• d - doubleword,
• ud - unsigned doubleword.

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 21:29, local time: 2024/5/23 08:11, TOP NEW HELP FIND:  44.210.83.132:LOG IN

 ©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?Please DO link to this page! Digg it! / MAKE! 6. More data types

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant"

 PICList 2024 contributors: o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr.

.