我在文件aR中写了一个Rjob,它调用文件bR中写入的函数和一个snw文件c.snw.我通过"R CMD c.snw"调用c.snw.
我正在寻找一个可能只通过\ SweaveInput {aR}将aR包含到c.snw中,但是从aR调用的函数的代码也应该写在tex文件中.这意味着Sweave跟踪包含的主R文件(此处为aR)中的所有source()命令.
任何人都可以建议如何做到这一点?
我正在尝试使用 std::from_chars 将字符串转换为双精度,但是当涉及指数数字时,我无法与 strtod 对齐。再现者:
#include <string>
#include <iostream>
#include <charconv>
void xxx(std::string const A){
double x;
std::from_chars(&A[0],&A.back(),x,std::chars_format::scientific);
printf("%s,%.17g\n",A.c_str(),x);
}
void yyy(std::string const A){
printf("%s,%.17g\n",A.c_str(),strtod(&A[0],NULL));
}
int main(){
xxx(std::string("0.9226e-01"));
yyy(std::string("0.9226e-01"));
xxx(std::string("0.9226e-10"));
yyy(std::string("0.9226e-10"));
}
Run Code Online (Sandbox Code Playgroud)
产生输出
0.9226e-01,0.92259999999999998
0.9226e-01,0.092259999999999995
0.9226e-10,0.092259999999999995
0.9226e-10,9.226e-11
Run Code Online (Sandbox Code Playgroud)
我想说 strtod 会产生正确的结果。
很高兴得知我弄错了。
平台:linux g++版本:12.2
谢谢,圣诞快乐