Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

[Bug] Precision Issue with Modulo

A topic by Yokin created Dec 05, 2022 Views: 205 Replies: 3
Viewing posts 1 to 4
(1 edit)

On live reloads it seems like the precision of modulo is reduced, or something like that.

Essentially this code:

if(live_call()) return live_result;

show_debug_message(10000000000000001);
show_debug_message(10000000000000001 % 2);

Results in this debug output:

It seems to work normally with one less digit, but it does cause minor issues for fetching the digits of large binary numbers. Using the most recent version of GMLive!!

(4 edits)

The precision seems to be lost at the point where n gets initialized as an int64 (54 binary digits), although modulo still works normally for smaller int64 types. (Could be a coincidence).

Developer (1 edit)

Man, I love GameMaker. What a good, transparent language with predictable behaviour:

function scr_test(){
    var a = int64(10000000000000001);
    var tr = real(2);
    var ti = int64(2);
    var ta = 2;
    show_debug_message(a % tr); // 0
    show_debug_message(a % ti); // 1
    show_debug_message(a % ta); // 0
    show_debug_message(a % 2); // 1
}

I don’t know what I’m supposed to do with this. The modulo operator works differently depending on whether you give it a variable or the same value directly.

Highly wack-o, maybe GameMaker initializes integer literals in operations as int64s for precision? Either way, I’ll be taking that int64 workaround for now