Detecting if Real is an Integer

Tawnttoo

New Member
Reaction score
36
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,462
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
36
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
Reaction score
963
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,462
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
36
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,462
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
36
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
36
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
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      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