Math2.java
1.34 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.fontengine.math;
public class Math2 {
private static final int[] bits = new int[]{0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
public static double roundHalfUp(double v) {
return Math.floor(v + 0.5);
}
public static double roundHalfDown(double v) {
return Math.ceil(v - 0.5);
}
public static boolean epsilonEquals(float a, float b) {
float epsilon = 1.0E-7f;
return Math.abs(a - b) < epsilon;
}
public static boolean epsilonEquals(double a, double b) {
double epsilon = 1.0E-8;
return Math.abs(a - b) < epsilon;
}
public static int powerOf2(int v) {
if ((long)v < 0) {
v = - v;
}
if (v < 65536) {
if (v < 256) {
if (v < 16) {
return bits[v];
}
return bits[v >> 4] + 4;
}
if (v < 4096) {
return bits[v >> 8] + 8;
}
return bits[v >> 12] + 12;
}
if (v < 16777216) {
if (v < 1048576) {
return bits[v >> 16] + 16;
}
return bits[v >> 20] + 20;
}
if (v < 268435456) {
return bits[v >> 24] + 24;
}
return bits[v >> 28] + 28;
}
}