caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 1 | |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame^] | 2 | #if 0 |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 3 | // 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 | |
| 31 | if (mantissa == 0) |
| 32 | { |
| 33 | return "0"; |
| 34 | } |
| 35 | |
| 36 | /* Normalize */ |
| 37 | while((mantissa & 1) == 0) |
| 38 | { /* i.e., Mantissa is even */ |
| 39 | mantissa >>= 1; |
| 40 | exponent++; |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame^] | 41 | } |
| 42 | #endif |