Math computation

I want to make sure I’m checking my math calculations properly here.

I’m calculating things for how they will scale on my screen, so my variables are all ints, but to make sure nothing scales too high, I’d want my calculations to truncate, and not round.

I’m… fairly sure that’s how these are going to work, but I have little experience with C# so I’d like to just make sure of this.

int a;
int b;

a = Mathf.Min(Screen.width / 64, Screen.height / 56) - 3;
b = (Screen.width - (64 * (a + 3))) / 4;

It’s the dividing that I’m worried about. If a divided number comes out to be 4.98, I’m counting on it being truncated to 4, because if it is rounded to 5 it will screw everything up.

If I remember my C++ right, it would be truncated. But this isn’t C++ so I just want to make sure.

C# rounds towards zero when dividing integers or when converting a float to int.

I highly recommend using Mathf.Round(), Mathf.CeilToInt(), Mathf.Floor(), or something similar. Your intentions will then be clear and doesn’t rely on the esoteric workings of C#.

Sources:
http://msdn.microsoft.com/en-us/library/aa691373(v=vs.71).aspx
http://msdn.microsoft.com/en-us/library/aa691289(v=vs.71).aspx