为什么 double、long double 或 float 之间没有区别?
例如,piin的计算C++是,
#include <iostream>
#include <quadmath.h>
#include <math.h>
int main()
{
float PI0 = acos(-1.0);
double PI1 = acos(-1.0);
long double PI2= acos(-1.0L);
__float128 x = acos(-1.0);
char buf[128];
quadmath_snprintf (buf, sizeof buf, "%*.34Qf",10, x);
std::cout << "Float=" << PI0 << std::endl;
std::cout << "Double=" << PI1 << std::endl;
std::cout << "LongDouble=" << PI2 << std::endl;
std::cout << "Float128=" << buf << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
在终端:
g++ -std=c++14 FileName.cpp -Wall -pedantic -lquadmath …Run Code Online (Sandbox Code Playgroud) 我在C++中使用多线程函数.使用n多线程,我有n随机输出.我需要计算代码中多线程输出的平均值.让我们假设n=4线程,代码是
#include <omp.h>
#include <unistd.h>
#include <stdio.h>
#include <random>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <array>
#include <eigen3/Eigen/Dense>
#define W 1.0
#define avg_disorder 10
#define numThd 4
int main()
{
#pragma omp parallel num_threads(numThd)
{
// define random numbers
std::mt19937 rng;
std::uniform_real_distribution <> dist;
std::random_device r;
std::array<int,624> seed_data;
std::generate(seed_data.begin(), seed_data.end(), std::ref(r));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
rng.seed(seq);
Eigen::Array<double, -1, 1> rp; // rp= random potential
rp = Eigen::Array<double, -1, 1>::Zero(avg_disorder, 1);
//List of 10 random …Run Code Online (Sandbox Code Playgroud)