Detecting if Real is an Integer

Tawnttoo

New Member
Reaction score
35
The title may be misleading but what I need is a way to check if a real is in this form: X.00 as in a whole number?
 

Accname

2D-Graphics enthusiast
Reaction score
1,456
if (real to int( REAL ) ) is equal to REAL

real to integer always rounds down. no matter what values follow the floating point. 7.1 and 7.99 both are 7 if converted into an integer.
 

Tawnttoo

New Member
Reaction score
35
But if I'm using a 0.05 second interval and reduce a real bu 0.05 each time, how can I check if it is a whole number?
 

mylemonblue

You can change this now in User CP.
Reaction score
7
I think so. Because what your method would do is once the .05 makes, say, 6 fall below 6.00 to 5.95 it would automatically reduce it to 5.00 which isn't what he wants. What I see is he wants it to tell him once the number becomes a whole number like so:

Each line is after every x seconds.
6.00 true
5.50 false
5.40 false
5.30 false
...
...
5.10 false
5.00 true
4.90 false

and so on.
 

muzk

Member
Reaction score
3
Just transform into a integer your real and then sustract, if it is equal to 0 then your number is a integer, if not, its a real. Example:
5.0 is your real
5 is the integer of that real
5.0-5 = 0
So your real is an integer.

Other
5.5 is your real
5 is the integer part of that real
5.5-5 = 0.5 , so your real isnt a integer.
 

drol

New Member
Reaction score
7
Just transform into a integer your real and then sustract, if it is equal to 0 then your number is a integer, if not, its a real. Example:
5.0 is your real
5 is the integer of that real
5.0-5 = 0
So your real is an integer.

Other
5.5 is your real
5 is the integer part of that real
5.5-5 = 0.5 , so your real isnt a integer.
Just as a hint: to do this in GUI you should use "Convert Real to Integer".

The check will be something like this:
Code:
YOURNUMBER - (convertToReal (convertToInt ( YOURNUMBER ) )) == 0
 

Romek

Super Moderator
Staff member
Reaction score
960
There's no need to subtract. Just compare the value to the original real, rather than subtracting and comparing to 0.
 

Accname

2D-Graphics enthusiast
Reaction score
1,456
I think so. Because what your method would do is once the .05 makes, say, 6 fall below 6.00 to 5.95 it would automatically reduce it to 5.00 which isn't what he wants. What I see is he wants it to tell him once the number becomes a whole number like so:

Each line is after every x seconds.
6.00 true
5.50 false
5.40 false
5.30 false
...
...
5.10 false
5.00 true
4.90 false

and so on.
maybe i should give some examples to clarify:

lets look at this:
if (real to int( REAL ) ) is equal to REAL

lets say our value REAL is 6.00
we check
if (real to int(6.00) == 6.00) => if (6 == 6.00) => true

we substract 0.25 and check:
if (real to int (5.75) == 5.75) => if (5 == 5.75) => false

we substract 0.25 and check:
if (real to int (5.5) == 5.5) => if (5 == 5.5) => false

we substract 0.25 and check:
if (real to int (5.25) == 5.25) => if (5 == 5.25) => false

we substract 0.25 and check:
if (real to int (5.0) == 5.0) => if (5 == 5.00) => true

we substract 0.25 and check:
if (real to int (4.75) == 4.75) => if (4 == 4.75) => false

... and so on and so on...

that means we will get TRUE whenever REAL is a whole number like 1.00, 2.00, 3.00, 4.00, and so on.
We will get FALSE whenever there are other digits then 0 after the floating point. for example 5.47 because (5 != 5.47)
 

Tawnttoo

New Member
Reaction score
35
So, if I'm using the 0.05-second-interval trigger for 20 seconds, do I have to check if its 20.00, 19.00, 18.00 etc in conditions? Using 'Or-multiple conditions'?
 

Accname

2D-Graphics enthusiast
Reaction score
1,456
no, you just do the following:
(written in pseudo code)

Code:
MyReal = 20

