Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

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

Author Topic: "Real"-numbers bug  (Read 8045 times)

  • Rookie - level 3
  • ***
  • Posts: 128
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 11
  • User
    • View Profile
"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  [Select]
  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. (:

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 959
  • WC3 Models: 59
  • WC3 Tutorials: 13
  • WC3 Tools: 14
  • WC3 Maps: 12
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 15
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
"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

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

 

Blizzard Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena Starcraft II Modding Information Center
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!