mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +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);
|
|
}
|