mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
19 lines
539 B
C++
19 lines
539 B
C++
#pragma once
|
|
#include <cassert>
|
|
#include <cmath>
|
|
|
|
/** Linear interpolation in logarithmic coordinates.
|
|
* Exponential interpolation is related to linear interpolation
|
|
* exactly in same way as geometric mean is related to arithmetic mean.
|
|
*/
|
|
constexpr double interpolateExponential(double min, double max, double ratio)
|
|
{
|
|
assert(min > 0 && ratio >= 0 && ratio <= 1);
|
|
return min * std::pow(max / min, ratio);
|
|
}
|
|
|
|
constexpr double interpolateLinear(double min, double max, double ratio)
|
|
{
|
|
return std::lerp(min, max, ratio);
|
|
}
|