Real Number Functions

The following functions exist that deal with real numbers.

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:

  1. math_set_epsilon
  2. math_get_epsilon

We can split the functions that GameMaker: Studio has for dealing with real numbers into various categories:

Random Functions

These functions all deal with using random numbers and values:

  1. choose
  2. random
  3. random_range
  4. irandom
  5. irandom_range
  6. random_set_seed
  7. random_get_seed
  8. random_use_old_version
  9. randomize

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.

Trigonometric Functions

These are all trigonometric functions:

  1. arccos
  2. arcsin
  3. arctan
  4. arctan2
  5. sin
  6. tan
  7. cos
  8. darccos
  9. darcsin
  10. darctan
  11. darctan2
  12. dsin
  13. dtan
  14. dcos
  15. degtorad
  16. radtodeg
  17. lengthdir_x
  18. lengthdir_y

Rounding Functions

These are all functions that round or select values:

  1. round
  2. floor
  3. frac
  4. abs
  5. sign
  6. ceil
  7. max
  8. mean
  9. median
  10. min
  11. lerp
  12. clamp

Miscellaneous Functions

These are various different mathematic functions:

  1. exp
  2. ln
  3. power
  4. sqr
  5. sqrt
  6. log2
  7. log10
  8. logn
  9. int64

Back: Maths
Next: Vector Functions
© Copyright YoYo Games Ltd. 2018 All Rights Reserved