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

 09-10-2008, 05:21 PM #17 w3soft User   Join Date: Jun 2008 Posts: 1 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.
 09-24-2008, 05:38 AM #18 Hoernchen User   Join Date: Mar 2007 Posts: 47 I tried this script but it always returns 88 for me.... __________________ Current Project: Advanced Wars Arena
 10-29-2008, 01:16 PM #19 Toadcop BuranX     Join Date: Jul 2006 Posts: 1,886 Submissions (4) i use only log for 2^x the rest is useless imo... __________________
10-29-2008, 05:40 PM   #20
Captain Griffen

Content Director

Join Date: Sep 2003
Posts: 5,375

Submissions (2)

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] hmm.. stil i want to have some unused women

10-30-2008, 09:53 AM   #21
master of fugue

Join Date: Jun 2007
Posts: 2,453

Submissions (5)

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.

 05-09-2009, 09:15 PM #22 Rising_Dusk Obscurity, the Art Projects DirectorProject Leader: OD   Join Date: Feb 2006 Posts: 9,729 Submissions (27) 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... __________________
05-09-2009, 09:35 PM   #23
akolyt0r
In Flames

Join Date: Jan 2006
Posts: 1,154

Submissions (3)

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.

 05-09-2009, 09:41 PM #24 Rising_Dusk Obscurity, the Art Projects DirectorProject Leader: OD   Join Date: Feb 2006 Posts: 9,729 Submissions (27) 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.
05-09-2009, 09:58 PM   #25
akolyt0r
In Flames

Join Date: Jan 2006
Posts: 1,154

Submissions (3)

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

 05-23-2009, 09:42 PM #26 PipeDream Moderator   Code Moderator   Join Date: Feb 2006 Posts: 1,405 Submissions (6) 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. __________________
05-24-2009, 03:01 AM   #27
Vexorian
Free Software Terrorist

Technical Director

Join Date: Apr 2003
Posts: 14,898

Submissions (37)

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

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

 06-14-2009, 01:24 AM #28 Rising_Dusk Obscurity, the Art Projects DirectorProject Leader: OD   Join Date: Feb 2006 Posts: 9,729 Submissions (27) Did you ever get anywhere with this? :) __________________
 11-08-2009, 12:23 AM #29 Rising_Dusk Obscurity, the Art Projects DirectorProject Leader: OD   Join Date: Feb 2006 Posts: 9,729 Submissions (27) 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. __________________
12-12-2009, 04:59 AM   #30
mystafox
User

Join Date: Jun 2009
Posts: 23

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 :)
JASS:
```//==============================================================================
//  Logarithm script by X - Version 1.0 - December 12, 2009
//==============================================================================
//
//      - 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
//==============================================================================```

 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.

 -- Night Elf -- Tauren -- Troll -- Pandaren -- Underworld -- Blood Elf -- Northrend -- Lightning ---- Light-ning -- Arcane -- Diablo III -- Protoss -- Mobile Version Wc3campaigns - Archive - Top

 Affiliates