• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
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   */
7  
8  #if 0
9  // 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  
37      if (mantissa == 0)
38      {
39          return "0";
40      }
41  
42      /* Normalize */
43      while((mantissa & 1) == 0)
44      {    /*  i.e., Mantissa is even */
45          mantissa >>= 1;
46          exponent++;
47      }
48  #endif
49