Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
tinfanide
- Posts: 117
- Joined: 05 Sep 2011 09:15
#1
Post
by tinfanide » 11 Apr 2012 10:51
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?
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#2
Post
by Ed Dyreen » 11 Apr 2012 16:00
'
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
-
Aacini
- Expert
- Posts: 1886
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#3
Post
by Aacini » 11 Apr 2012 17:42
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
-
tinfanide
- Posts: 117
- Joined: 05 Sep 2011 09:15
#4
Post
by tinfanide » 12 Apr 2012 09:45
Yes, no need to use EnableDelayedExpansion.
And still reading those complicated codes... hardest ever to me...