1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Bug in builtin function is_real

Discussion in 'Programming' started by Spinningmind, Nov 5, 2019.

  1. Spinningmind

    Spinningmind Member

    Joined:
    Nov 5, 2019
    Posts:
    3
    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.
     
  2. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,867
    Have you reported this bug to the bug tracker? ("Help --> Report a Bug" should open the page up automatically in your default browser)
     
    Spinningmind likes this.
  3. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,267
    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:

    Edit : But yeah, given that the manual says is_real() can identify integers, its a bug in the docs / or function.
     
    Skeletor likes this.
  4. Skeletor

    Skeletor Member

    Joined:
    Oct 31, 2019
    Posts:
    14
    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.


    ** EDIT - Sorry, turns out I was viewing the online manual for 1.4 **
     
    Last edited: Nov 6, 2019
  5. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    867
    Umm:
    upload_2019-11-6_17-15-29.png
     
    Skeletor likes this.
  6. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,267
    Looks like that is from the 1.4 documentation.
     
  7. Skeletor

    Skeletor Member

    Joined:
    Oct 31, 2019
    Posts:
    14
    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) )
    {
    }
    
     
    IndianaBones likes this.
  8. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,426
    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
     
    Yal and IndianaBones like this.
  9. Spinningmind

    Spinningmind Member

    Joined:
    Nov 5, 2019
    Posts:
    3
    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.
     
  10. Spinningmind

    Spinningmind Member

    Joined:
    Nov 5, 2019
    Posts:
    3
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice