[英]Where to find standard C++17 cmath file?
我在哪里可以找到原始的cmath
或math.h
文件?
我需要在我的程序中使用 comp_ellint_1(double) 函数。 它在C++17
标准中的特殊函数中声明。
但是我的编译器(我试过g++/clang++
等)说这个。
我发现在标准 math.h 和cmath
所在的核心文件中,没有在cmath
声明这样的函数。 好像是99的标准...
这些函数从 7.1 版开始在 gcc 中可用,从 3.9 开始在 clang 中可用。 您要么必须升级编译器,要么使用其他一些实现(根据en.cppreference.com ,您可以使用Boost.math
这对我有用。 您需要 g++ 版本 7 或更高版本,并且必须指定C++17
或更高版本。
#include <ctgmath>
#include <iostream>
int main(int argc, char *argv[]){
double x = 0.5;
double y = std::comp_ellint_1(x);
std::cout << "x="<<x <<" -> y(x)="<<y <<std::endl;
return 0;
}
编译运行如下
$ g++ --std=c++17 test.cpp -o test
$ ./test
x=0.5 -> y(x)=1.68575
$
顺便提一下,在 Ubuntu 18.04 中,头文件位于/usr/include/c++/n/tr1/
,其中n=7,8, or 9
(支持特殊数学函数的主要 g++ 版本,截至 2019 年 12 月)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.