12-01-2022 09:33 PM
在数值输入控件中输入4.2,并通过尾数和指数控件得到尾数和指数,如下图所示。
问题是为什么在输入控件中显示的数值不等于尾数*(2^指数),前者最后两位是18,后者计算得到是16。
有没有高手帮忙解答以下,多谢!
12-02-2022 01:11 AM
Hi xiao,
@yangxiao23 wrote:
Enter 4.2 in the value input control, and get the mantissa and exponent through the mantissa and exponent control, as shown in the figure below.
The question is why the value displayed in the input control is not equal to the mantissa * (2^exponent), the last two digits of the former are 18, and the latter is calculated to be 16.
Is there any expert to help answer the following, thank you!
Oh wonders of floating point accuracy! (Read Wikipedia on floating point numbers…)
A value of 4.2 cannot be represented accurately with a DBL floating point number. And so also the mantissa shows some rounding errors!
Btw. 18 \ 4 = 4 (integer division!), so the result seems correct to me!
12-02-2022 01:20 AM
超过有效位数了
12-02-2022 03:27 AM
谢谢你的回复!
我没明白你是指哪里超过有效位宽了?我的问题是,4.2这个浮点数在计算机里实际值应该等于尾数*2^指数吧?如果是这样的话,那输入控件里显示的值为什么不等于上述算出来的值呢?输入控件里的值是怎么来的呢?
12-02-2022 03:35 AM
thank you for your reply!
i kknow it's about floating
ponit aaccuracy. i want to know which value is actual value in computer for 4.2. the value in input
control or the value equal to the mantissa * (2^exponent)?and why they are different.
12-02-2022 04:41 AM - edited 12-02-2022 04:42 AM
Hi xiao,
@yangxiao23 wrote:
i kknow it's about floating ponit aaccuracy. i want to know which value is actual value in computer for 4.2. the value in input control or the value equal to the mantissa * (2^exponent)?and why they are different.
Both are correct:
(Within floating point numerics accuracy its the very same value…)
12-02-2022 08:49 AM
I mean why 1.05000000000000004*2^2 equal to 4.20000000000000018, but not equal to 4.20000000000000016?
Thanks!