Page 1 of 1
Any simpler way towards "To the power of..." in DOS?
Posted: 11 Apr 2012 10:51
by tinfanide
Code: Select all
@ECHO OFF
CALL :ToPower 3 2
GOTO :EOF
:ToPower
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A n=1
FOR /L %%A IN (1,1,%2) DO SET /A n=!n!*%1
ECHO !n!
ENDLOCAL
GOTO :EOF
Any simpler way in DOS?
Arithmetic operators for powering a number?
Re: Any simpler way towards "To the power of..." in DOS?
Posted: 11 Apr 2012 16:00
by Ed Dyreen
'
I'm not sure this will help tinfanide, it's a bit complex, I'm sorry I have little time
It's related:
SET/A: Macro to expand function results in SET /A expression
viewtopic.php?f=3&t=2704&start=0Thanks
Aacini

Re: Any simpler way towards "To the power of..." in DOS?
Posted: 11 Apr 2012 17:42
by Aacini
The simpler way is this:
Code: Select all
:ToPower base power
SET n=1
FOR /L %%A IN (1,1,%2) DO SET /A n*=%1
ECHO %n%
GOTO :EOF
Re: Any simpler way towards "To the power of..." in DOS?
Posted: 12 Apr 2012 09:45
by tinfanide
Yes, no need to use EnableDelayedExpansion.
And still reading those complicated codes... hardest ever to me...
