09102008, 05:21 PM  #17 
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(ri<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 : 09102008 at 05:23 PM. 
09242008, 05:38 AM  #18 
User
Join Date: Mar 2007
Posts: 47

I tried this script but it always returns 88 for me....
__________________ 
10292008, 01:16 PM  #19 
BuranX

i use only log for 2^x the rest is useless imo...
__________________ 
10292008, 05:40 PM  #20 
Dread Lord of the Cookies
Content Director

Apparently the return bug method (which can be made to 'work') has issues  it is known about.
__________________ 
10302008, 09:53 AM  #21  
master of fugue
Join Date: Jun 2007
Posts: 2,453

Quote:
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. Last edited by cohadar : 10302008 at 09:56 AM. 

05092009, 09:15 PM  #22 
Obscurity, the Art

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... 
05092009, 09:35 PM  #23  
In Flames
Join Date: Jan 2006
Posts: 1,154

Quote:
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 : 05092009 at 09:37 PM. 

05092009, 09:41 PM  #24 
Obscurity, the Art

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 : 05092009 at 09:45 PM. 
05092009, 09:58 PM  #25  
In Flames
Join Date: Jan 2006
Posts: 1,154

Quote:
well thats a thing ..only Vex's superpowers can achieve .... 

05232009, 09:42 PM  #26 
Moderator
Code Moderator
Join Date: Feb 2006
Posts: 1,405

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. 
05242009, 03:01 AM  #27 
Free Software Terrorist
Technical Director

It would need divisions in Jass since there are no binary operators, and R2I is not great either.
I am heading towards implementing: 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... 
11082009, 12:23 AM  #29 
Obscurity, the Art

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.
__________________ 
12122009, 04:59 AM  #30  
User
Join Date: Jun 2009
Posts: 23

Quote:
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 //============================================================================== // // 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 //============================================================================== 

Thread Tools  Search this Thread 

