Jump to content

[SOLVED] Very Long Equation is Not As Expected.


uniflare

Recommended Posts

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  ;D

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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 :P

 

Thanks in advance

Link to comment
Share on other sites

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 :P

Link to comment
Share on other sites

lol, thats fine  :D

 

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

Link to comment
Share on other sites

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  :D

 

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

ok, yeah I've used the Warcraft 3 map editor many times, god thats alot of fun  ;D

 

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!"; }
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.