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 09-10-2008, 05:21 PM   #17
w3soft
User
 
Join Date: Jun 2008
Posts: 1

w3soft has little to show at this moment (0)

Default

So, some faster version:
Code:
globals
  real array alog
  integer ilog = 0
endglobals

function B2I takes boolean is, integer ArgF, integer ArgT returns integer
  if is then
    return ArgT
  else
    return ArgF
  endif
endfunction

function r2i takes real r returns integer
  local integer i = R2I(r)
  return B2I(r-i<0.5, i+1, i)
endfunction

function log2 takes integer i returns real
  local real r = 0
  if i <= 0x400 then
    set r = alog[i]
  elseif i <= 0x100000 then
    set r = 0x0A + alog[r2i(i/0x400)]
  elseif i <= 0x40000000 then
    set r = 0x14 + alog[r2i(i/0x100000)]
  elseif i <= 0x7FFFFFFF then
    set r = 0x1E + alog[r2i(i/0x40000000)]
  endif
  return r
endfunction

function log takes integer base, integer num returns real
  return log2(num)/log2(base)
endfunction

function DecodeLog takes nothing returns nothing
  local real k = 0
  if ilog == 0x401 then
    call DestroyTimer(GetExpiredTimer())
    set ilog = 0
  endif
  loop
    exitwhen (ilog - Pow(2, k) < 0)
    set k = k + 0.1
  endloop
  set alog[ilog] = k - 0.1
  set ilog = ilog + 1
endfunction

function InitLog takes nothing returns nothing
  local timer t = CreateTimer()
  call TimerStart(t, 0.005, true, function DecodeLog)
endfunction

It can include some errors because is not tested=)

Last edited by w3soft : 09-10-2008 at 05:23 PM.
w3soft is offline   Reply With Quote
Old 09-24-2008, 05:38 AM   #18
Hoernchen
User
 
Join Date: Mar 2007
Posts: 47

Hoernchen is on a distinguished road (10)

Default

I tried this script but it always returns 88 for me....
__________________
Current Project:
Advanced Wars Arena
Hoernchen is offline   Reply With Quote
Old 10-29-2008, 01:16 PM   #19
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

i use only log for 2^x the rest is useless imo...
__________________
Toadcop is offline   Reply With Quote
Old 10-29-2008, 05:40 PM   #20
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

Apparently the return bug method (which can be made to 'work') has issues - it is known about.
__________________
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 10-30-2008, 09:53 AM   #21
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Quote:
Originally Posted by Vexorian
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.

Actually since most(all?) geometry is done in periodic timers you can use derivates(differentials) of functions you need, and since dy/dx[ln(x)] = 1/x
all you need to do is add 1/dx each iteration.
Now that is efficiency.
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 10-30-2008 at 09:56 AM.
cohadar is offline   Reply With Quote
Old 05-09-2009, 09:15 PM   #22
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

I was looking at this versus those ones that BlinkBoy posted and quite frankly this just seems inferior. Is there any way to improve this? I want to actually use functions in a library for this.

I can't believe I found a use for this...
__________________
Rising_Dusk is offline   Reply With Quote
Old 05-09-2009, 09:35 PM   #23
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,154

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

Quote:
Originally Posted by Rising_Dusk
I was looking at this versus those ones that BlinkBoy posted and quite frankly this just seems inferior. Is there any way to improve this? I want to actually use functions in a library for this.

I can't believe I found a use for this...

omg ...just add the library and private keywords yourself ?!?!?
if want to use it for something which will be submitted, just tell the people to choose on of the functions themselves ?
__________________

Last edited by akolyt0r : 05-09-2009 at 09:37 PM.
akolyt0r is offline   Reply With Quote
Old 05-09-2009, 09:41 PM   #24
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

Lol. I could as an admin ninja in the library keywords to BlinkBoy's submission, but I feel like that might be abusing my power. Regardless, I feel like there should be a standard for this kind of mathematical operation and the entire site should endorse it.
__________________

Last edited by Rising_Dusk : 05-09-2009 at 09:45 PM.
Rising_Dusk is offline   Reply With Quote
Old 05-09-2009, 09:58 PM   #25
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,154

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

Quote:
Originally Posted by Rising_Dusk
Lol. I could as an admin ninja in the library keywords to BlinkBoy's submission, but I feel like that might be abusing my power. Regardless, I feel like there should be a standard for this kind of mathematical operation and the entire site should endorse it.

well thats a thing ..only Vex's superpowers can achieve ....
__________________
akolyt0r is offline   Reply With Quote
Old 05-23-2009, 09:42 PM   #26
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

Clean fixed point implementation:
http://www.quinapalus.com/efunc.html

To convert into : out of fixed point, R2I(x*to_fix) : x/to_fix, where to_fix = pow(2.0,16.0).
t&0x80000000 means check if the integer is negative.
__________________
PipeDream is offline   Reply With Quote
Old 05-24-2009, 03:01 AM   #27
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

