practice_geomethicMeandian/cpp_impl/src/geometric_mean.cpp

22 lines
361 B
C++
Raw Normal View History

2021-05-01 13:31:59 +00:00
#include "geometric_mean.hpp"
#include <cmath>
#include <string>
#include "helpers.hpp"
double geometric_mean(double a, double b) {
double temp_a;
double temp_b;
while(!floating_point_similar(a, b, 5)) {
temp_a = a;
temp_b = b;
a = (temp_a + temp_b) / 2.0;
b = std::sqrt(temp_a * temp_b);
}
return a;
}