Mathf.FloorToInt doesn't really handle binary waste.

I have the following method:

public static VoxelOffset RotateOffset(VoxelOffset offs, VoxelOffset rotation)
		{
			Vector3 rotated = RotationToQuaternion(rotation) * offs.ToVector3();
			VoxelOffset final = new VoxelOffset(rotated);
			Debug.Log("Rotated: " + rotated.x.ToString() + ";" + rotated.y.ToString() + ";" + rotated.z.ToString() + " Final: " + Mathf.FloorToInt(rotated.x) + ";" + Mathf.FloorToInt(rotated.y) + ";" + Mathf.FloorToInt(rotated.z));
			Debug.Log("Direct test: " + Mathf.FloorToInt(-1f));
			return final;
			//return new VoxelOffset(RotationToQuaternion(rotation) * offs.ToVector3());
		}

The problem is:
Unit’s Mathf.FloorToInt converts float value “-1” to -2.
But not the constans one. I got the -1 from a vector rotation and I need it to be floored.

The Debug.Log displays a simple “-1” while the Mathf.Floor returns -2.
Probably some bits are messed up.

Any idea how can I solve this?

Depends what you mean by binary waste. If you are performing a calculation that should produce exactly -1 according to conventional math, but the result is less than that and floors to -2, you are dealing with a floating point precision problem and have to work around it in a way that works for your use case.

If you have no functional problem, but are just wondering why Debug.Log prints exactly -1 but flooring produces -2 it’s just that single.ToString() has a default setting for how many decimal places it shows and might not show that your number is actually -1.0000000000001. You can use for example the G format specifier to determine the amount of decimal places to show rotated.x.ToString("G12")

If rotated.x == -1f prints true but Mathf.FloorToInt(rotated.x)… we’ll discuss if that happens.