loop do
  MyReal -= 0.05
  if (MyReal.to_int) == MyReal
     comment: ITS AN INTEGER! HURRAY!
  else
     comment: ITS NOT AN INTEGER.....
  end
end
 

Tawnttoo

New Member
Reaction score
35
I have this:

Trigger:
  • Game - Display to (All players) the text: ((String((Load (Key duration) of (Key (Picked unit)) from Surge_Hash))) + ( not equal to + (String((Integer((Load (Key duration) of (Key (Picked unit)) from Rune_Hash)))))))


It always shows the integer as 0.
 

muzk

Member
Reaction score
3
JASS:
        if RqI(6.0) then
            call BJDebugMsg("true!")
        else
            call BJDebugMsg("false!")
        endif

Obiusly it shows false cuz the result is 0 == 0.0

Other thing,
Logicaly, A - R2I(A) == 0.0 is the same as A == R2I(A)
 

DioD

New Member
Reaction score
57
equal comparison will fail, it will count 6.001 and 6.002 as same reals, but this is not true.

with not equal it will detect fine.
 

muzk

Member
Reaction score
3
did you tested?
anyways we are comparing with the integer part I dont see your point :(
 

Tawnttoo

New Member
Reaction score
35
For some reason, it sets it to an integer below when it hits a whole number. E.g. 18.00 ---> 17

EDIT: got it to work by adding 1 to the integer. Thanks for the help!
 

Bribe

vJass errors are legion
Reaction score
67
The [LJASS]ModuloReal[/LJASS] function may interest you. See also [LJASS]ModuloInteger[/LJASS]. If I wanted to see if an integer was a multiple of 10...

JASS:
if ModuloInteger(i, 10) == 0 then
    // i is divisible by 10... some examples of i would be -50, 60, or even 0.
endif
 
General chit-chat
Help Users
  • jonas jonas:
    wow, happy birthday
    +1
  • The Helper The Helper:
    thank you very much!
    +1
  • The Helper The Helper:
    I have been seeing a number of posts from current members being spam leading me to believe the bots might be brute forcing the register system guessing old users passwords
  • The Helper The Helper:
    The last 3 user bans have been this way
  • The Helper The Helper:
    no more new instances since the last message so it might not be a big thing
  • Ghan Ghan:
    We've seen that on RpNation as well. I think it's password reuse. Passwords are being compromised elsewhere and then tried on different sites.
    +1
  • The Helper The Helper:
    Happy Thursday hope everyone has an Amazing Day!
  • tom_mai78101 tom_mai78101:
    I'm having my Amazon Day.
  • tom_mai78101 tom_mai78101:
    Just resting from the cloud.
  • vypur85 vypur85:
    Hey all! Hope everyone is doing fine!
    +2
  • jonas jonas:
    Hi Vypur, how are you doing?
  • vypur85 vypur85:
    Hey hey all's good here. Last year I dropped a message saying I'll be moving to China for a new job. Here I am in China now for the padt year!
    +1
  • vypur85 vypur85:
    Past*
  • vypur85 vypur85:
    Missing this place much. Wish that WE is still a thing now, just like the past when everything was so active.
  • The Helper The Helper:
    Are you in Taiwan or Mainland China?
  • vypur85 vypur85:
    I'm in Mainland. At Wuhan. The place where all shit began...
  • vypur85 vypur85:
    Lol. After one whole year here, I learnt a few good and bad things about China.
  • vypur85 vypur85:
    Everything you do is pretty much observed. There are eyes everywhere... They can even read your Wechat texts if they want to...
  • vypur85 vypur85:
    But it's pretty much safe here. Walking alone in the middle of the night in weird dark alleys is completely safe...
  • The Helper The Helper:
    that is cool
  • The Helper The Helper:
    at least its safe
  • jonas jonas:
    Haha, I remember taking a taxi in Beijing last year and the cabbie lectured me about how safe China is compared to America, then he made a gun with his fingers and pretended to shoot in the air while making "pew pew" sounds
  • jonas jonas:
    I pmed you my wechat, I'm thinking about visiting wuhan this year
  • jonas jonas:
    Which company do you work for?

    The Helper Discord

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top