Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

keyword - Logical AND in Forth?

I know the AND word defines binary and... but what defines logical and?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

2 Answers

0 votes
by (71.8m points)

The same word, AND, is also used for logical and. But the two input values to AND are recommended to be well-formed flags; true and false are represented by two values, bits all set (-1) and bits all unset (0). Other values than these may work as true (as in C), but it may lead to subtle errors.

All comparison operators return well-formed flags, but for instance - does not. The following evaluates to false (0).

7 5 - 7 3 - AND

AND gets bit patterns 100 and 010. The result is 0 (as it does the bitwise and).

References:

  1. Bit Manipulations in Forth, part of Learning Forth Bit by Bit.
  2. Section "A Little Logic" in Chapter 4 of Starting Forth.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
0 votes
by (100 points)
Saw this done recently on Project Euler:

Logical AND can be performed using multiplication! But the resulting value still won't be a "well-formed flag".
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...