SOLVED math_set_epsilon is not working properly

Plura

Member
I run into a problem with math_set_epsilon();
Can't set below 0.01
Here is my code:
GML:
var epsilon_value = string(math_get_epsilon());
show_debug_message("epsilon_value Default: "+epsilon_value);
math_set_epsilon(0.01);
epsilon_value = string(math_get_epsilon());
show_debug_message("epsilon_value for [0.01]: "+epsilon_value);
math_set_epsilon(0.001);
epsilon_value = string(math_get_epsilon());
show_debug_message("epsilon_value for [0.001]: "+epsilon_value);
math_set_epsilon(0.0001);
epsilon_value = string(math_get_epsilon());
show_debug_message("epsilon_value for [0.0001]: "+epsilon_value);
This is the console output:
epsilon_value Default: 0.00
epsilon_value for [0.01]: 0.01
epsilon_value for [0.001]: 0.00
epsilon_value for [0.0001]: 0.00

IDE 2.3.5.589 RUNTIME 2.3.5.458 - Platform: Windows VM
 
Last edited:

chamaeleon

Member
string() will give you two digits after the decimal point. Use string_format() for more.
GML:
var epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value Default: "+epsilon_value);
math_set_epsilon(0.01);
epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value for [0.01]: "+epsilon_value);
math_set_epsilon(0.001);
epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value for [0.001]: "+epsilon_value);
math_set_epsilon(0.0001);
epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value for [0.0001]: "+epsilon_value);
Code:
epsilon_value Default: 0.0000100000000000
epsilon_value for [0.01]: 0.0100000000000000
epsilon_value for [0.001]: 0.0010000000000000
epsilon_value for [0.0001]: 0.0001000000000000
 

Plura

Member
Thanks!
string() will give you two digits after the decimal point. Use string_format() for more.
GML:
var epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value Default: "+epsilon_value);
math_set_epsilon(0.01);
epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value for [0.01]: "+epsilon_value);
math_set_epsilon(0.001);
epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value for [0.001]: "+epsilon_value);
math_set_epsilon(0.0001);
epsilon_value = string_format(math_get_epsilon(), 0, 16);
show_debug_message("epsilon_value for [0.0001]: "+epsilon_value);
Code:
epsilon_value Default: 0.0000100000000000
epsilon_value for [0.01]: 0.0100000000000000
epsilon_value for [0.001]: 0.0010000000000000
epsilon_value for [0.0001]: 0.0001000000000000
 

Plura

Member
Well, I still have a problem displaying mouse X position with decimals.
Create event:
Code:
math_set_epsilon(0.000001);
Step event
GML:
show_debug_message(mouse_x);
won't display in decimals.
This is a real number and not a string.
I can't get even to two decimal places!
 

chamaeleon

Member
I don't want to display a string. Just a raw format from mouse_x.
Since gms only shows 2 decimal digits by default (or maybe none if it is effectively an integer value), you actually do, using the function mentioned a few times now. The debug function is converting the floating point value to a string in order to display it. If the format is not to your liking you need to convert it to a string in the format you do want.

Epsilon is used for changing comparison operator behavior, not how a number is converted to a string.
 

Plura

Member
So, my mouse cursor doesn't get any decimal values, everything is rounded like an integer.
Step:
GML:
math_set_epsilon(0.00001);
var x_value = mouse_x;
var value_as_string = string_format(x_value, 0, 2);
show_debug_message(x_value);
show_debug_message(value_as_string);
When I move the cursor this is the output:

Code:
305
305.00
307
307.00
308
308.00
304
304.00
293
293.00
281
281.00
274
274.00
Why is every mouse position always a rounded value?
 

chamaeleon

Member
Why is every mouse position always a rounded value?
string() documentation
If the real number is an integer, it will be saved with no decimal places, otherwise, it will be saved with two decimal places. If you require more decimal places, then use the function string_format().
Although I do not have insider knowledge of the internals, I am going to assume providing a single number as the parameter for show_debug_message() performs an implicit string() call on it in order to display the value.
 

GMWolf

aka fel666
So, my mouse cursor doesn't get any decimal values, everything is rounded like an integer.
Step:
GML:
math_set_epsilon(0.00001);
var x_value = mouse_x;
var value_as_string = string_format(x_value, 0, 2);
show_debug_message(x_value);
show_debug_message(value_as_string);
When I move the cursor this is the output:

Code:
305
305.00
307
307.00
308
308.00
304
304.00
293
293.00
281
281.00
274
274.00
Why is every mouse position always a rounded value?
Under Windows the mouse cursor position is given as integers.
GMS will then apply a transformation to get it in room space rather than window space. But if your view is just the size of your room and at 0,0 you will still just get integers.

Try scaling your view by 0.5 and see if you get fractional mouse positions.
 

Plura

Member
Try scaling your view by 0.5 and see if you get fractional mouse positions.
I tried resizing the view and it is impossible to get decimal values. I remember that I used to get decimals in the older version of the game maker.
 
Top