Type of variable after division

Jinxx

New Member
Reaction score
4
Is there any way to find out if the division of two integers is another integer?

I'm asking because this is what I need (roughly illustrated):

If [(Hero's Level) / 3 = Integer], then (do some stuff, blah blah...)

So, for hero's level, let's say, 6, this would give us 6/3=2, which is an integer, and the rest of the code would fire, but if the hero is level 7, 7/3=2.333 which is a real, and the rest of the code would not fire.

Help pl0x? :)
 

Jedi

New Member
Reaction score
63
Maybe you need to use a real comparasion

Trigger:
  • If ((Real((Level of (Hero)))) / 3.00) Equal to SomeRealNumber



Real(level of hero) = Convert integer to real
 

Bogrim

y hello thar
Reaction score
154
Yes, first do the equation with integers then do the equation with reals. Compare the two results (as a real comparison) and if the numbers don't match, the result isn't an integer.
 

Jinxx

New Member
Reaction score
4
Yes, first do the equation with integers then do the equation with reals. Compare the two results (as a real comparison) and if the numbers don't match, the result isn't an integer.

I don't get it, how would that help? Also, how would I do the equation with intigers, then with reals? The equation is always the same, all that's different is the number it puts out... :confused:
 

meOme

New Member
Reaction score
31
In Jass: if ( a - (a/b)*b == 0 ) then
(for example: 7 - (7/3)*3 = 7 - 2*3 = 7 - 6 = 1 =/= 0 --> not an integer)

In GUI just use a Modulo b (Modulo returns the rest of an integer division, just like the equation I used in the Jass version)
 

tooltiperror

Super Moderator
Reaction score
231
In Jass: if ( a - (a/b)*b == 0 ) then
(for example: 7 - (7/3)*3 = 7 - 2*3 = 7 - 6 = 1 =/= 0 --> not an integer)

In GUI just use a Modulo b (Modulo returns the rest of an integer division, just like the equation I used in the Jass version)

JASS:

 function Even takes integer i returns boolean
       if ( i-(i/2)*2 == 0 ) then
         return true
       endif
     return false
 endfunction
// Maybe?
 

Bogrim

y hello thar
Reaction score
154
I don't get it, how would that help? Also, how would I do the equation with intigers, then with reals? The equation is always the same, all that's different is the number it puts out... :confused:
Not at all. The difference between integer and real numbers are decimals, meaning that integer results always round the number, making it possible to see whether the result of a real was a whole number (an integer). GUI Example:

Trigger:
  • Actions
    • Set Temp_Integer = ((Hero level of (Triggering unit)) / 3)
    • Set Temp_Real = ((Real((Hero level of (Triggering unit)))) / 3.00)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Real(Temp_Integer)) Equal to Temp_Real
      • Then - Actions
      • Else - Actions
 
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