Real numbers in GameMaker: Studio are considered double-precision floating-point numbers, that is to say that they have a
decimal point in them with no fixed number of digits either before or after the point. 2, for example, is a binary integer
but 2.0 is a floating point real. This distinction between integers and floats is very important when dealing with cross platform
development as the precision of calculations made on a Windows pc is not the same as the precision of those same
calculations when made on a mobile device. This means that you should pay particular attention when making comparisons, for example:
if image_index == 1 {do something...}
Now that may appear to work, but due to the way that floating point maths works, it may mean that image_index
actually equals 1.00000000001, in which case the comparison will never result in a true result and the code running.
These types of errors can be quite hard to debug and so it is always good to be aware of them and to plan ahead and use
other means of checking values or to use the appropriate flooring or rounding functions (listed below) to convert the
number to check into an integer. For example the above code could be written as:
if floor(image_index) == 1 {do something...}
NOTE: On the YoYo Compiler target platforms (those marked (YYC)), expressions and functions are evaluated from
left to right, while on all other target platforms they are evaluated from right to left, meaning that this:
val = max(num, ++num, num++);
will give different results depending on the platform.
We can also use a special function available in GameMaker: Studio to set the epsilon value for floating point maths.
When a real number is rounded to the nearest floating point number, the epsilon (also know as "machine epsilon")
forms an upper bound on the relative error, and you can set the epsilon value using this special function:
◦math_set_epsilon
◦math_get_epsilon