80 maxInputValue = maxInputValueToUse;
81 scaler = FloatType (numPoints - 1) / (maxInputValueToUse - minInputValueToUse);
82 offset = -minInputValueToUse * scaler;
84 const auto initFn = [functionToApproximate, minInputValueToUse, maxInputValueToUse, numPoints] (
size_t i)
86 return functionToApproximate (
88 minInputValueToUse, maxInputValueToUse,
89 jmap (FloatType (i), FloatType (0), FloatType (numPoints - 1), minInputValueToUse, maxInputValueToUse))
93 lookupTable.initialise (initFn, numPoints);
97template <
typename FloatType>
99 FloatType minInputValue,
100 FloatType maxInputValue,
102 size_t numTestPoints)
104 jassert (maxInputValue > minInputValue);
106 if (numTestPoints == 0)
107 numTestPoints = 100 * numPoints;
109 LookupTableTransform transform (functionToApproximate, minInputValue, maxInputValue, numPoints);
113 for (
size_t i = 0; i < numTestPoints; ++i)
115 auto inputValue = jmap (FloatType (i), FloatType (0), FloatType (numTestPoints - 1), minInputValue, maxInputValue);
116 auto approximatedOutputValue = transform.
processSample (inputValue);
117 auto referenceOutputValue = functionToApproximate (inputValue);
119 maxError = jmax (maxError, calculateRelativeDifference ((
double) referenceOutputValue, (
double) approximatedOutputValue));
126template <
typename FloatType>
129 static const auto eps = std::numeric_limits<double>::min();
131 auto absX = std::abs (x);
132 auto absY = std::abs (y);
133 auto absDiff = std::abs (x - y);
138 return absDiff / absY;
143 return absDiff / std::min (absX, absY);
147template class LookupTable<float>;
148template class LookupTable<double>;
150template class LookupTableTransform<float>;
151template class LookupTableTransform<double>;