gpt4 book ai didi

Exact floating point multiplication(精确的浮点乘法)

转载 作者:bug小助手 更新时间:2023-10-24 20:41:55 25 4
gpt4 key购买 nike



I want to multiply a*b using floating point numbers.

我想用浮点数乘以a*b。


What is the condition on b such that the multiplication is exact for all a? (You may assume that both a and b are not excessively small/large)

B上的条件是什么,使得乘法对所有a都是精确的?(你可以假设a和b都不是太小/太大)


For example, small powers of two work will work. What other numbers have this property?

例如,两个小幂的工作就会奏效。还有哪些数字拥有这一特性?


更多回答

Generally, multiplying by positive and negative powers of two or positive/negative zero will not produce rounding errors.

通常,乘以2的正负次方或正/负零不会产生舍入误差。

@chtz That's what I already say in the questions. I'd like to know if these are the only numbers with this property.

@chtz这就是我在问题中已经说过的。我想知道这是不是这处房产的唯一数字。

No, everything else will add at least one bit to the significant, which may or may not be exactly representable.

不,其他所有内容都将向有效位添加至少一位,这可能是也可能不是完全可表示的。

Aside from powers of two, the only other values of b that will not cause inexactness for any a are zeroes, infinities, and NaNs.

除了2的幂之外,唯一不会导致任何a不准确的b的其他值是零、无穷大和nans。

@hanno You didn't mention a context where these exact multiplications are needed. Maybe you can restrict a? In general, the product will be exact if it can be represented with at most 24 bits for IEEE-754 binary32 (single precision), at most 53 bits for IEEE-754 binary64 (double precision). There are contexts where this is exploited by guaranteeing a sufficient number of trailing zero bits in the signficands of a and b.

@Hanno你没有提到需要这些精确乘法的背景。也许你可以限制一个?存在通过保证a和b的符号数中有足够数量的尾随零比特来利用这一点的上下文。

优秀答案推荐

I want to multiply a*b using floating point numbers.

我想用浮点数乘以a*b。


For binary floating point numbers

对于二进制浮点数



What is the condition on b such that the multiplication is exact for all a?

(You may assume that both a and b are not excessively small/large)




... small powers of two work will work. What other numbers have this property?



Aside from powers of two, the only other values of b that will not cause inexactness for any a are zeroes, infinities, and NaNs.

@Eric Postpischil

除了2的幂之外,唯一不会导致任何a不准确的b的其他值是零、无穷大和nans。@Eric Postpischil


... everything else will add at least one bit to the significant, which may or may not be exactly representable.

@chtz

..。其他任何东西都将使有效位至少增加一位,这可能是也可能不是完全可表示的。@chtz


For decimal floating point numbers

对于十进制浮点数


Then it is likewise for powers of 10.

那么,10的幂也是如此。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com