int bb = BurstMethod(2 * Mathf.PI); // =2048
int cc = CsharpMethod(2 * Mathf.PI); // =2047
[BurstCompile]
static int BurstMethod(float b)
{
const float a = 1024f / Mathf.PI;
return (int)(b * a);
}
static int CsharpMethod(float b)
{
const float a = 1024f / Mathf.PI;
return (int)(b * a);
}
Hi, this is expected behavior. Internally mono promotes all floating-point number operations to double precision and then converts it back down into single-precision (float) when storing it. While Burst does all the calculations as single-precision as you’d expect when working with float types. This is the same behavior you’d get from equivalent C/C++ code or from CoreCLR.