wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-08-2008, 03:15 AM   #1
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default 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...

Collapse 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
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-08-2008, 04:43 AM   #2
PandaMine
Panda > You
 
PandaMine's Avatar
 
Join Date: May 2006
Posts: 500

Submissions (4)

PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)

Send a message via MSN to PandaMine
Default

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:
PandaMine is offline   Reply With Quote
Old 07-08-2008, 05:49 AM   #3
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

This is still really cool, I love mathematical code.
__________________
Rising_Dusk is offline   Reply With Quote
Old 07-08-2008, 07:46 AM   #4
d07.RiV
User
 
d07.RiV's Avatar
 
Join Date: May 2008
Posts: 241

Submissions (1)

d07.RiV is on a distinguished road (10)

Default

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.
__________________
d07.RiV is offline   Reply With Quote
Old 07-08-2008, 09:18 AM   #5
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

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] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 07-08-2008, 02:22 PM   #6
PandaMine
Panda > You
 
PandaMine's Avatar
 
Join Date: May 2006
Posts: 500

Submissions (4)

PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)

Send a message via MSN to PandaMine
Default

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:
PandaMine is offline   Reply With Quote
Old 07-08-2008, 05:31 PM   #7
Strilanc
User
 
Strilanc's Avatar
 
Join Date: Jun 2007
Posts: 917

Submissions (4)

Strilanc has a spectacular aura about (131)

2008 Spell olympics - Fire - Gold

Default

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.
Strilanc is offline   Reply With Quote
Old 07-09-2008, 02:02 AM   #8
PandaMine
Panda > You
 
PandaMine's Avatar
 
Join Date: May 2006
Posts: 500

Submissions (4)

PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)PandaMine has a spectacular aura about (96)

Send a message via MSN to PandaMine
Default

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:
PandaMine is offline   Reply With Quote
Old 07-09-2008, 02:30 PM   #9
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

never saw use of such functions in wc3
DioD is offline   Reply With Quote
Old 07-09-2008, 03:29 PM   #10
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

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.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 07-11-2008, 08:01 AM   #11
d07.RiV
User
 
d07.RiV's Avatar
 
Join Date: May 2008
Posts: 241

Submissions (1)

d07.RiV is on a distinguished road (10)

Default

Also there are much better methods than bin search. Like:
Collapse 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.
__________________
d07.RiV is offline   Reply With Quote
Old 07-11-2008, 03:38 PM   #12
Pytho
User
 
Join Date: Aug 2007
Posts: 29

Pytho has little to show at this moment (6)

Default

Quote:
Originally Posted by d07.RiV
Collapse 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
Like your method
Just for the sake of completeness set i=i+1, in case someday someone really needs log...
Pytho is offline   Reply With Quote
Old 07-11-2008, 04:22 PM   #13
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

I was going to make one pipe suggested that does not use Pow, it is probably what Strilanc said as well.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 07-17-2008, 03:06 PM   #14
d07.RiV
User
 
d07.RiV's Avatar
 
Join Date: May 2008
Posts: 241

Submissions (1)

d07.RiV is on a distinguished road (10)

Default

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).
__________________
d07.RiV is offline   Reply With Quote
Old 07-17-2008, 05:51 PM   #15
BlinkBoy
User
 
BlinkBoy's Avatar


Respected User
 
Join Date: Dec 2003
Posts: 835

Submissions (4)

BlinkBoy has a spectacular aura about (97)BlinkBoy has a spectacular aura about (97)BlinkBoy has a spectacular aura about (97)BlinkBoy has a spectacular aura about (97)

Outstanding Tutorial

Default

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.
BlinkBoy is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 08:42 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services