• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

[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