vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

"Real"-numbers bug

rvonsonsnadtz · 8113

0 Members and 1 Guest are viewing this topic.

"Real"-numbers bug
on: May 17, 2013, 06:10:09 AM

So, alot of people "know" that a real of 5.00 sometimes converted to integer would give a integer of 4.. (and the same for other "whole" reals aswell)
 Now, I *could* buy the ordinary explanation (the reals sometimes are 4.9999 or 5.0001 instead of 5), except for one thing; I had a number that in ordinary cases was 1.00 (or 100%) that affected another number. However, when 0.05 (5%) was added and removed the affected number decreases as well as the integer-conversion of the modifier. I needed to doublecheck that the decrease was a 1-time thing only (thereby fixing it by increasing the 1.00 to 1.0001 or something). But my tests indicate that it was a lowering of the amount every time.. Here is a small report, if any1 has more information of the subject, please feel free to add.
Theory: A addition and subtraktion with the same real with digits of a real variable seems to actually lower the variable when it should have been returned to the same. 
 Test1: To quickly see if it works like that, I created a simple loop running through 300 times that adds and removes the same amount from a global real variable. A bjdebugmsg with the real*10000 (to see otherwise "hidden" digits) is called before and after the loop. Code:
Code: jass
  1. globals
  2.     real testnumber = 1.00
  3.     constant real TNA = 0.05
  4. endglobals
  5.  
  6. function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
  7. local integer i = 0
  8. call BJDebugMsg("R2I: " + I2S(R2I(testnumber)) + " and R * 10000: " + R2S(testnumber*10000))
  9. loop
  10.     exitwhen i > 300
  11.     set testnumber = testnumber + TNA
  12.     set testnumber = testnumber - TNA
  13.     set i = i + 1
  14. endloop
  15. call BJDebugMsg("R2I: " + I2S(R2I(testnumber)) + " and R * 10000: " + R2S(testnumber*10000))
  16. endfunction
  17.  
  18. //===========================================================================
  19. function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
  20.     set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
  21.     call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
  22.     call TriggerRegisterPlayerChatEvent(gg_trg_Untitled_Trigger_001, Player(0), "-test", true)
  23. endfunction
  24.  
To test if this is the way in non-loops, I tried the samething without loops, and it still decreases every time it is tested, but with lower speed (the loop generated about a minus of 3.5*10^-4 in the loop, the unlooped version had a to low number to get any good approx-number at all, but it seemed to be a little below 1.5*10^-5.
 A testmap is attached. (:



"Real"-numbers bug
Reply #1 on: May 18, 2013, 08:40:42 AM

Yes, converting or typecasting from real to integer is a pain in the ass in JASS. The best solution is to keep everything as "real" as possible.

In my experience, I avoid totally the typecasting.

I'll check the code this evening... no2w that I have, at last, some time :D


 

Power of Corruption - A Warcraft III altered melee map   Chaos Realm - The world of Game modders and wc3 addicts     WC3JASS.com - The JASS Vault   Jetcraft - A Starcraft II mod