• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Math (real rounded upward)

Status
Not open for further replies.
you could just skip all that hassle and use:
  • set integervariable = (integer((realvariable + 0.50)))

Edit:
approved, but it will work only if you use 0.99 and not 0.5:

Real =0.99, need to bring it to int upward
0.99 + 0.99 =1.98 (int 1)
Real =0.01, need to bring it to int upward
0.01 + 0.99 = 1.00 (int 1)

set integervariable = (integer((realvariable + 0.99)))

4 commends became one!!!
+rep
 
Edit:
approved, but it will work only if you use 0.99 and not 0.5:

Real =0.99, need to bring it to int upward
0.99 + 0.99 =1.98 (int 1)
Real =0.01, need to bring it to int upward
0.01 + 0.99 = 1.00 (int 1)

set integervariable = (integer((realvariable + 0.99)))

Yeah, true.
By default, wc3 floors the real numbers when converting to integers.
Adding 0.50 to the real will change it into a rounding function.
Adding 0.99 to the real will change it into a ceiling function.
 
Decimals is a variable representing the remainder of the number after its integer has been chopped off.

there is "integer" and "real", decimal not exist.

Yeah, true.
By default, wc3 floors the real numbers when converting to integers.
Adding 0.50 to the real will change it into a rounding function.
Adding 0.99 to the real will change it into a ceiling function.

English is not my mother tounge, my intention was "ceilling function" and in most less commmends possible.
Yeah but it is practical.
Sure you could just go all:
If (realVar mod 1) not equal to 0, then intVar = integer(realVar+1), else intVar = integer(realVar)
If you really need it to be that accurate.
Probably the best way to do it when you are facing reals who can become more precise than 0.01.

Solved :)
 
Status
Not open for further replies.
Top