在哪里可以找到标准的 C++17 cmath 文件?
Where to find standard C++17 cmath file?
在哪里可以找到原始 cmath
或 math.h
文件?
我需要在程序中使用 comp_ellint_1(double) 函数。它在特殊功能的 C++17
标准中声明。
但是我的编译器(我试过 g++/clang++
等等)say this.
我发现在标准 math.h 和 cmath
所在的核心文件中,cmath
中没有声明此类函数。貌似是99标准...
从 7.1 版开始的 gcc 和从 3.9 版开始的 clang 中都可以使用这些函数。您要么必须升级编译器,要么使用其他实现(根据 en.cppreference.com, you can use 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 中,headers 在 /usr/include/c++/n/tr1/
中,其中 n=7,8, or 9
(支持特殊数学函数的 g++ 主要版本,截至 2019 年 12 月)
在哪里可以找到原始 cmath
或 math.h
文件?
我需要在程序中使用 comp_ellint_1(double) 函数。它在特殊功能的 C++17
标准中声明。
但是我的编译器(我试过 g++/clang++
等等)say this.
我发现在标准 math.h 和 cmath
所在的核心文件中,cmath
中没有声明此类函数。貌似是99标准...
从 7.1 版开始的 gcc 和从 3.9 版开始的 clang 中都可以使用这些函数。您要么必须升级编译器,要么使用其他实现(根据 en.cppreference.com, you can use 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 中,headers 在 /usr/include/c++/n/tr1/
中,其中 n=7,8, or 9
(支持特殊数学函数的 g++ 主要版本,截至 2019 年 12 月)