Wc3C.net Logarithm
 Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar

07-08-2008, 03:15 AM   #1
Vexorian
Free Software Terrorist

Technical Director

Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Logarithm

Approximates the logarithm after 20 calls to Pow. Does someone need logarithms? I can think of some uses for them but they don't fit warcraft too much, well, just in case someone does...

JASS:
```library Logarithm

globals
private constant integer ITERATIONS=20
endglobals

function Log takes real x returns real
local real min=-88.0
local real max= 88.0
local real mid
local integer i=ITERATIONS

loop
set mid=(min+max)/2
exitwhen(i<=0)
set i=i-1
if (Pow(bj_E,mid)>=x) then
set max=mid
else
set min=mid
endif
endloop
return mid
endfunction

function Logarithm takes real base, real x returns real
local real min=-88.0
local real max= 88.0
local real mid
local integer i=ITERATIONS

loop
set mid=(min+max)/2
exitwhen(i<=0)
set i=i-1
if (Pow(base,mid)>=x) then
set max=mid
else
set min=mid
endif
endloop
return mid
endfunction

endlibrary
```
__________________
 Wc3 map optimizer 5.0 Someone should fix .wav sound in this thing. JassHelper 0.A.2.A Turns your simple code into something that is complicated enough to work.
 Wc3 map optimizer 5.0 JassHelper 0.A.2.A Xye 0.12.1 | Editor/Levels xe0.9 CS16.0 My spells jEdit modes for vJass&Zinc (v9) WarCiTy 0.2.0
Faster != more useful

07-08-2008, 04:43 AM   #2
PandaMine
Panda > You

Join Date: May 2006
Posts: 500

Submissions (4)

Well general use of logs is for caculating max time in searches (i.e. binary search).

Possibly physics might need it, but I don't really think a situation one would need it in wc3
__________________
PandaMine's Creations:
 Systems AMHS v5.2 HSAS v3.6 AFS v1.2 Tutorials Animations

 07-08-2008, 05:49 AM #3 Rising_Dusk Obscurity, the Art Projects DirectorProject Leader: OD   Join Date: Feb 2006 Posts: 9,729 Submissions (27) This is still really cool, I love mathematical code. __________________
 07-08-2008, 07:46 AM #4 d07.RiV User     Join Date: May 2008 Posts: 241 Submissions (1) You need logarithms to find negative armor knowing damage reduction, I doubt there is much use unless you made your formulas use logarithms on purpose. __________________
07-08-2008, 09:18 AM   #5
Captain Griffen

Content Director

Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Sometimes maths code is needed in strange places.

Quote:
 Originally Posted by d07.RiV You need logarithms to find negative armor knowing damage reduction, I doubt there is much use unless you made your formulas use logarithms on purpose.

Or you can itinerate it, I think, which'd be faster. Far faster.
__________________
Quote:
 Originally Posted by Earth-Fury Griffen is correct, you are not.
Quote:
 [13:32] hmm.. stil i want to have some unused women

07-08-2008, 02:22 PM   #6
PandaMine
Panda > You

Join Date: May 2006
Posts: 500

Submissions (4)

Quote:
 Originally Posted by Captain Griffen Sometimes maths code is needed in strange places. Or you can itinerate it, I think, which'd be faster. Far faster.

Pity you can't do recursion in wc3...
__________________
PandaMine's Creations:
 Systems AMHS v5.2 HSAS v3.6 AFS v1.2 Tutorials Animations

 07-08-2008, 05:31 PM #7 Strilanc User     Join Date: Jun 2007 Posts: 917 Submissions (4) Nice. I actually thought there was already log function (which shows how often I have needed it). It would probably be faster to just repeatedly square b (or 1/b) (storing each computed value in an array) until you went past the number, then working from there. POW probably works by repeated squaring so you're repeating the low squares a lot. __________________ Don't pay attention to this signature, it's self-contradictory.
07-09-2008, 02:02 AM   #8
PandaMine
Panda > You

