v11 idea - Numeric range comparison operators

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,376
39
Albuquerque, NM
prospero.unm.edu
#1
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

and

IF expr BETWEEN min AND 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....