This function sc2_sqrt(x) produces the same results as SC2 now.
The real moral here is just that SC2 uses a fixed-precision data type as described by Talv. If any unusual behavior comes up, it's because of how the values are stored.
I was recently exposed to the oddity of the SquareRoot function in Starcraft 2's Engine.
For example
SquareRoot(10.5) ==> 3.2402
This is quite far, and in a strange manner so, from the correct value (computed from a python console):
10.5**0.5 = 3.24037034920393
However, it seems to do better with integers (though I am still using the fixed/real version), for example it computes the square root of 24 as 4.899, which is accurate at least to that many digits.
Does anyone know what this function is actually doing? Is there a way to find out? This is quite curious.
Thanks, the specification for their fixed type is very helpful. I will investigate further in my spare time :)
It looks like it's very simple knowing that. Reproducing SC2's results was as simple as (python again):
This function sc2_sqrt(x) produces the same results as SC2 now.
The real moral here is just that SC2 uses a fixed-precision data type as described by Talv. If any unusual behavior comes up, it's because of how the values are stored.
I was recently exposed to the oddity of the SquareRoot function in Starcraft 2's Engine.
For example
This is quite far, and in a strange manner so, from the correct value (computed from a python console):
However, it seems to do better with integers (though I am still using the fixed/real version), for example
it computes the square root of 24 as 4.899, which is accurate at least to that many digits.
Does anyone know what this function is actually doing? Is there a way to find out? This is quite curious.