CMath — Evaluate a math expression at the command line.

To evaluate a math expression, type a colon followed by the expression. Then press Enter:

:1+2*3

The answer, 7, will be displayed below your expression. It will also be saved to the environment variable ANS. You can use this variable in your next expression:

:ans*2

Just remember that the value of ANS changes every time you use CMath. After the second line, ANS will be 14, not 7.


CMath calls the same function that @EVAL uses internally. You can use any operator or function that is legal in @EVAL:

:log(100)


set r=4
:pi*r**2



You do not need to quote or escape special characters:

:(1+2)*3


:1 << 8


:1024 >> 3


:5 & 9


:5 | 9


:5 ^ 9



The one special character which needs attention is the percent sign. If you want to use a percent sign as the modulo operator, you will need to double it. (But it’s probably easier just to type MOD.)

:100%%7


:100 mod 7



You do not need a percent sign before environment variables. You do need a percent sign before internal variables and variable functions:

:%_pid =x


:3 * %@dec[foo]



@EVAL’s built-in functions do not take a percent sign:

set n=52
set r=5
:fact(n) / fact(n-r) / fact(r)