F2Dot14.java 1.08 KB
/*
 * 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 F2Dot14 {
    public static final int ZERO = 0;
    public static final int ONE = 16384;
    public static final int ONE_SIXTEENTH = 1024;
    private static final DecimalFormat df = new DecimalFormat("0.###");

    private static int clamp(long x) {
        if (x > 32767) {
            return 32767;
        }
        if (x < -32768) {
            return -32768;
        }
        return (int)x;
    }

    public static int multiply(int v1, int v2) {
        return F2Dot14.clamp(((long)v1 * (long)v2 >> 13) + 1 >> 1);
    }

    public static int square(int v) {
        return F2Dot14.multiply(v, v);
    }

    public static int fromDouble(double v) {
        return (int)(v * 16384.0);
    }

    public static double toDouble(int v) {
        return (double)v / 16384.0;
    }

    public static String toString(int v) {
        return df.format(F2Dot14.toDouble(v));
    }
}