erf(x)和math.h [英] erf(x) and math.h

查看:236
本文介绍了erf(x)和math.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此网站,错误函数erf(x)出现了来自math.h.但是实际上是在math.h中查找的,它不存在,而gcc不能编译以下测试程序,而g ++可以:

According to this site the error function erf(x) comes from math.h. But actually looking in math.h, it isn't there, and gcc cannot compile the following test program while g++ can:

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

int main(int argc, char* argv[]) {
  double x;
  double erfX;
  x = 1.0;
  erfX = erf(x);

  printf("erf(%f) = %f", x, erfX);
}

$ gcc mathHTest.c
/tmp/ccWfNox5.o: In function `main':
mathHTest.c:(.text+0x28): undefined reference to `erf'
collect2: ld returned 1 exit status
$ g++ mathHTest.c

g ++不能提供gcc的功能是什么?在/usr/include中查找,我唯一能找到erf(x)的地方是tgmath.h,我没有包含.因此,g ++必须使用与gcc不同的标头,但是哪个标头呢?

What does g++ pull in that gcc doesn't? Looking in /usr/include, the only place I could find erf(x) was in tgmath.h, which I don't include. So g++ must be grabbing different headers than gcc, but which ones?

我没有在libm中用gcc链接,因此链接错误.但是,我仍然不明白为什么erf()不在math.h中.它来自哪里?

I wasn't linking in libm with gcc, hence the link error. However, I still don't understand why erf() is not in math.h. Where is it coming from?

推荐答案

'erf'实际上是在bits/mathcalls.h中声明的,该元素已由math.h包含.实际的声明在很大程度上被宏魔术所掩盖,以使其对C和C ++都适用.

'erf' is actually declared in bits/mathcalls.h, which is #included by math.h. The actual declaration is heavily obscured by macro magic to make it do the right thing for both C and C++

这篇关于erf(x)和math.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