Download

FMath::Wrap behavior

This function in UnrealMathUtility.h seems to be weird or is it just me ?

/** Wraps X to be between Min and Max, inclusive */
	template< class T >
	static FORCEINLINE T Wrap(const T X, const T Min, const T Max)
	{
		T Size = Max - Min;
		T EndVal = X;
		while (EndVal < Min)
		{
			EndVal += Size;
		}

		while (EndVal > Max)
		{
			EndVal -= Size;
		}
		return EndVal;
	}

Considering Min = 0, Max = 5 :
for X = 5 it returns 5
for X = 6 it returns 1
for X =0 it returns 0
for X = -1 it returns 4

Isn’t it supposed to be X=6 => 0, x=-1 => 5 ?
Or maybe make the max exclusive and for X=5 => 0, X=6 => 1 ?