本文介绍了在不精确的浮点运算中,乘法总是可交换的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解 D 语言运行时中的一些代码.似乎以下两件事有单独的功能:

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.

推荐答案

我对 D 语言一无所知,但我很乐意回答你标题中的问题:

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

在不精确的浮点运算中,乘法总是可交换的吗?

直到 NaN 值的有效载荷",是的.IEEE-754 浮点乘法是可交换的(加法也是如此).如果您不知道 NaN 的有效载荷是什么,请不要担心.

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.

这篇关于在不精确的浮点运算中,乘法总是可交换的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 18:58