Weird real array value on loop

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
JASS:
//Here, I made a loop test.
scope LoopTest
    globals
        private constant integer COUNT = 5 //Number of loops
    endglobals

    private struct S1
        private real r1
        private real r2
        private real r3
        private integer i
        private real array ra1[COUNT]
        private real array ra2[COUNT]
        private real array ra3[COUNT]
        private static method onInit takes nothing returns nothing
            local thistype this = thistype.create()

            set .i = 0
            loop
                set .i = .i+1
                set .r1 = GetRandomReal(0,700)
                set .r2 = GetRandomInt(0,360)*bj_DEGTORAD
                set .ra1[.i] = 0+.r1*Cos(.r2)
                set .ra2[.i] = 0+.r1*Sin(.r2)
                set .r3 = SquareRoot((.ra1[.i]-0)*(.ra1[.i]-0)+(.ra2[.i]-0)*(.ra2[.i]-0))
                set .ra3[.i] = .r3/(.r3*.03125)

                call BJDebugMsg("======")
                call BJDebugMsg(R2S(.r3)+": Distance / ( Distance * 0.03125 ) is equal to...")
                call BJDebugMsg(R2S(.ra3[.i]))//Shows wrong value?
                //.ra3[.i] shows same values on all loops
                exitwhen .i == COUNT
            endloop
        endmethod
    endstruct
endscope
//Or is there something wrong?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Be very careful mixing reals and integers, ie. this part:
JASS:
set .r2 = GetRandomInt(0,360)*bj_DEGTORAD //Risky?  Wrap GetRandomInt in I2R.
set .ra1[.i] = 0+.r1*Cos(.r2) //"0" is an integer, maybe?  Use "0."  But why are you adding/subtracting 0 anyway?


If WC3 thinks it's doing a part of the calculation with integers, it will truncate any reals (eg. 1.8265 becomes 1).

I'd guess some valuable decimal data is getting lost in there, somewhere.
 

Artificial

Without Intelligence
Reaction score
326
> If WC3 thinks it's doing a part of the calculation with integers, it will truncate any reals (eg. 1.8265 becomes 1).
Such truncation only happens when explicitly casting a real to an integer or when dividing an integer with an integer (so e.g. 2/3 becomes 0, whereas 2.0/3.0 becomes 0.667).

> [ljass]set .ra3[.i] = .r3/(.r3*.03125)[/ljass]
Hmm, let's see what that calculation there is:
Code:
[u]     .r3     [/u]
.r3 * 0.03125        || Reduce .r3

= [u]   1   [/u]
  0.03125
Oh, so the value isn't related to [ljass].r3[/ljass] in any way. I would tell you how to change that calculation, but I have no idea what you're trying to achieve with it. Your variable names ain't that descriptive.
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
Be very careful mixing reals and integers, ie. this part:
JASS:
set .r2 = GetRandomInt(0,360)*bj_DEGTORAD //Risky?  Wrap GetRandomInt in I2R.
set .ra1[.i] = 0+.r1*Cos(.r2) //"0" is an integer, maybe?  Use "0."  But why are you adding/subtracting 0 anyway?


If WC3 thinks it's doing a part of the calculation with integers, it will truncate any reals (eg. 1.8265 becomes 1).

I'd guess some valuable decimal data is getting lost in there, somewhere.

And about that .r1*Cos thingy, 0 was just a replacement of someone's X or Y, and I wan't it at middle, and yes, removing 0 is also in middle. I didn't just notice.

Your variable names ain't that descriptive.
Yeah lol, many people tells that to me, even my big bro

EDIT: @Artificial, I kinda don't get what you mean but
Let
.r3 be 300.

.r3 / (.r3 * .03125 ) = 300/6.25 = 92.30769....
Why does it tells 32?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top