home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / cmp.1 < prev    next >
Text File  |  2020-01-01  |  1KB  |  31 lines

  1. # Macro CMP - Compare integers even if they are bigger than machine word size
  2. # \%1 = arithmetic comparison operator (>, <, =, etc, listed below)
  3. # \%2 = first number (unsigned decimal integer of any length)
  4. # \%3 = second number (ditto)
  5. #
  6. # Succeeds if comparison is true, fails if not, or if called incorrectly.
  7. # Example:
  8. #  cmp > 1 2
  9. #  if success { commands if true } else { commands if false }
  10. #
  11. # F. da Cruz, Columbia U, 18 December 2007
  12. #
  13. def cmp {
  14.     .\%9 = 24  # max number of digits - you can make this any size you want
  15.     if < \v(argc) 4 end 1 "Usage: CMD operator number number"
  16.     if not integer \%2 end 1 "CMD: operand not numeric"
  17.     if not integer \%3 end 1 "CMD: operand not numeric"
  18.     .\%2 := \flpad(\%2,\%9,0)
  19.     .\%3 := \flpad(\%3,\%9,0)
  20.     switch \%1 {
  21.       :<,  if LLT \%2 \%3 end 0, end 1
  22.       :>,  if LGT \%2 \%3 end 0, end 1
  23.       :=,  if EQU \%2 \%3 end 0, end 1
  24.       :==, if EQU \%2 \%3 end 0, end 1
  25.       :!=, if NOT EQU \%2 \%3 end 0, end 1
  26.       :<=, if NOT LGT \%2 \%3 end 0, end 1
  27.       :>=, if NOT LLT \%2 \%3 end 0, end 1
  28.       :default, end 2 "CMD: Bad operator '\%1'"
  29.     }
  30. }
  31.