Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

v11 idea - Numeric range comparison operators

Charles Dye

Super Moderator
May
5,243
154
Staff member
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....
 
Back
Top
[FOX] Ultimate Translator
Translate