Is multiplication always commutative in inaccurate floating point arithmetic?

I am trying to understand some code in the D-language runtime. It seems that there are separate functions for the following two things:

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

Why is this impossible to do with a single function? I thought that multiplication is commutative even in inaccurate exact floating point arithmetic.

+3
source share
2 answers

I don't know anything about the D language, but I will gladly answer the question in your title:

Is multiplication always commutative in inaccurate floating point arithmetic?

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

+3

, - - (double, double[]), - (double[], double). .

+5

Source: https://habr.com/ru/post/1792293/


All Articles