Any simpler way towards "To the power of..." in DOS?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Any simpler way towards "To the power of..." in DOS?

#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:

Re: Any simpler way towards "To the power of..." in DOS?

#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 :oops:

It's related:
SET/A: Macro to expand function results in SET /A expression
viewtopic.php?f=3&t=2704&start=0


Thanks Aacini :wink: :!:

Aacini
Expert
Posts: 1886
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Any simpler way towards "To the power of..." in DOS?

#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

Re: Any simpler way towards "To the power of..." in DOS?

#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... :roll:

Post Reply