Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is multiplication always commutative in inexact floating point arithmetic?

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.

like image 322
dsimcha Avatar asked Jan 21 '23 11:01

dsimcha


1 Answers

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.

like image 154
Stephen Canon Avatar answered Jan 31 '23 06:01

Stephen Canon