为什么 atan 没有产生正确的结果?

Why is atan not producing the correct result?

我有以下小程序在我的大项目中重现触发错误:

#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

#define R2D(trig_fn, val) trig_fn (val * (180.0 / M_PI))

int main()
{
    printf("%f\n", R2D(atan, 2.5));
    return 0;
}

atan(2.5) 从弧度转换为度数的预期结果是 68.1985...,但此程序输出的结果是 1.563815,与正确答案相去甚远。

我将其预处理到一个文件中;问题不在宏中,这也是我的第一个猜测;宏正确扩展 (atan (2.5 * (180.0 / 3.14159265358979323846))).

double atan(double x);

Returns the principal value of the arc tangent of x, expressed in radians.

输出以弧度为单位,而不是度数。您需要将函数的结果转换为度数。输入仍然是一个简单的无单位数字。

#define R2D(trig_fn, val) (trig_fn(val) * (180.0 / M_PI))