F26Dot6.java
3.7 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.agl.text.DecimalFormat
*/
package com.adobe.fontengine.math;
import com.adobe.agl.text.DecimalFormat;
public final class F26Dot6 {
public static final int ZERO = 0;
public static final int ONE = 64;
public static final int ONE_HALF = 32;
public static final int MAX_VALUE = Integer.MAX_VALUE;
public static final int MIN_VALUE = Integer.MIN_VALUE;
private static final DecimalFormat df = new DecimalFormat("0.##");
public static int truncate(int v) {
return v & -64;
}
public static int ceiling(int v) {
return F26Dot6.truncate(v + 64 - 1);
}
public static int floor(int v) {
return F26Dot6.truncate(v);
}
public static int round(int v) {
return F26Dot6.truncate(v + 32);
}
public static int roundHalfUp(int v) {
return F26Dot6.truncate(v + 32);
}
public static int roundHalfDown(int v) {
return F26Dot6.truncate(v + 32 - 1);
}
public static int negate(int v) {
return - v;
}
public static int abs(int v) {
return v < 0 ? - v : v;
}
public static int add(int v1, int v2) {
return v1 + v2;
}
public static int subtract(int v1, int v2) {
return v1 - v2;
}
private static int clamp(long x) {
if (x > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
if (x < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return (int)x;
}
public static int multiply(int v1, int v2) {
return F26Dot6.clamp((long)v1 * (long)v2 >> 6);
}
public static int divide(int v1, int v2) {
return (int)((long)v1 << 6) / v2;
}
public static int multiplyByF2Dot14(int v1, int v2) {
return F26Dot6.clamp(((long)v1 * (long)((short)v2) >> 13) + 1 >> 1);
}
public static int divideByF2Dot14(int v1, int v2) {
return (int)((long)v1 << 14) / v2;
}
public static int multiplyByF16Dot16(int v1, int v2) {
return F26Dot6.clamp(((long)v1 * (long)v2 >> 15) + 1 >> 1);
}
public static int divideByF16Dot16(int v1, int v2) {
return (int)(((long)v1 << 16) / (long)v2);
}
public static int multiplyDivide(int v1, int v2, int v3) {
long numerator = (long)v1 * (long)v2;
long denominator = v3;
boolean negate = false;
if (numerator < 0) {
numerator = - numerator;
boolean bl = negate = !negate;
}
if (denominator < 0) {
denominator = - denominator;
negate = !negate;
}
long v = (numerator + denominator / 2) / denominator;
if (negate) {
return F26Dot6.clamp(- v);
}
return F26Dot6.clamp(v);
}
public static int multiplyByF2Dot14DivideByF2Dot14(int v1, int v2, int v3) {
return F26Dot6.multiplyDivide(v1, v2, v3);
}
public static boolean isEven(int v1) {
return (v1 & 64) == 0;
}
public static boolean sameSign(int v1, int v2) {
return (v1 & Integer.MIN_VALUE) == (v2 & Integer.MIN_VALUE);
}
public static int min(int v1, int v2) {
return Math.min(v1, v2);
}
public static int max(int v1, int v2) {
return Math.max(v1, v2);
}
public static double toDouble(int v) {
return (double)v / 64.0;
}
public static int fromDouble(double v) {
return (int)Math.round(v * 64.0);
}
public static int toInt(int v) {
return v >> 6;
}
public static int fromInt(int v) {
return v << 6;
}
public static String toString(int v) {
return df.format(F26Dot6.toDouble(v));
}
}