[英]Why does C or C++ “-0” not produce a floating-point −0?
我正在嘗試為浮點運算收集一些邊緣情況。 問題是,我對printf
的嘗試並沒有向我展示我想要的東西:
#include <cmath>
#include <stdio.h>
#include <complex>
int main() {
double x = -0;
auto y = sqrt(x);
printf("x %f y %f \n", x, y);
return 1;
}
根據 IEEE, squareRoot(-0)
是-0
,但這會將 x 和 y 都打印為 0。
關於如何實現我想要的任何建議? 是通過編譯器標志還是不同的東西?
0
是一個整數常量,所以-0
也是一個仍然是0
的整數。
要獲得負零,請使用浮點常量。
double x = -0.0;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.