我在 macOS/arm64 下移植一些复杂的东西时遇到了一些问题,最终得到了以下简单的代码来展示 macOS/x86_64 的不同行为(使用来自 conda-forge 的本机 osx/arm64 clang 版本 14.0.6,并针对 x86_64 进行交叉编译):
#include "assert.h"
#include "stdio.h"
int main()
{
double y[2] = {-0.01,0.9};
double r;
r = y[0]+0.03*y[1];
printf("r = %24.26e\n",r);
assert(r == 0.017);
}
Run Code Online (Sandbox Code Playgroud)
在arm64上的结果是
$ clang -arch arm64 test.c -o test; ./test
Assertion failed: (r == 0.017), function main, file test.c, line 9.
r = 1.69999999999999977517983751e-02
zsh: abort ./test
Run Code Online (Sandbox Code Playgroud)
而 x86_64 上的结果是
$ clang -arch x86_64 test.c -o test; ./test
r = 1.70000000000000012212453271e-02
$
Run Code Online (Sandbox Code Playgroud)
测试程序也在 x86_64 机器上编译/运行,它产生与上面相同的结果(在 …
下面的 C 程序 (dgesv_ex.c)
#include <stdlib.h>
#include <stdio.h>
/* DGESV prototype */
extern void dgesv( int* n, int* nrhs, double* a, int* lda, int* ipiv,
double* b, int* ldb, int* info );
/* Main program */
int main() {
/* Locals */
int n = 10000, info;
/* Local arrays */
/* Initialization */
double *a = malloc(n*n*sizeof(double));
double *b = malloc(n*n*sizeof(double));
int *ipiv = malloc(n*sizeof(int));
for (int i = 0; i < n*n; i++ )
{
a[i] = ((double) …Run Code Online (Sandbox Code Playgroud)