F16Dot16.java
2.14 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
/*
* 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 class F16Dot16 {
public static final int ZERO = 0;
public static final int ONE = 65536;
public static final int ONE_HALF = 32768;
private static final DecimalFormat df = new DecimalFormat("0.###");
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 truncate(int v) {
return v & -65536;
}
public static int multiply(int v1, int v2) {
return F16Dot16.clamp((long)v1 * (long)v2 >> 16);
}
public static int square(int v) {
return F16Dot16.multiply(v, v);
}
public static int multiplyByF2Dot14(int v1, int v2) {
return F16Dot16.clamp(((long)v1 * (long)v2 >> 13) + 1 >> 1);
}
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 F16Dot16.clamp(- v);
}
return F16Dot16.clamp(v);
}
public static int divide(int v1, int v2) {
return F16Dot16.clamp(((long)v1 << 16) / (long)v2);
}
public static int round(int v) {
return F16Dot16.truncate(v + 32768);
}
public static double toDouble(int v) {
return (double)v / 65536.0;
}
public static int fromDouble(double v) {
return (int)(v * 65536.0);
}
public static int fromInt(int v) {
return v << 16;
}
public static String toString(int v) {
return df.format(F16Dot16.toDouble(v));
}
}