HalRiyami
Member
Not quite sure where to put this but I figured since it's related to GML this is a suitable sub. I'm using the latest version of GMS 2.
So after about a few hours debugging my code to see why I had relatively huge rounding errors in my scripts, I was able to trace the source of my problems to the trigonometric functions in GMS 2. It seems that when feeding the functions large numbers, you end up with "major" rounding errors, I say "major" because they are actually pretty small but when precision is required they do compound like in my case. I was luckily able to find a workaround (use "mod 360" before feeding the number into the functions) but I still thought this is worth discussing.
Here is a comparison between GMS 2 output and WolframAlpha:
You can see that there is a significant loss in the precision of dsin when the input is large and this affects the entire spectrum of the trig function (degrees and radian versions).
I'm not sure if this is known and accepted or if GMS 2 should implement mod 360/mod 2pi in these functions.
Does anyone know anything about this?
So after about a few hours debugging my code to see why I had relatively huge rounding errors in my scripts, I was able to trace the source of my problems to the trigonometric functions in GMS 2. It seems that when feeding the functions large numbers, you end up with "major" rounding errors, I say "major" because they are actually pretty small but when precision is required they do compound like in my case. I was luckily able to find a workaround (use "mod 360" before feeding the number into the functions) but I still thought this is worth discussing.
Here is a comparison between GMS 2 output and WolframAlpha:
Function | GMS 2 | WolframAlpha | Error (wa - gms2)/wa |
var a = dsin(123456.123456); | -0.404558420181274 | -0.40476727150660 | 5.16E-04 |
var b = dsin(123456.123567); | -0.404558420181274 | -0.40476549998613 | 5.12E-04 |
var c1 = 123456.123456 mod 360; | 336.123456000001 | 336.123456000000 | -3.04E-15 |
var d1 = 123456.123567 mod 360; | 336.123567000002 | 336.123567000000 | -6.09E-15 |
var c = dsin(c1); | -0.404767006635666 | -0.40476727150658 | 6.54E-07 |
var d = dsin(d1); | -0.404765278100967 | -0.40476549998630 | 5.48E-07 |
You can see that there is a significant loss in the precision of dsin when the input is large and this affects the entire spectrum of the trig function (degrees and radian versions).
I'm not sure if this is known and accepted or if GMS 2 should implement mod 360/mod 2pi in these functions.
Does anyone know anything about this?