在幕后,做什么用十进制值类型发生在C#/。NET? [英] Behind the scenes, what's happening with decimal value type in C#/.NET?

查看:126
本文介绍了在幕后,做什么用十进制值类型发生在C#/。NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在小数类型实现?

更新


  • 这是一个128位的值类型(16字节)

  • 1符号位
  • $ b $对于设置为指数
  • 其余位(其中23!)b
  • 96位(12字节)的尾数

  • 8位0

  • It's a 128-bit value type (16 bytes)
  • 1 sign bit
  • 96 bits (12 bytes) for the mantissa
  • 8 bits for the exponent
  • remaining bits (23 of them!) set to 0

谢谢! 。我会坚持使用一个64位长的与我自己的隐含规模

Thanks! I'm gonna stick with using a 64-bit long with my own implied scale.

推荐答案

Decimal浮点在维基百科上的文章与特定的链接,这篇文章的 System.Decimal

Decimal Floating Point article on Wikipedia with specific link to this article about System.Decimal.

一个小数存储在128位,即使只有102是绝对必要的。这是方便考虑代表尾数小数点为3个32位整数,然后代表符号和指数有一个整数。最后整数的最高位是符号位(以正常的方式,与该位被设置为(1)为负数)和位16-23(高16位字的低位)包含指数。其他位都必须清除(0)。这种表示是decimal.GetBits(十进制)给出的返回的4个整数的数组。

A decimal is stored in 128 bits, even though only 102 are strictly necessary. It is convenient to consider the decimal as three 32-bit integers representing the mantissa, and then one integer representing the sign and exponent. The top bit of the last integer is the sign bit (in the normal way, with the bit being set (1) for negative numbers) and bits 16-23 (the low bits of the high 16-bit word) contain the exponent. The other bits must all be clear (0). This representation is the one given by decimal.GetBits(decimal) which returns an array of 4 ints.

这篇关于在幕后,做什么用十进制值类型发生在C#/。NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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