v11 idea - Numeric range comparison operators

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
It's a common task to check that a numeric value falls within a certain range. It would simplify batch files if TCC had native range-check operators for use in IF, IFF, @IF (and perhaps even SWITCH/CASE?) I'm thinking something like WITHIN min TO max for an inclusive range test, and BETWEEN min AND max for an exclusive test. So, for example,

IF expr WITHIN min TO max ECHO YES

would work much like

IF expr GE min .AND. expr LE max ECHO YES



would work much like

IF expr GT min .AND. expr LT max ECHO YES

but with three differences. First, TCC would require expr, min, and max all to be numeric, and give an error if any value is non-numeric. Second, TCC would check that min <= max (WITHIN) or min < max (BETWEEN), and issue an error otherwise. Finally, expr would be evaluated only once.

I chose TO and AND because they seem intuitive to me in context. In practice, I suppose the parser might accept either TO or AND between values in either test. Other types of range tests might also be useful: ATLEAST / BUTNOT for min <= expr < max (tax brackets?), or ABOVE / UPTO for min < expr <= max....
Thread starter Similar threads Forum Replies Date
S Suggestions 9
G Suggestions 3
p.f.moore Suggestions 0
J Suggestions 2
Charles Dye Suggestions 3