DoubleMath.java
9.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package com.google.common.math;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Booleans;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Iterator;
import rg;
import rh;
@GwtCompatible(emulated=true)
public final class DoubleMath
{
@VisibleForTesting
static final double[] a = { 1.0D, 2.0922789888E13D, 2.631308369336935E35D, 1.2413915592536073E61D, 1.2688693218588417E89D, 7.156945704626381E118D, 9.916779348709496E149D, 1.974506857221074E182D, 3.856204823625804E215D, 5.5502938327393044E249D, 4.7147236359920616E284D };
private static final double b = Math.log(2.0D);
@GwtIncompatible("#isMathematicalInteger, com.google.common.math.DoubleUtils")
private static double a(double paramDouble, RoundingMode paramRoundingMode)
{
if (!rg.b(paramDouble)) {
throw new ArithmeticException("input is infinite or NaN");
}
switch (1.a[paramRoundingMode.ordinal()])
{
default:
throw new AssertionError();
case 1:
rh.a(isMathematicalInteger(paramDouble));
}
double d;
do
{
do
{
do
{
do
{
return paramDouble;
} while ((paramDouble >= 0.0D) || (isMathematicalInteger(paramDouble)));
return paramDouble - 1.0D;
} while ((paramDouble <= 0.0D) || (isMathematicalInteger(paramDouble)));
return paramDouble + 1.0D;
} while (isMathematicalInteger(paramDouble));
return paramDouble + Math.copySign(1.0D, paramDouble);
return Math.rint(paramDouble);
d = Math.rint(paramDouble);
if (Math.abs(paramDouble - d) == 0.5D) {
return paramDouble + Math.copySign(0.5D, paramDouble);
}
return d;
d = Math.rint(paramDouble);
} while (Math.abs(paramDouble - d) == 0.5D);
return d;
}
public static double factorial(int paramInt)
{
rh.b("n", paramInt);
if (paramInt > 170) {
return Double.POSITIVE_INFINITY;
}
double d = 1.0D;
int i = (paramInt & 0xFFFFFFF0) + 1;
while (i <= paramInt)
{
d *= i;
i += 1;
}
return a[(paramInt >> 4)] * d;
}
public static int fuzzyCompare(double paramDouble1, double paramDouble2, double paramDouble3)
{
if (fuzzyEquals(paramDouble1, paramDouble2, paramDouble3)) {
return 0;
}
if (paramDouble1 < paramDouble2) {
return -1;
}
if (paramDouble1 > paramDouble2) {
return 1;
}
return Booleans.compare(Double.isNaN(paramDouble1), Double.isNaN(paramDouble2));
}
public static boolean fuzzyEquals(double paramDouble1, double paramDouble2, double paramDouble3)
{
if (paramDouble3 < 0.0D)
{
String str = String.valueOf(String.valueOf("tolerance"));
throw new IllegalArgumentException(str.length() + 40 + str + " (" + paramDouble3 + ") must be >= 0");
}
return (Math.copySign(paramDouble1 - paramDouble2, 1.0D) <= paramDouble3) || (paramDouble1 == paramDouble2) || ((Double.isNaN(paramDouble1)) && (Double.isNaN(paramDouble2)));
}
@GwtIncompatible("java.lang.Math.getExponent, com.google.common.math.DoubleUtils")
public static boolean isMathematicalInteger(double paramDouble)
{
return (rg.b(paramDouble)) && ((paramDouble == 0.0D) || (52 - Long.numberOfTrailingZeros(rg.a(paramDouble)) <= Math.getExponent(paramDouble)));
}
@GwtIncompatible("com.google.common.math.DoubleUtils")
public static boolean isPowerOfTwo(double paramDouble)
{
return (paramDouble > 0.0D) && (rg.b(paramDouble)) && (LongMath.isPowerOfTwo(rg.a(paramDouble)));
}
public static double log2(double paramDouble)
{
return Math.log(paramDouble) / b;
}
@GwtIncompatible("java.lang.Math.getExponent, com.google.common.math.DoubleUtils")
public static int log2(double paramDouble, RoundingMode paramRoundingMode)
{
int j = 1;
int k = 1;
int i = 1;
if ((paramDouble > 0.0D) && (rg.b(paramDouble))) {}
int m;
for (boolean bool = true;; bool = false)
{
Preconditions.checkArgument(bool, "x must be positive and finite");
m = Math.getExponent(paramDouble);
if (rg.c(paramDouble)) {
break;
}
return log2(4.503599627370496E15D * paramDouble, paramRoundingMode) - 52;
}
switch (1.a[paramRoundingMode.ordinal()])
{
default:
throw new AssertionError();
case 1:
rh.a(isPowerOfTwo(paramDouble));
case 2:
i = 0;
}
while (i != 0)
{
return m + 1;
if (isPowerOfTwo(paramDouble))
{
i = 0;
continue;
if (m < 0)
{
i = 1;
label161:
if (isPowerOfTwo(paramDouble)) {
break label181;
}
}
for (;;)
{
i = j & i;
break;
i = 0;
break label161;
label181:
j = 0;
}
if (m >= 0)
{
i = 1;
label194:
if (isPowerOfTwo(paramDouble)) {
break label218;
}
}
label218:
for (j = k;; j = 0)
{
i = j & i;
break;
i = 0;
break label194;
}
paramDouble = rg.d(paramDouble);
if (paramDouble * paramDouble <= 2.0D) {
i = 0;
}
}
}
return m;
}
@GwtIncompatible("MeanAccumulator")
public static double mean(Iterable<? extends Number> paramIterable)
{
a locala = new a((byte)0);
paramIterable = paramIterable.iterator();
while (paramIterable.hasNext()) {
locala.a(((Number)paramIterable.next()).doubleValue());
}
return locala.a();
}
@GwtIncompatible("MeanAccumulator")
public static double mean(Iterator<? extends Number> paramIterator)
{
a locala = new a((byte)0);
while (paramIterator.hasNext()) {
locala.a(((Number)paramIterator.next()).doubleValue());
}
return locala.a();
}
@GwtIncompatible("MeanAccumulator")
public static double mean(double... paramVarArgs)
{
int i = 0;
a locala = new a((byte)0);
int j = paramVarArgs.length;
while (i < j)
{
locala.a(paramVarArgs[i]);
i += 1;
}
return locala.a();
}
@GwtIncompatible("MeanAccumulator")
public static double mean(int... paramVarArgs)
{
int i = 0;
a locala = new a((byte)0);
int j = paramVarArgs.length;
while (i < j)
{
locala.a(paramVarArgs[i]);
i += 1;
}
return locala.a();
}
@GwtIncompatible("MeanAccumulator")
public static double mean(long... paramVarArgs)
{
int i = 0;
a locala = new a((byte)0);
int j = paramVarArgs.length;
while (i < j)
{
locala.a(paramVarArgs[i]);
i += 1;
}
return locala.a();
}
@GwtIncompatible("#roundIntermediate, java.lang.Math.getExponent, com.google.common.math.DoubleUtils")
public static BigInteger roundToBigInteger(double paramDouble, RoundingMode paramRoundingMode)
{
int j = 1;
paramDouble = a(paramDouble, paramRoundingMode);
int i;
if (-9.223372036854776E18D - paramDouble < 1.0D)
{
i = 1;
if (paramDouble >= 9.223372036854776E18D) {
break label49;
}
label29:
if ((j & i) == 0) {
break label55;
}
paramRoundingMode = BigInteger.valueOf(paramDouble);
}
label49:
label55:
BigInteger localBigInteger;
do
{
return paramRoundingMode;
i = 0;
break;
j = 0;
break label29;
i = Math.getExponent(paramDouble);
localBigInteger = BigInteger.valueOf(rg.a(paramDouble)).shiftLeft(i - 52);
paramRoundingMode = localBigInteger;
} while (paramDouble >= 0.0D);
return localBigInteger.negate();
}
@GwtIncompatible("#roundIntermediate")
public static int roundToInt(double paramDouble, RoundingMode paramRoundingMode)
{
int j = 1;
paramDouble = a(paramDouble, paramRoundingMode);
int i;
if (paramDouble > -2.147483649E9D)
{
i = 1;
if (paramDouble >= 2.147483648E9D) {
break label42;
}
}
for (;;)
{
rh.b(j & i);
return (int)paramDouble;
i = 0;
break;
label42:
j = 0;
}
}
@GwtIncompatible("#roundIntermediate")
public static long roundToLong(double paramDouble, RoundingMode paramRoundingMode)
{
int j = 1;
paramDouble = a(paramDouble, paramRoundingMode);
int i;
if (-9.223372036854776E18D - paramDouble < 1.0D)
{
i = 1;
if (paramDouble >= 9.223372036854776E18D) {
break label44;
}
}
for (;;)
{
rh.b(j & i);
return paramDouble;
i = 0;
break;
label44:
j = 0;
}
}
@GwtIncompatible("com.google.common.math.DoubleUtils")
static final class a
{
private long a = 0L;
private double b = 0.0D;
final double a()
{
if (this.a > 0L) {}
for (boolean bool = true;; bool = false)
{
Preconditions.checkArgument(bool, "Cannot take mean of 0 values");
return this.b;
}
}
final void a(double paramDouble)
{
Preconditions.checkArgument(rg.b(paramDouble));
this.a += 1L;
this.b += (paramDouble - this.b) / this.a;
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/math/DoubleMath.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/