• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[General] math

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2010
Messages
230
mC is an integer
(1.+mC/ 3.)

how does this expression evaluated in war3? addition or division first?
 
Level 6
Joined
Aug 12, 2010
Messages
230
are you sure? theres a space between / and 3 though, it might mean something. Also, the dots.. what could it mean?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Try it?
Make a new map and make a trigger for map initialization that sends a message to all players with the outcome.
That solves your question and maybe more questions that you have ;)

In this case, diversion comes before addition. spaces are actually neccesary for certain things in JASS equal as is a newline. but in this case it wont matter.
 
The dots indicate that it is dividing by a float (a real in JASS).

"1." is equivalent to "1.0". It is usually used to perform a calculation with floats rather than integers. For example, if you divide an integer by an integer (e.g. 5 / 3), you'll end up with an integer (1) rather than 1.666. If you add the dot after the divisor, then you'll be guaranteed the decimal result.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,184
Normal math rules apply.

() > / or * > + or -

However GUI automatically creates () so if you do the math in GUI it could potentially give incorrect results.

are you sure? theres a space between / and 3 though, it might mean something. Also, the dots.. what could it mean?
Spaces do nothing. You can write 3 + 5 in jass the answer will be same as 3+5.

I suppose you mean if the answer becomes .x?

If you get the answer .33 the answer is 0.33
 
Level 7
Joined
May 11, 2010
Messages
278
Normal math rules apply.

() > / or * > + or -

However GUI automatically creates () so if you do the math in GUI it could potentially give incorrect results.

Sorry for semi-necroing this thread, but I'm curious about the math.
Say I have this expression: 600/2*0,02
Will it evaluate to (600/2)*0,02=6
or will it evaluate to 600/(2*0,02)=15000 if written without brackets? Why?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I will also add to this :D

If 2 expressions are of the same weight(2 multiplications next to each other, multiplication then division etc) then they are always evaluated left to right.

So: 5+3+7*9/3+8-7 will be the same as ((5+3)+((7*9)/3)+8)-7, the result is 30 btw
 
Level 6
Joined
Aug 12, 2010
Messages
230
multi or divi has no difference, whether who will come first. answer always same

pure multi and divi expression can be evaluated in anyway
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
The importance of knowing left to right instead of "anyway" e.g. right to left is when you deal with more than numbers.

JASS:
set i = SomeFunction() * someOtherFunction()

Lets say SomeFunction creates some unit and stores it in some global variable and then returns some integer or real value. Then someOtherFunction will try to do something to the unit and return some other value.

If there was no guarantee of Left to right execution, this code would have potential to not even work because if evaluated right to left you will try to manip unit that does not exist and only then you will actually try to create the unit.

Just example of course
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,206
Another example is simply involving numbers.
JASS:
set i = 11 * 3 / 7 * 5
// Equivalent with bracers for explicit ordering.
set i = (((11 * 3) / 7) * 5)
The variable "i" would become equal to 20. This is because the '*' and '/' operators have the same precedence so are evaluated from left to right.

If it was evaluated any other way it would be 0 since the result of integer division of a small number by a larger number is 0.
 
Status
Not open for further replies.
Top