Explictly cast calculation to int, to allow std::min to work.

When compiling on FreeBSD, the calculation here returns an unsigned int. This causes a compile-time error with std::min, which cannot compare signed with unsigned integers.

This pull inserts an explicit cast, treating the calculated value as signed, keeping the compiler happy.