blob: e6c4abc59039550dea231d0ecb278010faadd2db [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
caryclark@google.com639df892012-01-10 21:46:10 +00007
caryclark@google.comd88e0892012-03-27 13:23:51 +00008#if 0
caryclark@google.com639df892012-01-10 21:46:10 +00009// snippets that one day may be useful, unused for now...
10
11// get sign, exponent, mantissa from double
12// Translate the double into sign, exponent and mantissa.
13 long bits = BitConverter.DoubleToInt64Bits(d);
14 // Note that the shift is sign-extended, hence the test against -1 not 1
15 bool negative = (bits < 0);
16 int exponent = (int) ((bits >> 52) & 0x7ffL);
17 long mantissa = bits & 0xfffffffffffffL;
18
19 // Subnormal numbers; exponent is effectively one higher,
20 // but there's no extra normalisation bit in the mantissa
21 if (exponent==0)
22 {
23 exponent++;
24 }
25 // Normal numbers; leave exponent as it is but add extra
26 // bit to the front of the mantissa
27 else
28 {
29 mantissa = mantissa | (1L<<52);
30 }
31
32 // Bias the exponent. It's actually biased by 1023, but we're
33 // treating the mantissa as m.0 rather than 0.m, so we need
34 // to subtract another 52 from it.
35 exponent -= 1075;
36
rmistry@google.comd6176b02012-08-23 18:14:13 +000037 if (mantissa == 0)
caryclark@google.com639df892012-01-10 21:46:10 +000038 {
39 return "0";
40 }
41
42 /* Normalize */
rmistry@google.comd6176b02012-08-23 18:14:13 +000043 while((mantissa & 1) == 0)
caryclark@google.com639df892012-01-10 21:46:10 +000044 { /* i.e., Mantissa is even */
45 mantissa >>= 1;
46 exponent++;
caryclark@google.comd88e0892012-03-27 13:23:51 +000047 }
caryclark@google.coma3f05fa2012-06-01 17:44:28 +000048#endif