Real and integer clarification needed.

Solu9

You can change this now in User CP.
Reaction score
216
When I calculate the sum of numbers in an equation I am often confused by the difference on real and integer variables.

What I kinda know:
Reals can store fractions of number fx. 2.38. Where integer only stores whole numbers like 4.

My question is if this has any effect on the calculation itself other than Reals can add fractions of a number into the equation?
 

afisakov

You can change this now in User CP.
Reaction score
37
This has an effect on the calculation because integers lose any decimal places at every step.
For instance when using integers (9+3)/2 does NOT equal 9/2+3/2.
(9+3)/2=12/2=6 whereas 9/2=4, 3/2=1 (decimals dropped for integer), therefore 9/2+3/2=4+1=5 when using integer operations.
For this reason I often prefer to calculate using reals and then convert into an integer at the very end if I have to.
 

Solu9

You can change this now in User CP.
Reaction score
216
Ah thanks for the clarification.

Bonus question so further my understanding:
Take this equation for damage...

(((Real + Real) + (Integer)) + (Integer x Real)) x (Real + Real)
(((24.00 + 24.00) + (140)) + (20 x 75.00)) x (1.00 + 0.45)

Since the Reals are whole numbers I take that there is no loss whatsoever.
(188 + 1500) x 1.45 -> 2447.6
Now the sum (2447.6). Or will the 0.6 be disregarded because the sum is an Integer. Or is the sum a Real so the 0.6 will indeed count?

Edit:
(((Real + Real) + (Integer)) + (Integer x Real)) x (Real + Real) to clarify:
(((Agility + Strength) + (Weapon Damage)) + (Spell level x 75)) x (1.00 x 0.45)
 

Imp Midna

Active Member
Reaction score
52
At least in c++ floats are given the higher priority when it comes to implicit type conversion. I don't have a grammar file of jass though so i can't really tell. Maybe the guy who made jass helper should publish his file, would certainly be interesting to see.

Apart from that, integer and real (== float) are totally different. There's a lot of difference that you probably won't understand as you never actually learned low-level programming languages (aka Assembler), but to sum up the major effects:
- (signed 32bit) integers contain numbers from -2147483648 to 2147483647. Therefor, adding/subtracting will never yield false results unless you exceed those borders
- a (32bit signed) float contains numbers of uncertain range. However, it will become less and less accurate the higher the number is
- floating points use their own instruction set which is significantly slower than the integer one
- the floating point instructions push 80 bit floats while float variables store 32 bit floats. Therefor, writing pi==pi will occasionally return false
- Especially when multiplying extremely small with extremely big numbers, the inaccurateness of floating points can be seen very clearly. It's disgusting what the computer tries to make you believe

As a result, you usually learn: floats are bad, and if you use them, you should feel bad.
 

Solu9

You can change this now in User CP.
Reaction score
216
Hehe Imp Midna. I understood very little of that to be honest :D

So the conclusion is?
 

vypur85

Hibernate
Reaction score
803
Uhh Imp... seems a lil too deep there.

> Solu9
If you're worried anything goes uncounted for, just convert any integer to real, and do your calculation. Nothing will go wrong from here. Use variable.

Set real = ......

As for the question you're wondering about, just use game text and test for yourself. Wouldn't take too long time I figure.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top