C++:实现 ln(a) 的数值近似

C++: Implementing a numeric approximation for ln(a)

我要实现公式:

#include <iostream>
#include <cmath>
#include <limits>

using namespace std;

int main(){
    double a, eps = numeric_limits<double>::epsilon();
    cout << "a=";
    cin >> a;
    double w = sqrt(a), prod = 1 + w;
    int n = 1;
    do {
        w = sqrt(w);
        prod *= 1 + w;
        cout << "ln(" << a << ")=" << ldexp(a-1, n)/prod << endl;
        n++;
    } while(abs(w - 1) > eps);

    return 0;
}

但是例如ln(2.78787)=0.512639 这不可能是真的。哪里错了?

循环的初始条件不成立。从

开始
double w = a, prod = 1;

程序会生成 expected results