I don’t know why, but I did. I guess I was just curious. I looked at the C# standard, ECMA 334 (now an ISO standard).

A few seconds in I notice the following:

Section 11.1.6 describes the set of values in the `double`

type:

“The finite set of non-zero values of the form s × m × 2^{e}, where s is 1 or −1, and for double, 0 < m < 2^{53} and −1075 ≤ e ≤ 970.”

It also says that `double`

is represented using the 64-bit double precision IEC 60559. Now of course I can’t actually get a copy of that standard, but it’s well known that the exponent for double precision is 11-bits wide with a bias of 1023. That means that the smallest (positive) normalised number is 2^{-1022}; the smallest denormal is 2^{-52} times that value: 2^{-1074}. Still, the C# boys nearly got it right. They’re off-by-one on the top end too, the largest finite double is (2^{53}-1) × 2^{971}.

Like a boy with a new toy (I discovered Python’s struct module a few days ago), I can check the math with Python:

>>> struct.unpack(‘d’, struct.pack(‘Q’, 1))[0]

4.9406564584124654e-324

>>> 2**-1074

4.9406564584124654e-324

Further on in the same section the standard says: “The double type can represent values ranging from approximately 5.0 × 10^{−324} to 1.7 × 10^{308} with a precision of 15–16 digits.” At least they get the range right in decimal. I still find this slightly misleading because down in the denormal range you don’t get 15-16 digits of precision (consider, 3e-324 == 7e-324). It would be more accurate to say “The double type can represent values ranging from approximately 5.0 × 10^{−324} to 1.7 × 10^{308}, with a precision of 15–16 digits when the magnituitude is greater than approximately 2.2 × 10^{-308}.”

These are tedious details; some might think them a little bit dull, but they’re details that a standard should get right. After all, if the guy writing the standard isn’t going to get them right, who is? Your vendor? (mwahaha) It’s sloppy and makes me wonder what else might they have got wrong. Am I encouraged to continue reading? No.

Sorry, wrong category because wordpress thinks C, C++, and C# are all the same. Meh.

### Like this:

Like Loading...

*Related*

This entry was posted on 2007-07-03 at 08:51:35 and is filed under c++, programming, rant.

2007-07-03 at 14:53:50

From what you say, 0.0 is not a member of the double type.

2007-07-03 at 14:56:36

Oh, and I think we have a paper copy of the IEEE float standard somewhere in the office.

2007-07-03 at 15:19:11

I trimmed too harshly. The section first goes to mention the zeroes, the infinities, and the NaNs, then goes on to discuss the finite non-zero values.

2007-07-03 at 17:15:59

“4th edition”. *snigger*