小数在C#中的误解? [英] decimal in c# misunderstanding?

查看:179
本文介绍了小数在C#中的误解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(在试图分析如何十进制作品)及和放大器;阅读 @jonskeet文章,看到的 MSDN 和思考的最后4小时,的 我有一些问题:

此链接他们说的东西很简单:

1.5×10 ^ 2 2 显著数字

1.50×10 ^ 2 3 显著数字。

1.500×10 ^ 2 4 显著数字等...

确定...我们的想法。

从Jon的文章:

  *号尾数/ 10 ^指数
 

  

和往常一样,符号仅仅是一个单一的比特,但也有96位的   尾数和5位指数

  ^ _ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^ ___ ^^^^^

 1 _ 96 5
 

确定

所以最大的 mantiss VAL = 2 ^ 96-1 = 79228162514264337593543950335 是: 7.9228162514264 * 10 ^ 28 (根据我的iphone ... could'nt看到指数重新presentation在Windows计算)

注意:

7.9228162514264 * 10 ^ 28 14 显著数字(根据上面的示例)

现在,在指数的5位的部分是无关紧要的,因为它在分母的 - 所以我需要最小VAL是2 ^ 0

问题#1:

MSDN说: 28-29显著数字

但根据我的样本( 1.500×10 ^ 2 4 显著数字)他们的 2 显著数字 7.9 (7,9)。

如果MSDN会写:

 ±79228162514264337593543950335×10 ^ 0
 

我能明白这一点,因为所有的显著的数字是在EX pression

为什么他们写的28-29,但显示2?

问题#2:

如何将十进制重新presentation(mantiss&安培;&安培;指数)?将显示值0.5

最大分母可 2 ^ 32-1 - > 31

谢谢你们。

问题#3:

1 + 96 + 5 = 102位。

MSDN说:

  

十进制关键字表示一个128位的数据类型

  128-102 = 26
 

可以understnad从文章为什么心不是一个使用这些26位

解决方案

他们已经考虑到的范围的,只留下两个显著位,但指定了的 precision 的分别。这就是为什么的范围被列为近似的范围内。

十进制重0.5 presentation将是5尾数和1(的指数被视为在逆感觉正常,也就是说,它的有效的-1)。

(while trying to analyze how decimal works ) && after reading @jonskeet article and seeing msdn , and thinking for the last 4 hours , I have some questions :

in this link they say something very simple :

1.5 x 10^2 has 2 significant figures

1.50 x 10^2 has 3 significant figures.

1.500 x 10^2 has 4 significant figures etc...

ok...we get the idea.

from jon's article :

 sign * mantissa / 10^exponent

As usual, the sign is just a single bit, but there are 96 bits of mantissa and 5 bits of exponent

 ^ _ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^___ ^^^^^

 1 _                     96                         5

ok

so max mantiss val = 2^96-1 = 79228162514264337593543950335 which is : 7.9228162514264*10^28 (according to my iphone... could'nt see exponent representation in windows calc.)

notice :

7.9228162514264*10^28 has 14 significant figures (according to examples above)

now the part with the 5 bit in exponent is irrelevant because its in the denominator - so i need the min val which is 2^0

question #1 :

msdn say : 28-29 significant digits

but according to my sample (1.500 x 10^2 has 4 significant figures) they have 2 significant figures which is 7.9 ( 7 and 9).

if msdn would have written :

±79228162514264337593543950335 × 10^0

i would understand this , since all significant digits are in the expression.

why do they write 28-29 but display 2 ?

question #2 :

how will decimal representation ( mantiss && exponent) will be displayed for the value 0.5 ?

the max denominator can be 2^32-1 --> 31

thanks guys.

question #3 :

1+96+5 = 102 bits.

msdn says :

The decimal keyword denotes a 128-bit data type.

128-102 = 26

could understnad from article why there isnt a usage to those 26 bits

解决方案

They've given the range to just two significant digits, but specified the precision separately. That's why the range is listed as "approximate range".

The decimal representation of 0.5 would be a mantissa of 5 and an exponent of 1 (which is treated in the inverse sense to normal, i.e. it's effectively -1).

这篇关于小数在C#中的误解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