Bug in builtin function is_real

S

Spinningmind

Guest
Found what seems like a bug in GameMaker Studio 2:

is_real() returns false when passed an enum even though enums are treated as ints in every other case I can find.

The documentation for is_real says it "returns whether a given variable is a real number (single, double or integer) or not" and passing the enum to is_int64 returns true, so it seems is_real should be able to tell that it's an integer and respond correctly.
 

Yal

🐧 *penguin noises*
GMC Elder
Have you reported this bug to the bug tracker? ("Help --> Report a Bug" should open the page up automatically in your default browser)
 
An integer is a separate type from real in GameMaker. See the typeof() entry in the manual for a list of types.

Also, enums are their own type, and can only be integers, from the manual page Data Types:

The enum entries can only be integer numbers or expressions with previous enums that evaluate to an integer number, and by default are numbered from 0 upwards, so our example given above would default to red = 0, orange = 1, yellow = 2, etc...
Edit : But yeah, given that the manual says is_real() can identify integers, its a bug in the docs / or function.
 
S

Skeletor

Guest
The documentation for is_real says it "returns whether a given variable is a real number (single, double or integer) or not"
The manual doesn't say that at all, it says this

This function returns whether a given variable is a real number or not.
Nothing about single, double, or integer is mentioned.

A 'real' is not an integer. A real is a double precision number. As a result an enum won't be a real.


** EDIT - Sorry, turns out I was viewing the online manual for 1.4 **
 
Last edited by a moderator:
The manual doesn't say that at all, it says this



Nothing about single, double, or integer is mentioned.

A 'real' is not an integer. A real is a double precision number. As a result an enum won't be a real.
Looks like that is from the 1.4 documentation.
 
S

Skeletor

Guest
Looks like that is from the 1.4 documentation.
Interesting. My bad.

Either the 1.4 documentation is correct for 2.x in this case. Meaning the manual is wrong or there is in fact a bug.

Maybe try this then?

Code:
if( !is_nan(value) )
{
}
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
IIRC enum values are compiled as 64-bit integers, so you'd want is_int64.

Or, save yourself some sanity, and make an is_number script that's is_real||is_bool||is_int32||is_int64
 
S

Spinningmind

Guest
IIRC enum values are compiled as 64-bit integers, so you'd want is_int64.

Or, save yourself some sanity, and make an is_number script that's is_real||is_bool||is_int32||is_int64
Indeed! I've replaced it with a custom one that does what I expect. Hopefully posting here will save someone else from an hour or two of head scratching.
 
S

Spinningmind

Guest
Have you reported this bug to the bug tracker? ("Help --> Report a Bug" should open the page up automatically in your default browser)
Thanks for the tip. This is the first time I've found something that seems like it may be a legit bug rather than just something I'd prefer to work differently than it does so I hadn't noticed the report menu option.
 
Top