Is multiplication always commutative in inexact floating point arithmetic?

 ̄綄美尐妖づ 提交于 2019-12-17 20:51:15

问题


I'm trying to understand some code in the D language runtime. It seems like there are separate functions for the following two things:

array1[] += scalar * array2[];
array1[] += array2[] * scalar;

Why can't these be done with one function? I thought multiplication was commutative even in inexact floating-point arithmetic.


回答1:


I know nothing about the D language, but I'll happily answer the question in your title:

Is multiplication always commutative in inexact floating point arithmetic?

Up to the "payload" of NaN values, yes. IEEE-754 floating-point multiplication is commutative (and so is addition). If you don't know what the payload of a NaN is, don't worry about it.




回答2:


I guess the difference is just in the function prototypes - one is (double, double[]) and the other is (double[], double). But the result should be the same either way.



来源:https://stackoverflow.com/questions/5007400/is-multiplication-always-commutative-in-inexact-floating-point-arithmetic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!