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:
We can split the functions that GameMaker: Studio has for
dealing with real numbers into various categories:
These functions all deal with using random numbers and values:
NOTE: When using the random functions, GameMaker: Studio maintains the same random seed every time you start the game. This makes debugging much easier as you are guaranteed that the random functions will always return the same value, however should you not wish this to happen, you must first set a new random seed at the very start of the game, either using randomize or random_set_seed.
These are all trigonometric functions:
These are all functions that round or select values:
These are various different mathematic functions: