LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview中双精度浮点数为什么不等于通过指数和尾数计算得到的数值?

在数值输入控件中输入4.2,并通过尾数和指数控件得到尾数和指数,如下图所示。

问题是为什么在输入控件中显示的数值不等于尾数*(2^指数),前者最后两位是18,后者计算得到是16。

有没有高手帮忙解答以下,多谢!

屏幕截图 2022-12-02 112852.png

 

屏幕截图 2022-12-02 112354.png

 

0 Kudos
Message 1 of 7
(801 Views)

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(757 Views)

超过有效位数了

0 Kudos
Message 3 of 7
(756 Views)

谢谢你的回复!

我没明白你是指哪里超过有效位宽了?我的问题是,4.2这个浮点数在计算机里实际值应该等于尾数*2^指数吧?如果是这样的话,那输入控件里显示的值为什么不等于上述算出来的值呢?输入控件里的值是怎么来的呢?

 

0 Kudos
Message 4 of 7
(727 Views)

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.

0 Kudos
Message 5 of 7
(725 Views)

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…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(703 Views)

I mean why 1.05000000000000004*2^2 equal to 4.20000000000000018, but not equal to 4.20000000000000016?

Thanks!

0 Kudos
Message 7 of 7
(679 Views)