使用 x86-64 gcc -Og -std=gnu99 -xc 编译。
在.L3 ( addl (%rdi,%rcx,4), %eax)的第二行中,为什么不直接%edx在加和时使用寄存器?
addl (%rdi,%edx,4), %eax
int sum_arr(int arr[], int nelems) {
int sum = 0;
for (int i = 0; i < nelems; i++) {
sum += arr[i];
}
return sum;
}
sum_arr:
movl $0, %edx
movl $0, %eax
jmp .L2
.L3:
movslq %edx, %rcx
addl (%rdi,%rcx,4), %eax
addl $1, %edx
.L2:
cmpl %esi, %edx
jl .L3
rep ret
Run Code Online (Sandbox Code Playgroud) 有效数字是2.
为什么输出
cout << setprecision(2) << 0.999 << endl;`
Run Code Online (Sandbox Code Playgroud)
是1不是1.0?