Join Date: May 2006
Posts: 500

Submissions (4)

Apparently POW is faster then doing x*x*x*x all the time (think pipedream proved this somewhere).

It might be vice versa, can't remember completley
__________________
PandaMine's Creations:
 Systems AMHS v5.2 HSAS v3.6 AFS v1.2 Tutorials Animations

 07-09-2008, 02:30 PM #9 DioD obey     Join Date: Feb 2006 Posts: 1,532 Submissions (4) never saw use of such functions in wc3
07-09-2008, 03:29 PM   #10
Vexorian
Free Software Terrorist

Technical Director

Join Date: Apr 2003
Posts: 14,898

Submissions (37)

If you keep looking for fun curves, Log will eventually appear in a derivative. The problem is that the only math that people conceive in war3 is geometry, though after seeing a couple of systems in which heuristics were used, Log doesn't seem all that much of an unlikely requirement.
__________________
 Wc3 map optimizer 5.0 Someone should fix .wav sound in this thing. JassHelper 0.A.2.A Turns your simple code into something that is complicated enough to work.
 Wc3 map optimizer 5.0 JassHelper 0.A.2.A Xye 0.12.1 | Editor/Levels xe0.9 CS16.0 My spells jEdit modes for vJass&Zinc (v9) WarCiTy 0.2.0
Faster != more useful

 07-11-2008, 08:01 AM #11 d07.RiV User     Join Date: May 2008 Posts: 241 Submissions (1) Also there are much better methods than bin search. Like: JASS:```function Logarithm takes real a returns real local real x = 0 local integer i = 0 loop exitwhen i > 10 set x = x - 1 + a / Pow (bj_E, x) set i = 1 + 1 endloop return x endfunction ``` Of course logarithm with another base would require you to know ln (base) but that can be computed the same way or, since base is usually constant, hard-coded. __________________
07-11-2008, 03:38 PM   #12
Pytho
User

Join Date: Aug 2007
Posts: 29

Quote:
 Originally Posted by d07.RiV JASS:```function Logarithm takes real a returns real local real x = 0 local integer i = 0 loop exitwhen i > 10 set x = x - 1 + a / Pow (bj_E, x) set i = 1 + 1 endloop return x endfunction```
Just for the sake of completeness set i=i+1, in case someday someone really needs log...

07-11-2008, 04:22 PM   #13
Vexorian
Free Software Terrorist

Technical Director

Join Date: Apr 2003
Posts: 14,898

Submissions (37)

I was going to make one pipe suggested that does not use Pow, it is probably what Strilanc said as well.
__________________
 Wc3 map optimizer 5.0 Someone should fix .wav sound in this thing. JassHelper 0.A.2.A Turns your simple code into something that is complicated enough to work.
 Wc3 map optimizer 5.0 JassHelper 0.A.2.A Xye 0.12.1 | Editor/Levels xe0.9 CS16.0 My spells jEdit modes for vJass&Zinc (v9) WarCiTy 0.2.0
Faster != more useful

07-17-2008, 03:06 PM   #14
d07.RiV
User

Join Date: May 2008
Posts: 241

Submissions (1)

Quote:
 POW probably works by repeated squaring so you're repeating the low squares a lot.
No, POW is a crt function which (in 99.999% implementations) uses FPU (a processor for floating point arithmetics).
__________________

 07-17-2008, 05:51 PM #15 BlinkBoy User   Respected User   Join Date: Dec 2003 Posts: 835 Submissions (4) you could try using Briggs' method, it does not require pow, but you'll have to store in arrays the consecutive values of 10^(1/2^n) so, you end up storing 10^1/2, 10^1/4, 10^1/8..... and so on. 10 is the base. Google it around. __________________ Tools: NeoDex - a Gmax and 3ds Max modeling Toolset for Wc3! Learn to animate! check out my: Basic Animation Tutorial! Currently working at a sequel to my animation tutorial. Last edited by BlinkBoy : 07-17-2008 at 05:54 PM.