uniflare Posted June 30, 2008 Share Posted June 30, 2008 Ok so i have this JASS (from Warcraft 3) Code that i have attempted to convert to PHP. In the Script is an equation that is completely baffling me. This Equation works as expected: 0+79*0/(61+1)+293*(61/1+0-(0/62)*62)+479 = 18352 Unfortunately this Equation Doesn't: 479+79*479/(1+1)+293*(1/1+479-(479/62)*62)+479 = 20171.5 in PHP / and i want it to equal: 19884 (as JASS does ???). The Equation is exactly the same, same numbers/operators/brackets etc. This must have soemthing to do with which operators it executes first or something im sure of it (might be wrong tho im newb at math). Thanks very much for any help - i really appreciate it and this must be a tough solution. I just hope some super math guru shows me some enlightenments Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 OK Cannot find Edit Button, i put 1 bracket in wrong place . 479+79*479/(1+1)+293*(1/1+479-(479/62)*62)+479 = 20171.5 should be 479+79*479/(1+1)+293*1/(1+479-(479/62)*62)+479 = 20171.5 --- I hope i didnt throw anyone Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 Ugh - Very Sorry for Multiple posts if mod can edit these please do. (where is the edit button!?!?!) anyway i forgot to edit the top equation like the bottom... so, from the top: This Equation works as expected: 0+79*0/(61+1)+293*61/(1+0-(0/62)*62)+479 = 18352 Unfortunately this Equation Doesn't: 479+79*479/(1+1)+293*1/(1+479-(479/62)*62)+479 = 20171.5 in PHP / and i want it to equal: 19884 (as JASS does ). please help Thanks in advance Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 by the way the edit button is called 'Modify' and is next to 'Quote' in the top right of your post ok, so your current formula's you have posted are definantly correct? Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 Ah ARG time limit on edits. lol im very very sorry. damn. i hope i havent wasted your time ok. This Works: 0+79*0/(0+1)+293*0/(1+0-(0/62)*62)+479 = 479 AND this works: 0+79*0/(61+1)+293*(61/1+0-(0/62)*62)+479 = 3352 This Doesnt 479+79*479/(1+1)+293*1/(1+479-(479/62)*62)+479 = 20171.5 last one should be 19884 --- again really sorry for posts and getting it wrong - im really bad at math i swear im dislexic or summat Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 lol, thats fine try this. <?php $result = ((((((((479 + 79) * 479) / (1 + 1)) + 293) * 1) / (1 + 479 - (479 / 62) * 62)) + 479)); if ($result == 19884) { echo "SUCCESS!"; } elseif ($result == 20171.5) { echo "Same Again..."; } else { echo "Something different??? " . $result; } ?> let me know what you get. I just hope I've put in the correct amount of parenthesis Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 Unfortunately: Something different??? 134413 thanks for the help so far lol there was no parse errors Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 ok. First I want you to run that same equation 5 times, and note down what the result was each time (if the results differ). then let me know what you get. Once you have done that. Try this: <?php $result = ((((((((479 + 79) * 479) / (1 + 1)) + 293) * 1) / (1 + 479 - (479 / 62) * 62)) + 479)); if(is_numeric($result)) { if ($result == 19884) { echo "SUCCESS!"; } elseif ($result == 20171.5) { echo "Same Again..."; } else { echo "Something different??? " . $result; } } else { echo "It is not a number!"; } ?> see what we get EDIT: I just tried running this through google ((((((((479 + 79) * 479) / (1 + 1)) + 293) * 1) / (1 + 479 - (479 / 62) * 62)) + 479)) and it equaled 134 413 EDIT again: I just ran the exact same equation through my school calculator and it equaled 134 413 as well. Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 lol did not think of google. ok the equation was the same 15 times in a row. Something different??? 134413 the other script is: Something different??? 134413 Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 hmmmm, ok. I ran this one through google as well(the one you had before we added the parenthesis) 479+79*479/(1+1)+293*1/(1+479-(479/62)*62)+479 = 20171.5 and google came back with 20171.5 as well. So I believe the error is within where and how the parenthesis are placed within the equation, which may be quite difficult to get right as there is so many numbers involved with hundreds of combinations to try. hmmm. Any how, what is this JASS your talking about. I use to play WoW, but am more a Warcraft 3 fan as WoW has kinda ruined the series but anyway. Whats JASS ? Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 JASS is the scripting language Warcraft 3 uses in its maps, every map has triggers (you might of heard of them), GUI triggers (in world editor) gets converted to JASS when you save the map. i also ran it through google, only thing with php is i tried certain combinations, most of them didn't even change the number....strange.. thanks for your help so far Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 ok, yeah I've used the Warcraft 3 map editor many times, god thats alot of fun All I can think of is, that the difference between how equations are run in C/C++ and PHP is what is giving the varying results. try this: <?php $result = ((((((((479 + 79) * 479) / (1 + 1)) + 293) * 1) / (1 + 479 - (479 / 62) * 62)) + 479)); $result = abs($result); if(is_numeric($result)) { if ($result == 19884) { echo "SUCCESS!"; } elseif ($result == 20171.5) { echo "Same Again..."; } else { echo "Something different??? " . $result; } } else { echo "It is not a number!"; } ?> Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 Something different??? 134413 hmmmm, im starting to think its the JASS integer limitations thats causing this. See all these number are integer varibles in the JASS code, integers cannot have any decimal places. im wondering if the calculations mid-way are throwing of some of the other calculations in the process.. im going to test this. Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 wow i seem to be a lot closer but not quite... notice anything wrong? btw - real values (numbers with decimals) that get converted to integers are literally stripped of the decimal part. doesnt round down/up/around whatever just takes the dot and anything after it off and bins it. eg: 3.7 would become 3 etc. so: <?php Function R2I($num){ $nume = explode(".",$num); return $nume[0]; } $result = 479 + R2I((R2I((79 * 479)) / 2)) + R2I((293 * R2I((1 / R2I((1 + 479 - R2I((R2I((479 / 62)) * 62)) )) )) )) + 479; $result = abs($result); if(is_numeric($result)) { if ($result == 19884) { echo "SUCCESS!"; } elseif ($result == 20171.5) { echo "Same Again..."; } else { echo "Something different??? " . $result; } } else { echo "It is not a number!"; } ?> i now get Something different??? 19878 .... Ok im going to test with Rounding Up, as these integers are not actually getting converted manually... Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 hmm ok with round() i get 1 digit closer lol. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 lol, nice, so theres ceil(), and round(). you could do: <?php $result = round($result)-1; Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 Thanks for suggestion, but i think i have narrowed the problem.. For some completely random reason JASS interprets: (479 / 62 * 62) to 434 ??? lol. Guess im heading over to a JASS forum to see wth is goin on Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 lol, yeah. maybe a glitch Blizzard hasn't patched Quote Link to comment Share on other sites More sharing options...
uniflare Posted June 30, 2008 Author Share Posted June 30, 2008 ok no glitch me bein stupid lol. The Answer (If your interested) is here: http://www.thehelper.net/forums/showthread.php?t=96964 Thanks again for your help Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 no problem, any time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.