• 🏆 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!

Assignment

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
here is the code but this is madness....
the math of editor is completly nuts !!
i did set each integer to their value and did the math but the result is 1
then i tried with real result was 1.00, then i forced a order for maths operation "(a/b)*(c/d)*e-f " and result was still 1.00 !!!
i did it with a calculator a/b*c/d*e-f and result was 2.20...
if i do with calculator (a/b)*(c/d)*2-1 i also get 2.20, so order isn't important for the result, that mean it is impossible from that to determine in wich order the editor does maths...
what is crazy is that editor still say when i use real that 6/5 = 1.00 wtf ???

Code[Jass=]
//! runtextmacro variables()
// This is where you should delcare your variables
// Remember, (type) (name)

// Assignment sector:
integer a
integer b
integer c
integer d
integer e
integer f
real g
real h
real ab
real cd
//! runtextmacro endvariables()

//! runtextmacro actions()
// This is where you should put all the code that modifies
// and plays with the variables you declared above.
set a = 6
set b = 5
set c = 4
set d = 3
set e = 2
set f = 1
set ab = 6/5
set cd = 4/3
set g = a/b*c/d*e-f
set h = ab*cd*e-f

// Assignment sector:
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "total is " + I2S(a/b*c/d*e-f))
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "total is " + R2S(g))
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2S(ab)+"X "+ R2S(cd)+"X 2 - 1 = "+ R2S(h))

//! runtextmacro endactions()[/code]
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
You can use integers when a real is expected, and it's the same in the math world.
"6/5", 6 and 5 are what we call litteral values (directly written, not got from a variable read).
For jass, litteral values are integer or real depends how it's written, basically if it has no "." then it's an integer.
If you want a real value, at least one of this value needs to be a real :
6./5 or 6.0/5 if it's clearer for you.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
oh, i see...
then even if i declare the variable real, it won't be treated as real if i don't add 6.
well that's pretty strange, thanks for the tips.

so this mean also that 2 integer will always give an integer result even if i am expecting a real.
so to do integer a/b i should do real a/real b = real even if a and b were integer (no float)

well this is good to know because it could f*k up many maths operation if not carefull.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
oh, i see...
then even if i declare the variable real, it won't be treated as real if i don't add 6.
well that's pretty strange, thanks for the tips.

No, if you use a variable it will be treated as a real because it's already defined as a real through the variable type, no matter if you use the integer form or not when writing the variable value.

so this mean also that 2 integer will always give an integer result even if i am expecting a real.

Yes.
And it can be considered as a feature in fact.

so to do integer a/b i should do real a/real b = real even if a and b were integer (no float)

It doesn't matter with (+)(-)(*), but in case you want to divide numbers, if you want a real result at least one of this number must be a real.
There is a function to make an integer as a real I2R.
Or you can also add it +0., but it's tricky there.
 
I think the assignment wasn't very clear then.
You were not supposed to find the value of the expression I gave you, you were supposed to find the order of operations.

I will reword it.

Also, you're an enrolled student, so you have the privilege of posting your assignment in the Hand-In forum.
If you don't wish to have this privilege and would rather just post them in the public part of the forum, you can give your position to any other observer.
 
Last edited by a moderator:

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
i didn't know about the hand in forum,
i will post there then, sorry for the mistake.
 
Status
Not open for further replies.
Top