本帖最后由 solly 于 2022-5-27 08:39 编辑
Reverse to source:
[C] 纯文本查看 复制代码 #include <iostream>
#include <math.h>
double calc(double p1, double p2);
char wrong[] = "you are wrong!\n";
char right[] = "you are right!\n";
int main(int argc, char** argv) {
char * msg;
double p1 = 0;//3.0;
double p2 = 1;//7.0;
double ret1 = calc(p1, p2); /// 0018FF10 1.966366887301097
printf("ret1 = %18.16f\n", ret1);
double v0 = 0;
long long v1 = 0;
double v2 = ret1 / 100000000.0; /// 0018FF08 1.966366887301097e-08
do {
double v3 = exp((double)v1 * v2); /// 1,
double v4 = sqrt(v3 * v3 + 1); /// 1.4142135623731
v1 ++;
v0 += v4 * v2; /// v4 * v2 = 2.78086272062258e-008
} while (v1 <= 100000000);
////// v0 = 0018FF20 6.541963349981230
printf("v0 = %18.16f\n", v0);
v1 = 0;
double v8;
double v5 = exp(ret1); //// 0018FF18 7.144671879977526
double v6 = ret1 - p1;
double v7 = v5 - p2;
v2 = sqrt(v6 * v6 + v7 * v7); /// 0018FF08 1.043708467209044
printf("v2 = %18.16f\n", v2);
double v1_0 = v0;
double v1_1 = v2;
if((fpclassify(v1_0) == FP_NORMAL) && (fpclassify(v1_1) == FP_NORMAL) || (fpclassify(v0) == FP_ZERO) || (fpclassify(v2) == FP_ZERO)){
msg = wrong;
double v8 = v5 - p2;
double v9 = ret1 - p1;
int v10 = (int)((sqrt(v8 * v8 + v9 * v9) + 0.0000005) * 1000000.0); //// 0x000FECFC, 1043708
double v12 = (double)((float)v10 / 1000000.0);
printf("v12 = %18.16f\n", v12);
int v11 = (int)((v0 + 0.0000005) * 1000000.0); /// 0x0063D28B, 6541963
double v13 = (double)((float)v11 / 1000000.0);
printf("v13 = %18.16f\n", v13);
if(v12 == v13) {
msg = right;
}
} else {
msg = wrong;
}
printf(msg);
//system("pause");
return 0;
}
double calc(double p1, double p2) {
double v1 = 0;
double v1_prev = 0;
do {
v1_prev = v1; // 0, -2.25
double v2 = exp(v1); // 1, 0.105399224561864
double v3 = exp(v1 + v1); // 1, 0.0111089965382423
v1 -= ((p2 - v2) * v2 - v1 + p1) / ((v2 * p2) - (v3 + v3) - 1.0); /// -2.25, 18.7633383227283
} while (fabs(v1 - v1_prev) >= 0.00001);
return v1; /// 1.9663668873011
}
|