It would need divisions in Jass since there are no binary operators, and R2I is not great either.

I am heading towards implementing:
Click image for larger version

Name:	6b05eb2167fb761f5e0e9312ac44ca36.png
Views:	209
Size:	2.1 KB
ID:	43269
Zoom (requires log in)

As it will use division and product but no further things. First need to test stuff though.

edit: ok, that sucks, it takes ages to converge... There are tricks to fix it but require a quick approximation, will check implementing that one, pipe, it isn't that bad as those divisions are just for special cases anyway...
__________________
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 06-14-2009, 01:24 AM   #28
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

Did you ever get anywhere with this? :)
__________________
Rising_Dusk is offline   Reply With Quote
Old 11-08-2009, 12:23 AM   #29
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

Just bumping this. I realize it's not really critical, but this is inaccurate enough that for armor calculation via my ArmorUtils library, you get -3.999999 instead of -4.00000. It's not a big deal, I guess, but it is kind of annoying. The function that Blinkboy posted that uses simpson's seems to give better results.
__________________
Rising_Dusk is offline   Reply With Quote
Old 12-12-2009, 04:59 AM   #30
mystafox
User
 
Join Date: Jun 2009
Posts: 23

mystafox has little to show at this moment (5)

Default

Quote:
Clean fixed point implementation:
http://www.quinapalus.com/efunc.html

To convert into : out of fixed point, R2I(x*to_fix) : x/to_fix, where to_fix = pow(2.0,16.0).
t&0x80000000 means check if the integer is negative.
This method is horrible due to jass real value limitation. I've tried it and it gives very bad results.

Here is a more accurate method, i didnt benchmark it but it gives good results.
Feel free to test it :)
Collapse JASS:
//==============================================================================
//  Logarithm script by X - Version 1.0 - December 12, 2009
//==============================================================================
//
//  about:
//      - compute natural logarithm of a real.
//      - compute logarithm to the base b of a real.
//       
//  Usage:
//      - Ln(x)   to compute the natural logarithm of the real x
//      - LogB(x, b) to compute the logarithm to the base b of the real x
//      - LogBV2(x, b) to compute the logarithm to the base b of the real x with another method, see Notes
//      - Logarithm_e to acces the value of the constant e
//
//  Notes:
//      - Ln(x) is exactly the same as LogB(x,Logarithm_e)
//      - LogBV2(x,b) is Ln(x)/Ln(b)  , make your own tests to compare it to LogB(x,b)
//      
//      - you can find the algorithm used at this address :
//              [url]http://en.literateprograms.org/Logarithm_Function_%28Python%29[/url]
//              it is the same as the basic one explained by Donald E. Knuth in his book
//
//      - reals in jass are not very precise, something like 9 total digits. Be happy if it works
//
//  Requirements:
//      - JassHelper.
//
//  Installation:
//      - Create a new trigger called Logarithm.
//      - Convert it to custom text and replace all the code with this code.
//
//  Special Thanks:
//      - Ammorth: for is LinkedList information layout 
//
//==============================================================================

library Logarithm

   globals
       public constant real e = 2.718282  //e=2.71828182845904523536
       private constant real EPSILON = 0.0000001 // dont use lower values, jass reals sucks
   endglobals
    
    function Ln takes real x returns real
        local real decimal = 0.0
        local real partial = 0.5
        local integer i = 0
        if x <= 0 then
            return 0
        endif
        loop
            exitwhen x >= 1
            set i = i - 1
            set x = x * e
        endloop
        loop
            exitwhen x < e
            set i = i + 1
            set x = x / e
        endloop
        set x = Pow(x,2)  // maybe power is more accurate than x*x -_-'
        loop
            exitwhen partial <= EPSILON
            if x >= e then
                set decimal = decimal + partial
                set x = x / e
            endif
            set partial = partial * 0.5
            set x = Pow(x,2)
        endloop
        return i + decimal
    endfunction

    function LogBV2 takes real x, real base returns real
            return Ln(x)/Ln(base) 
    endfunction
    function LogB takes real x, real base returns real
        local real decimal = 0.0
        local real partial = 0.5
        local integer i = 0
        if x <= 0 or base <=0 then
            return 0
        endif
        loop
            exitwhen x >= 1
            set i = i - 1
            set x = x * base
        endloop
        loop
            exitwhen x < base
            set i = i + 1
            set x = x / base
        endloop
        set x = Pow(x,2)
        loop
            exitwhen partial <= EPSILON
            if x >= base then
                set decimal = decimal + partial
                set x = x / base
            endif
            set partial = partial * 0.5
            set x = Pow(x,2)
        endloop
        return i + decimal
    endfunction
endlibrary
//==============================================================================
//  End of Logarithm script
//==============================================================================
mystafox 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 10:35 AM.


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