public float[] calculate(float[] x) {

        int k = functions.length;

        if (k == 1 && bounds.length == 0) {
            if (domain[0] <= x[0] && x[0] <= domain[1]) {
                return encode(x, functions[0], 0);
            }
        }

        // Find where x finds into the following range:
        // Domain0 < Bounds0 < Bounds1 < ... < Boundsk-2 < Domain1
        // where k = functions length.  The found bound is the equivalent function
        // to use to encode the x value.
        for (int b = 0; b < bounds.length; b++) {
            // first sub domain
            if (b == 0) {
                // check if domain0 <= x < bounds0, return function if true
                if (domain[0] <= x[0] && x[0] < bounds[b]) {
                    return encode(x, functions[b], b);
                }
            }
            // last sub domain
            if (b == k - 2) {
                // check if bounds k-2 <= x <= domain 0, return function if true
                if (bounds[b] <= x[0] && x[0] <= domain[1]) {
                    return encode(x, functions[k - 1], k - 1);
                }
            }
            // bounds <= x < bounds b + 1, return function if true
            if (bounds[b] <= x[0] && x[0] < bounds[b + 1]) {
                return encode(x, functions[b], b);
            }
        }

        return null;
    }