blob: 7321fef49b53e5297bbfb93834fbb9d9575853f4 [file] [log] [blame]
caryclark@google.com639df892012-01-10 21:46:10 +00001
caryclark@google.comd88e0892012-03-27 13:23:51 +00002#if 0
caryclark@google.com639df892012-01-10 21:46:10 +00003// snippets that one day may be useful, unused for now...
4
5// get sign, exponent, mantissa from double
6// Translate the double into sign, exponent and mantissa.
7 long bits = BitConverter.DoubleToInt64Bits(d);
8 // Note that the shift is sign-extended, hence the test against -1 not 1
9 bool negative = (bits < 0);
10 int exponent = (int) ((bits >> 52) & 0x7ffL);
11 long mantissa = bits & 0xfffffffffffffL;
12
13 // Subnormal numbers; exponent is effectively one higher,
14 // but there's no extra normalisation bit in the mantissa
15 if (exponent==0)
16 {
17 exponent++;
18 }
19 // Normal numbers; leave exponent as it is but add extra
20 // bit to the front of the mantissa
21 else
22 {
23 mantissa = mantissa | (1L<<52);
24 }
25
26 // Bias the exponent. It's actually biased by 1023, but we're
27 // treating the mantissa as m.0 rather than 0.m, so we need
28 // to subtract another 52 from it.
29 exponent -= 1075;
30
rmistry@google.comd6176b02012-08-23 18:14:13 +000031 if (mantissa == 0)
caryclark@google.com639df892012-01-10 21:46:10 +000032 {
33 return "0";
34 }
35
36 /* Normalize */
rmistry@google.comd6176b02012-08-23 18:14:13 +000037 while((mantissa & 1) == 0)
caryclark@google.com639df892012-01-10 21:46:10 +000038 { /* i.e., Mantissa is even */
39 mantissa >>= 1;
40 exponent++;
caryclark@google.comd88e0892012-03-27 13:23:51 +000041 }
caryclark@google.coma3f05fa2012-06-01 17:44:28 +000042#endif