GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2022-04-01 08:39:46

gnysek
Member
Registered: 2011-12-29
Posts: 28

is_int

Edit: updated with faster version by @maras:

Expandfunction is_int(number) {
    return floor(number) == number;
}

Old, less efficient version:

Expandfunction is_int(number) {
    return sign(frac(number)) == 0;
}

Results for both:

Expandshow_debug_message(is_int(1)); // 1
show_debug_message(is_int(1.0)); // 1
show_debug_message(is_int(1.1)); // 0
show_debug_message(is_int(-1)); // 1
show_debug_message(is_int(-1.0)); // 1
show_debug_message(is_int(-1.1)); // 0
show_debug_message(is_int(0)); // 1

Last edited by gnysek (2022-06-27 04:34:44)

Offline

#2 2022-04-09 06:02:20

maras
Member
Registered: 2021-04-25
Posts: 26
Website

Re: is_int

Hmm wouldn't this be a little bit faster?

Expand return floor(number) == number; 

I'm on the official GM discord > maras#5104

Offline

#3 2022-06-27 04:33:19

gnysek
Member
Registered: 2011-12-29
Posts: 28

Re: is_int

Yes, it would be faster.
I've made additional tests on numbers which are shown as 1.00 by show_debug_message or draw_text, but are "0.99999999999998" when using string_format(), and it gives same results in every case.

Offline

Board footer

Powered by FluxBB