23 template <
typename AnyNumber>
26 return number < 0 ? -number : number;
45 template <
typename AnyNumber>
46 constexpr AnyNumber
getConstrain(AnyNumber number, AnyNumber min, AnyNumber max)
48 return number < min ? min : (number > max ? max : number);
65 template <
typename AnyNumber>
66 AnyNumber
getMedian(AnyNumber unsortedNumbers[],
const unsigned int& arraySize)
69 for (
unsigned int i = 0; i < arraySize - 1; i++)
71 for (
unsigned int j = 0; j < arraySize - 1 - i; j++)
73 if (unsortedNumbers[j] > unsortedNumbers[j + 1])
75 auto swappedValue = unsortedNumbers[j];
76 unsortedNumbers[j] = unsortedNumbers[j + 1];
77 unsortedNumbers[j + 1] = swappedValue;
82 return unsortedNumbers[arraySize / 2];
103 template <
typename AnyNumber>
105 AnyNumber valueToMap, AnyNumber fromLow, AnyNumber fromHigh, AnyNumber toLow, AnyNumber toHigh)
107 return fromHigh == fromLow
109 : (valueToMap - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;