Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

> (more)

Keyword Abbreviation Token (hex) Version(s) Classification
> none B3 1.0 to 7.0 Operator (4)

  Syntax  
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)
 
  Purpose  
Evaluate a comparative relation.

 
  Remarks  
The more operator returns a boolean result; it may be used in one of three ways:
  • In the first Syntax shown above, known as "greater than", if the subject is greater than 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 false.

  • The more operator may be combined with the equal operator to perform a "greater than or equal to" comparison as shown in the second and third forms of 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 a 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.

  • The more operator may be combined with the less operator to perform a "not equal" (or, if you prefer, "less or more") comparison, as shown in the last two forms of the Syntax above.  In these cases, 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 true.  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 true result.  Finally, if both strings are the same length and have the same codes (they are equal) the result is false.
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 the first form (strictly greater than) is generally considered safe with floating-point numbers, while the others are not due the 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 is true 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.
 
Relational operators (like more) are frequently used with IF, DO, and LOOP.
  
  Compare With  
 
  Contrast With  
 
  See Also  

© H2Obsession, 2014
Comments