SET /A var\=...?

Interesting...under CMD;
c:\utils>set n=85

c:\utils>set /a "n/=2"
c:\utils>set /a "n/=2"
c:\utils>set /a "n/=2"
c:\utils>set /a "n/=2"
c:\utils>set /a "n/=2"
c:\utils>set /a "n/=2"

under TCC18;
c:\users\jlc\utils>set n=85

c:\users\jlc\utils>set /a "n/=2"

c:\users\jlc\utils>set /a "n/=2"

c:\users\jlc\utils>set /a "n/=2"

c:\users\jlc\utils>set /a "n/=2"

c:\users\jlc\utils>set /a "n/=2"

c:\users\jlc\utils>set /a "n/=2"

May 20, 2008
Syracuse, NY, USA
That may be CMD, but I'm using TCC. TCC doesn't need the quotes. I don't think CMD handles anything but integers.

And I'm talking about '\' (integer division), not '/', In TCC, if n is 85, "set /a n\=2", if it works at all, should give 42.
May 20, 2008
Syracuse, NY, USA
Not supported in CMD, so not supported in TCC. (The SET /A syntax is solely for CMD compatibility, as there's otherwise no reason to use it.)
Well, "set /a n=n\2" is easy enough. But it should be noted that TCC's "SET /A" supports much that CMD doesn't.
v:\> set /a x=sin(PI/2)
v:\> set /a x=exp(1)
v:\> set /a x=atan(1)
v:\> set /a x=log10(100)
v:\> set /a x=2**3

It should also be noted that SET /A usually involves less typing and is often faster than using @EVAL.
v:\> set zz=0

v:\> timer do i=1 to 10000 (set /q /a zz+=3)
Timer 1 on: 21:35:31
Timer 1 off: 21:35:33  Elapsed: 0:00:01.48

v:\> echo %zz

v:\> timer do i=1 to 10000 (set zz=%%@eval[zz+3])
Timer 1 on: 21:35:41
Timer 1 off: 21:35:43  Elapsed: 0:00:01.61

v:\> echo %zz


Staff member
May 14, 2008
You're timing the wrong thing. Your test is comparing the speed of a single environment update with that of a delete and a create.

Set /a updates in place; the other set has to delete the variable before adding it again. This is to allow changing the case of a variable name, which is required by some buggy apps like ClearCase.

Your argument about the difference in speed is unpersuasive. On my system it is about 7 microseconds. If you did this a hundred times a day, you'd have to run it a few centuries to make up the time you spent composing the message about @eval being slower.
May 20, 2008
Syracuse, NY, USA
I'm not really complaining (about "\=" or the speed) ... just making observations. I found it odd that SET /A lets you use almost everything @EVAL has to offer. A few exceptions are mentioned in the help, but not "\=". As for it not being supported, it does produce results, just not the intended ones, in fact, rether peculiar ones. You might think that, since "set /a n\=2" echoes "2", n is set to 2, but n remains unchanged.
May 29, 2008
Groton, CT
Looks like a parsing error where SET /A is assigning a value to envvar "n\"

Groton> set /a n\=2
Groton> set n*

Similar threads
Thread starter Title Forum Replies Date
M Fixed Set "VAR=VAL" format causes problems Support 12
vefatica SET /A var=expression=digits Support 3
vefatica SET /A "var%=N", TCC vs. CMD Support 0
V Set path permanently from within TCC? Support 3
S Debugger keeps breaking with no break point set. Support 1
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R How to? Set default application in a special folder Support 4
A How to? Set up SMTP password in TCC-RT Support 1
vefatica WAD More SET /A woes Support 4
vefatica SET /A and multidimensional array. Support 1
M How to set Path variable for non-executable file extensions in 4DOS Support 8
D Need to set Take Command font size when switching to high DPI display Support 0
P "Set" command behavior - a bug? Support 3
M How to? Set the ribbon titles to mixed case Support 1
X How to set %_INIREAD result to variable Support 5
M WAD Set statements in () causes problems Support 8
M How to? How to set a default TITLE for newly opened tab? Support 2
cxxl Set encoding for batch file Support 4
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
dcantor Documentation SET /T: missing from heading Support 0
fpefpe Documentation Set /v Support 4
vefatica What's SET /Z? Support 1
R Fixed set /r has stopped working in build 35 Support 4
BeechComer Debugger: how to set %1 variable? Support 3
fpefpe How to? Global variable set /v Support 4
fpefpe Documentation Can the title line of tcmd be set? Support 4
J How to set working directory Support 10
Jay Sage Failure of ACTIVATE to Set a Window Position Support 3
rps Fixed Win "set /p" not working in V17 build 53 Support 3
J Set environment variable from stdout of command Support 3
B How to? Pre-set _tcfolder on startup when Folders is set Auto-Hide Support 6
Dan Glynhampton Fixed @version "force" flag not working, and unable to set separator Support 3
R WAD /= size ranges not set correctly Support 5
S How to? Set the timestamp of ZIP command built archive to match latest member Support 8
Mordachai Help! How to set parameters for script I'm debugging?! Support 6
Roedy SET= Support 2
A How to? Set up a log file for all command output Support 3
M Fixed character set in dir/copy Support 3
Phileosophos Fixed TakeCommand exits upon "set [" command Support 14
R How to set comspec to point to cmd.exe? Support 5
S WAD SET problem - array element initialization Support 11
C Wildcard expansion in FOR set Support 27
vefatica SET question Support 16
T Set 1% then Echo 1% Support 9
S SET /A question; HELP nits Support 8
noahcoad copy /w to FTP does not set time stamp Support 1
M A request for a new feature for the "set" command... Support 5
cgunhouse Accessing variables set using SET /U or SET /S Support 3
D Force For to treat set of values as text, not files Support 3
vefatica Regular expressions in FOR's set? Support 10

Similar threads