Mercurial > projects > dwt2
comparison base/src/java/math/BigDecimal.d @ 98:48d4ee626868
rm databinding.observable seems to be duplicate, databinding.beans now building
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 22 Apr 2009 07:30:21 +0200 |
parents | b2d6122fa189 |
children | 9f4c18c268b2 |
comparison
equal
deleted
inserted
replaced
97:c86eb8b3098e | 98:48d4ee626868 |
---|---|
11 static int ROUND_HALF_EVEN; | 11 static int ROUND_HALF_EVEN; |
12 static int ROUND_HALF_UP; | 12 static int ROUND_HALF_UP; |
13 static int ROUND_UNNECESSARY; | 13 static int ROUND_UNNECESSARY; |
14 static int ROUND_UP; | 14 static int ROUND_UP; |
15 | 15 |
16 private BigInteger intVal; | |
17 private int scale_; | |
18 private int intCompact; | |
19 private int precision; | |
20 private static const MAX_BIGINT_BITS = 62; | |
21 | |
16 this(BigInteger val){ | 22 this(BigInteger val){ |
17 implMissing(__FILE__, __LINE__); | 23 implMissing(__FILE__, __LINE__); |
18 } | 24 } |
19 this(BigInteger unscaledVal, int scale){ | 25 this(BigInteger unscaledVal, int scale_){ |
20 implMissing(__FILE__, __LINE__); | 26 this.intVal = unscaledVal; |
27 this.scale_ = scale_; | |
21 } | 28 } |
22 this(double val){ | 29 this(double val){ |
23 implMissing(__FILE__, __LINE__); | 30 if (double.nan is val || double.infinity is val ) |
31 throw new NumberFormatException("Infinite or NaN"); | |
32 | |
33 // Translate the double into sign, exponent and significand, according | |
34 // to the formulae in JLS, Section 20.10.22. | |
35 long valBits = *cast(long*) & val; | |
36 int sign = ((valBits >> 63)==0 ? 1 : -1); | |
37 int exponent = cast(int) ((valBits >> 52) & 0x7ffL); | |
38 long significand = (exponent==0 ? (valBits & ((1L<<52) - 1)) << 1 | |
39 : (valBits & ((1L<<52) - 1)) | (1L<<52)); | |
40 exponent -= 1075; | |
41 // At this point, val == sign * significand * 2**exponent. | |
42 | |
43 /* | |
44 * Special case zero to supress nonterminating normalization | |
45 * and bogus scale calculation. | |
46 */ | |
47 if (significand == 0) { | |
48 intVal = BigInteger.ZERO; | |
49 intCompact = 0; | |
50 precision = 1; | |
51 return; | |
52 } | |
53 | |
54 // Normalize | |
55 while((significand & 1) == 0) { // i.e., significand is even | |
56 significand >>= 1; | |
57 exponent++; | |
58 } | |
59 | |
60 // Calculate intVal and scale | |
61 intVal = BigInteger.valueOf(sign*significand); | |
62 if (exponent < 0) { | |
63 intVal = intVal.multiply(BigInteger.valueOf(5).pow(-exponent)); | |
64 scale_ = -exponent; | |
65 } else if (exponent > 0) { | |
66 intVal = intVal.multiply(BigInteger.valueOf(2).pow(exponent)); | |
67 } | |
68 if (intVal.bitLength() <= MAX_BIGINT_BITS) { | |
69 intCompact = intVal.longValue(); | |
70 } | |
24 } | 71 } |
25 this(String val){ | 72 this(String val){ |
26 implMissing(__FILE__, __LINE__); | 73 implMissing(__FILE__, __LINE__); |
27 } | 74 } |
28 BigDecimal abs(){ | 75 BigDecimal abs(){ |
43 } | 90 } |
44 BigDecimal divide(BigDecimal val, int roundingMode){ | 91 BigDecimal divide(BigDecimal val, int roundingMode){ |
45 implMissing(__FILE__, __LINE__); | 92 implMissing(__FILE__, __LINE__); |
46 return null; | 93 return null; |
47 } | 94 } |
48 BigDecimal divide(BigDecimal val, int scale, int roundingMode){ | 95 BigDecimal divide(BigDecimal val, int scale_, int roundingMode){ |
49 implMissing(__FILE__, __LINE__); | 96 implMissing(__FILE__, __LINE__); |
50 return null; | 97 return null; |
51 } | 98 } |
52 double doubleValue(){ | 99 double doubleValue(){ |
53 implMissing(__FILE__, __LINE__); | 100 implMissing(__FILE__, __LINE__); |
97 implMissing(__FILE__, __LINE__); | 144 implMissing(__FILE__, __LINE__); |
98 return null; | 145 return null; |
99 } | 146 } |
100 int scale(){ | 147 int scale(){ |
101 implMissing(__FILE__, __LINE__); | 148 implMissing(__FILE__, __LINE__); |
102 return 0; | 149 return this.scale_; |
103 } | 150 } |
104 BigDecimal setScale(int scale){ | 151 BigDecimal setScale(int scale_){ |
105 implMissing(__FILE__, __LINE__); | 152 implMissing(__FILE__, __LINE__); |
106 return null; | 153 return null; |
107 } | 154 } |
108 BigDecimal setScale(int scale, int roundingMode){ | 155 BigDecimal setScale(int scale_, int roundingMode){ |
109 implMissing(__FILE__, __LINE__); | 156 implMissing(__FILE__, __LINE__); |
110 return null; | 157 return null; |
111 } | 158 } |
112 int signum(){ | 159 int signum(){ |
113 implMissing(__FILE__, __LINE__); | 160 implMissing(__FILE__, __LINE__); |
131 } | 178 } |
132 static BigDecimal valueOf(long val){ | 179 static BigDecimal valueOf(long val){ |
133 implMissing(__FILE__, __LINE__); | 180 implMissing(__FILE__, __LINE__); |
134 return null; | 181 return null; |
135 } | 182 } |
136 static BigDecimal valueOf(long unscaledVal, int scale){ | 183 static BigDecimal valueOf(long unscaledVal, int scale_){ |
137 implMissing(__FILE__, __LINE__); | 184 implMissing(__FILE__, __LINE__); |
138 return null; | 185 return null; |
139 } | 186 } |
140 } | 187 } |
141 | 188 |