• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] IsInteger

Status
Not open for further replies.
Level 21
Joined
Mar 19, 2009
Messages
444
JASS:
function IsRational takes real r returns boolean
    return R2I(r) == r
endfunction

That should work, yeah. Only the () are useless.

Note: the "==" operator just take care about the first 3 numbers after the coma.

Example: R2I(1.254) == 1.254 will work (and return false) but R2I(1.0004) == 1.0004 will not work (the == will just check 1.000).
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
You're not really determining whether or not the value is an integer, rather whether a real number is a whole number. If there was a modulus operation then it would be even cooler:

Code:
if (yourNumber % 1 == 0) {
    // "yourNumber" is a whole number.

}
 
Level 10
Joined
Jun 26, 2005
Messages
236
If you don't declare the number with a decimal place, it will start to fail at around 1.678*10^7.

Try calling:

IsRational(16778079) - this will be false.
IsRational(16778079.) - this will be true.
 
Status
Not open for further replies.
Top