home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
scripts
/
ckermit
/
cmp.1
< prev
next >
Wrap
Text File
|
2007-12-17
|
1KB
|
31 lines
# Macro CMP - Compare integers even if they are bigger than machine word size
# \%1 = arithmetic comparison operator (>, <, =, etc, listed below)
# \%2 = first number (unsigned decimal integer of any length)
# \%3 = second number (ditto)
#
# Succeeds if comparison is true, fails if not, or if called incorrectly.
# Example:
# cmp > 1 2
# if success { commands if true } else { commands if false }
#
# F. da Cruz, Columbia U, 18 December 2007
#
def cmp {
.\%9 = 24 # max number of digits - you can make this any size you want
if < \v(argc) 4 end 1 "Usage: CMD operator number number"
if not integer \%2 end 1 "CMD: operand not numeric"
if not integer \%3 end 1 "CMD: operand not numeric"
.\%2 := \flpad(\%2,\%9,0)
.\%3 := \flpad(\%3,\%9,0)
switch \%1 {
:<, if LLT \%2 \%3 end 0, end 1
:>, if LGT \%2 \%3 end 0, end 1
:=, if EQU \%2 \%3 end 0, end 1
:==, if EQU \%2 \%3 end 0, end 1
:!=, if NOT EQU \%2 \%3 end 0, end 1
:<=, if NOT LGT \%2 \%3 end 0, end 1
:>=, if NOT LLT \%2 \%3 end 0, end 1
:default, end 2 "CMD: Bad operator '\%1'"
}
}