浮点乘法是可交换的吗?
Is floating-point multiplication commutative?
由于精度有限,浮点数并不准确。我的问题是:乘法在浮点数计算机计算中是否可以交换?
例如
double a = ..;
double b = ...;
double c = a * b;
double d = b * a;
if (c == d)
cout << "Yes, great floating";
根据Wikipedia,是的,浮点乘法是可交换的。
While floating-point addition and multiplication are both commutative (a + b = b + a and a×b = b×a), they are not necessarily associative. That is, (a + b) + c is not necessarily equal to a + (b + c).
由于精度有限,浮点数并不准确。我的问题是:乘法在浮点数计算机计算中是否可以交换?
例如
double a = ..;
double b = ...;
double c = a * b;
double d = b * a;
if (c == d)
cout << "Yes, great floating";
根据Wikipedia,是的,浮点乘法是可交换的。
While floating-point addition and multiplication are both commutative (a + b = b + a and a×b = b×a), they are not necessarily associative. That is, (a + b) + c is not necessarily equal to a + (b + c).