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

v11 idea - Numeric range comparison operators

Discussion in 'Suggestions' started by Charles Dye, Feb 1, 2009.

  1. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    May 20, 2008
    Likes Received:
    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


    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....

Share This Page