Wednesday, May 26, 2010

C# Decimal type dissected

I was going through C# 4 Essentials. The Decimal type description is sufficient and it is cool to imagine it as +/- N * 10k. But I was not satisfied. The above statement and below url have put me much at ease. Must have been a difficult decision to keep a 128 bit location and leave bits blank after using 102 bits:
http://www.yoda.arachsys.com/csharp/decimal.html

Remember machines are binary and 128 is the closest upper 2^x (for a whole number x) above 102.

Update: Even more amazing explanation:
http://gregs-blog.com/2007/12/10/dot-net-decimal-type-vs-float-type/
If you are even more interested in the mathematics (non .net specific) check out the below (it will help you understand greg's post as well):
http://sandbox.mc.edu/~bennet/cs110/flt/dtof.html
Note: there is something to be found in each of these absent in the rest


Enjoy!

No comments:

Post a Comment