StarCraft® II

Calculating Logarithms in the Galaxy Editor

Is it possible to do this? I know someone who is trying to make a map that calculates SQ (Spending Quotient) on the fly, but doing so requires computing a natural logarithm. Has anyone else solved this problem already? Is Blizzard going to add in an ln function?
Reply Quote
I think there are Log and exponent and etc. If you want to make some kind of mathematical equation in trigger, go for it, but I won't help you there haha.
Reply Quote
12/06/2012 08:33 AMPosted by Fenix
I think there are Log and exponent and etc. If you want to make some kind of mathematical equation in trigger, go for it, but I won't help you there haha.


From http://www.teamliquid.net/forum/viewmessage.php?topic_id=374400&currentpage=17#332 :
Ok, now those are the two big numbers needed to calculate SQ. Here is the third giant problem: there is no mathematical function for calculating the natural log of a value in the editor. Not really a HUGE problem, but definitely a problem. I would then have to calculate the Taylor series or an Infinite series and traverse a certain number of steps to determine the natural log by hand (via computer ). Then use that value to calculate SQ.


Are you sure there is a log function? The map developer for TheStaircase custom map seems to think one does not exist.
Reply Quote
Open the Trigger Editor, make two new variables, one REAL one INTEGER, then take a look at what functions are available. (Especially in the MATH part).

Rather than list them all out and say, is this one any use, it would be better for you to go take a look :)
Reply Quote
Open the Trigger Editor, make two new variables, one REAL one INTEGER, then take a look at what functions are available. (Especially in the MATH part).

Rather than list them all out and say, is this one any use, it would be better for you to go take a look :)

I believe this is what the map-maker for TheStaircase map (see the TL thread) has already tried. I can try it too, although I'm a huge noob with the editor. It's my understanding though that none of the math functions include logarithm calculations.
Reply Quote
Randomly checked a bit, there is only Log2 and checking its galaxy code equivalent ( "Log2I(value)" ) sure don't imply something different than base 2.

So if there is a way, it might be deep into some galaxy code documentation somewhere but not from the Editor UI.

I am afraid he might have to calculate/mimic it as best he can. The only suggestion I have is if mimic'ing requires too much execution time and there are a lot of the SAME values/results, he might want to "hardcode" the sets of logs/values into the pre-calculated results into a 2D array.

Ex : LogResult[2][4] = 2. The first index being the log base and 4 being the number.

or perhaps LogResult[20][4] = 2 . Thus the first index being 2.0 for 1 decimal if the index numbers goes up to 800 max (considering 8000 max or so for the array).

Obviously that would only work if it's a not a huge set of integers (and not reals). If his potential pool of results is big, it won't help that much.

EDIT : If you are honestly going that way, obviously have some program (c++ or something) that mass calculate everything you need. If you are going to make it into galaxy code, preferably output all the galaxy code lines to mass copy them as "Custom Script" (action-type) in the Trigger UI.

EDIT 2 : Do factor that doing so will probably greatly increase the loading phase of your map.
Edited by Honejasi on 12/6/2012 10:11 AM PST
Reply Quote
Wait, but if there is log base 2, then you can just do log2(x) / log2(e) to get ln(x). Right?
Reply Quote
If I remember my maths lessons of yonder year...

http://en.wikipedia.org/wiki/Logarithm#Change_of_base

logb(x) = logk(x) / logk(b)

therefore to calculate ln(x)...

ln(x) = log2(x) / log2(e)

Since its been a long time since I've mathamaticized anything let me pick some random number to check.

Let x = 4321
ln(x) = 8.37124

log2(e) = 1.442695
log2(4321) = 12.07715

log2(4321) / log2(e) = 12.07715 / 1.442695 = 8.37124

whelp, with a sample size of 1 (very scientific) it seems to be correct. So all you have to do if you want to calculate ln(x) is calculate log2(x) and divide by 1.442695 and it should give you the answer.

EDIT: Ninja'd
Edited by turtles on 12/6/2012 10:28 AM PST
Reply Quote
In galaxy, 'real' numbers use 20.12 fixed point values. This generally means you can only rely on three decimal places.
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)
Submit Cancel

Reported!

[Close]