Home > CBM > BASIC > Keywords > (equal) 180 Subpages: (divide), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor |
| Keyword | Abbreviation | Token (hex) | Version(s) | Classification |
| = | none | B2 | 1.0 to 7.0 | Operator (4) |
subject = comparator
~ or ~
subject = < comparator
~ or ~
subject < = comparator
~ or ~
subject = > comparator
~ or ~
subject > = comparator
| Parameters | Type | Legal Value(s) | Default Value | Note(s) |
| subject | Numeric or String | any | | |
| comparator | Numeric or String | any | | Type must match subject (numeric or string) |
| Returns | Type | Value(s) | Note(s) |
| result | Boolean | -1 (true) or 0 (false) | |
Evaluate a comparative relation.
The equal operator returns a boolean result; it may be used in one of three ways:
- In the first Syntax shown above, known as "equal to ",
if the subject is not equal to the comparator
then -1 (for true) is returned; otherwise 0 (for false) is returned.
Hopefully it is obvious how this works for numeric values.
For comparison of strings, if the lengths are different, the result is false.
Otherwise the pair of PETSCII codes from each corresponding position of the two strings is compared.
The first code pair not equal between the two strings will return a false result.
Finally, if both strings are the same length and have the same codes (they are equal) the result is true.
- The equal operator may be combined with the less operator
to perform a "less than or equal to" comparison as shown in the second and third forms of Syntax above.
In these cases, if the subject is less-than or equal-to the comparator
then -1 (for true) is returned; otherwise 0 (for false) is returned.
Hopefully it is obvious how this works for numeric values.
For comparison of strings, the pair of PETSCII codes from each corresponding position
of the two strings is compared. The first code pair not equal between the two strings
will return the result, which is simply the numeric relation of the two different codes.
If all codes match up to the shorter of the two strings,
then the shorter string is considered "less" (returns true if subject is the shorter string).
If both strings are the same length and have the same codes (they are equal) the result is also true.
- The equal operator may be combined with the more operator
to perform a "greater than or equal to" comparison, as shown in the last two forms of the Syntax above.
In these cases, if the subject is greater-than or equal-to the comparator
then -1 (for true) is returned; otherwise 0 (for false) is returned.
Hopefully it is obvious how this works for numeric values. For comparison of strings,
the pair of PETSCII codes from each corresponding position of the two strings is compared.
The first code pair not equal between the two strings will return the result,
which is simply the numeric relation of the two different codes.
If all codes match up to the shorter of the two strings,
then the longer string is considered "more" (returns true if subject is the longer string).
If both strings are the same length and have the same codes (they are equal) the result is also true.
It is interesting that BASIC allows some operators to be combined to form new operators (as shown here),
but unfortunately it is not very general. For example you can't combine the not and less operators
to form a NOT < operator -- you have to do it manually!
Manual operations are error prone because some people don't know that NOT <
is equivallant to greater-than-or-equal-to ( >= ) and is different from strictly more ( > ).
Heck, even people who do know better will occassionally make mistakes.
Similarly, combining NOT with AND to form NAND is forbidden as well.
Another interesting thing is spaces may appear between the operators when combining them
and the order of combination is not important; in programming many languages (including some BASICs),
this "easy syntax" will fail.
It should also be noted that all forms are generally considered unsafe with floating-point numbers
due to involvement of equality. Specifically, the nature of floating-pointing numbers means
there will often be subtle rounding errors that will make two numbers that should be the same
(may even print as the same value) will not be exactly the same, leading to an invalid result.
This happens with any finite-representation of real numbers (floating-point in this case)
and is not a blemish on CBM. On the contrary, CBM 8-bit computers use a 32-bit mantissa
which is more precision than most 8-bit BASICs or even the "float" type in modern languages
such as Visual BASIC and C which use a 24-bit mantissa.
Finally, another use of the equal token, totally unrelated to relational comparison,
is with the assignment of values to variables. See LET and MID$.
For the opposite case (inequality) see either the less or more operators (< or >).
Relational operators (like equal) are frequently used with IF, DO, and LOOP.
(less), (more), LET,
MID$
ASC, BASIC Expressions,
DO, IF, LOOP
© H2Obsession, 2014
|