New Math Functions in Java

Posted
Comments None

As far as the 39 new math functions added to the built-in math functions of GeneXproTools, the Java code is almost an exact clone of the C# code, except that the word "const" was replaced by "final" and "Min" and "Max" were replaced by "min" and "max" and implemented the Java way as these functions can take two or more arguments in Java.

Again, as for all programming languages with native min and max functions (thus far, only C# and VB.Net), we are leaving the chunks of code for evaluating min and max values in the places where argmin and argmax values are calculated, as this simplifies testing and debugging.

And here's the Java code for all the 39 new math functions added to the Java Grammar of GeneXproTools with v5.0 MR1:

    double gepRamp1(double x)
    {
        if (x > 0.0)
            return x;
        else
            return 0.0;
    }

    double gepRamp2(double x)
    {
        if (x > 0.0)
            return 0.0;
        else
            return x;
    }

    double gepRamp3(double x)
    {
        if (x > 0.0)
            return 0.0;
        else
            return -x;
    }

    double gepRamp4(double x)
    {
        if (x > 0.0)
            return -x;
        else
            return 0.0;
    }

    double gepStep1(double x)
    {
        if (x > 0.0)
            return 1.0;
        else
            return -1.0;
    }

    double gepStep2(double x)
    {
        if (x > 0.0)
            return 1.0;
        else
            return 0.0;
    }

    double gepStep3(double x)
    {
        if (x >= 1.0)
            return 1.0;
        else
            if (x <= -1.0)
                return -1.0;
            else
                return x;
    }

    double gepStep4(double x)
    {
        if (x >= 1.0)
            return 1.0;
        else
            if (x <= 0.0)
                return 0.0;
            else
                return x;
    }

    double gepCL2A(double x, double y)
    {
        if (x > 0.0 && y > 0.0)
            return 1.0;
        else
            return -1.0;
    }

    double gepCL2B(double x, double y)
    {
        if (x >= 0.0 && y < 0.0)
            return -1.0;
        else
            return 1.0;
    }

    double gepCL2C(double x, double y)
    {
        if (x > 1.0 && y < -1.0)
            return -1.0;
        else
            return 1.0;
    }

    double gepCL2D(double x, double y)
    {
        if (x > 0.0 && y > 0.0)
            return 1.0;
        else
            return 0.0;
    }

    double gepCL2E(double x, double y)
    {
        if (x >= 0.0 && y <= 0.0)
            return 0.0;
        else
            return 1.0;
    }

    double gepCL2F(double x, double y)
    {
        if (x > 1.0 && y < -1.0)
            return 0.0;
        else
            return 1.0;
    }

    double gepCL3A(double x, double y)
    {
        if (x > 0.0 && y < 0.0)
            return 1.0;
        else
            if (x < 0.0 && y > 0.0)
                return -1.0;
            else
                return 0.0;
    }

    double gepCL3B(double x, double y)
    {
        if (x >= 1.0 && y >= 1.0)
            return 1.0;
        else
            if (x <= -1.0 && y <= -1.0)
                return -1.0;
            else
                return 0.0;
    }

    double gepCL3C(double x, double y)
    {
        if (x > 0.0 && y > 0.0)
            return 1.0;
        else
            if (x < 0.0 && y < 0.0)
                return -1.0;
            else
                return 0.0;
    }

    double gepMap3A(double x, double y)
    {
        final double SLACK = 10.0;
        double outVal = 0.0;
        if (y < (x - SLACK))
            outVal = -1.0;
        else if (y > (x + SLACK))
            outVal = 1.0;
        return outVal;
    }

    double gepMap3B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double outVal = 0.0;
        if (z < minValue)
            outVal = -1.0;
        else if (z > maxValue)
            outVal = 1.0;
        return outVal;
    }

    double gepMap3C(double a, double b, double c, double d)
    {
        double minValue = Math.min(a,b,c);
        double maxValue = Math.max(a,b,c);
        double outVal = 0.0;
        if (d < minValue)
            outVal = -1.0;
        else if (d > maxValue)
            outVal = 1.0;
        return outVal;
    }

    double gepMap4A(double x, double y)
    {
        final double SLACK = 10.0;
        double outVal = 0.0;
        if (y < (x - SLACK))
            outVal = 0.0;
        else if (y >= (x - SLACK) && y < x)
            outVal = 1.0;
        else if (y >= x && y < (x + SLACK))
            outVal = 2.0;
        else if (y >= (x + SLACK))
            outVal = 3.0;
        return outVal;
    }

    double gepMap4B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double midrange = (maxValue + minValue)/2.0;
        
        double outVal = 0.0;
        if (z < minValue)
            outVal = 0.0;
        else if (z >= minValue && z < midrange)
            outVal = 1.0;
        else if (z >= midrange && z < maxValue)
            outVal = 2.0;
        else if (z >= maxValue)
            outVal = 3.0;
        return outVal;
    }

    double gepMap4C(double a, double b, double c, double d)
    {
        // evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
        //
        // evaluate minValue(a,b,c)
        double minValue = a;
        int argMin = 0;
        if (minValue > b)
        {
            minValue = b;
            argMin = 1;
        }
        if (minValue > c)
        {
            minValue = c;
            argMin = 2;
        }
        // evaluate maxValue(a,b,c)
        double maxValue = a;
        int argMax = 0;
        if (maxValue < b)
        {
            maxValue = b;
            argMax = 1;
        }
        if (maxValue < c)
        {
            maxValue = c;
            argMax = 2;
        }
        // evaluate midleValue(a,b,c)
        double midleValue = c;
        if (0 != argMin && 0 != argMax)
            midleValue = a;
        if (1 != argMin && 1 != argMax)
            midleValue = b;

        double outVal = 0.0;
        if (d < minValue)
            outVal = 0.0;
        else if (d >= minValue && d < midleValue)
            outVal = 1.0;
        else if (d >= midleValue && d < maxValue)
            outVal = 2.0;
        else if (d >= maxValue)
            outVal = 3.0;
        return outVal;
    }

    double gepMap5A(double x, double y)
    {
        final double SLACK = 15.0;
        double outVal = 0.0;
        if (y < (x - SLACK))
            outVal = 0.0;
        else if (y >= (x - SLACK) && y < (x - SLACK/3.0))
            outVal = 1.0;
        else if (y >= (x - SLACK/3.0) && y < (x + SLACK/3.0))
            outVal = 2.0;
        else if (y >= (x + SLACK/3.0) && y < (x + SLACK))
            outVal = 3.0;
        else if (y >= (x + SLACK))
            outVal = 4.0;
        return outVal;
    }

    double gepMap5B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double intervalLength = (maxValue - minValue)/3.0;
        double midpoint1 = minValue + intervalLength;
        double midpoint2 = minValue + 2.0*intervalLength;
        
        double outVal = 0.0;
        if (z < minValue)
            outVal = 0.0;
        else if (z >= minValue && z < midpoint1)
            outVal = 1.0;
        else if (z >= midpoint1 && z < midpoint2)
            outVal = 2.0;
        else if (z >= midpoint2 && z < maxValue)
            outVal = 3.0;
        else if (z >= maxValue)
            outVal = 4.0;
        return outVal;
    }

    double gepMap5C(double a, double b, double c, double d)
    {
        // evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        //
        // evaluate minValue(a,b,c)
        double minValue = a;
        int argMin = 0;
        if (minValue > b)
        {
            minValue = b;
            argMin = 1;
        }
        if (minValue > c)
        {
            minValue = c;
            argMin = 2;
        }
        // evaluate maxValue(a,b,c)
        double maxValue = a;
        int argMax = 0;
        if (maxValue < b)
        {
            maxValue = b;
            argMax = 1;
        }
        if (maxValue < c)
        {
            maxValue = c;
            argMax = 2;
        }
        // evaluate midleValue(a,b,c)
        double midleValue = c;
        if (0 != argMin && 0 != argMax)
            midleValue = a;
        if (1 != argMin && 1 != argMax)
            midleValue = b;
        // evaluate midrange1 and midrange2
        double midrange1 = (minValue + midleValue)/2.0;
        double midrange2 = (midleValue + maxValue)/2.0;

        double outVal = 0.0;
        if (d < minValue)
            outVal = 0.0;
        else if (d >= minValue && d < midrange1)
            outVal = 1.0;
        else if (d >= midrange1 && d < midrange2)
            outVal = 2.0;
        else if (d >= midrange2 && d < maxValue)
            outVal = 3.0;
        else if (d >= maxValue)
            outVal = 4.0;
        return outVal;
    }

    double gepMap6A(double x, double y)
    {
        final double SLACK = 10.0;
        double outVal = 0.0;
        if (y < (x - SLACK))
            outVal = 0.0;
        else if (y >= (x - SLACK) && y < (x - SLACK/2.0))
            outVal = 1.0;
        else if (y >= (x - SLACK/2.0) && y < x)
            outVal = 2.0;
        else if (y >= x && y < (x + SLACK/2.0))
            outVal = 3.0;
        else if (y >= (x + SLACK/2.0) && y < (x + SLACK))
            outVal = 4.0;
        else if (y >= (x + SLACK))
            outVal = 5.0;
        return outVal;
    }

    double gepMap6B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double midrange = (minValue + maxValue)/2.0;
        double midpoint1 = (minValue + midrange)/2.0;
        double midpoint2 = (midrange + maxValue)/2.0;
        
        double outVal = 0.0;
        if (z < minValue)
            outVal = 0.0;
        else if (z >= minValue && z < midpoint1)
            outVal = 1.0;
        else if (z >= midpoint1 && z < midrange)
            outVal = 2.0;
        else if (z >= midrange && z < midpoint2)
            outVal = 3.0;
        else if (z >= midpoint2 && z < maxValue)
            outVal = 4.0;
        else if (z >= maxValue)
            outVal = 5.0;
        return outVal;
    }

    double gepMap6C(double a, double b, double c, double d)
    {
        // evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        //
        // evaluate minValue(a,b,c)
        double minValue = a;
        int argMin = 0;
        if (minValue > b)
        {
            minValue = b;
            argMin = 1;
        }
        if (minValue > c)
        {
            minValue = c;
            argMin = 2;
        }
        // evaluate maxValue(a,b,c)
        double maxValue = a;
        int argMax = 0;
        if (maxValue < b)
        {
            maxValue = b;
            argMax = 1;
        }
        if (maxValue < c)
        {
            maxValue = c;
            argMax = 2;
        }
        // evaluate midleValue(a,b,c)
        double midleValue = c;
        if (0 != argMin && 0 != argMax)
            midleValue = a;
        if (1 != argMin && 1 != argMax)
            midleValue = b;
        // evaluate midrange1 and midrange2
        double midrange1 = (minValue + midleValue)/2.0;
        double midrange2 = (midleValue + maxValue)/2.0;

        double outVal = 0.0;
        if (d < minValue)
            outVal = 0.0;
        else if (d >= minValue && d < midrange1)
            outVal = 1.0;
        else if (d >= midrange1 && d < midleValue)
            outVal = 2.0;
        else if (d >= midleValue && d < midrange2)
            outVal = 3.0;
        else if (d >= midrange2 && d < maxValue)
            outVal = 4.0;
        else if (d >= maxValue)
            outVal = 5.0;
        return outVal;
    }

    double gepECL3A(double x, double y, double z)
    {
        if (y > x && z < x)
            return 1.0;
        else
            if (y < x && z > x)
                return -1.0;
            else return 0.0;
    }

    double gepECL3B(double x, double y, double z)
    {
        if (y > x && z > x)
            return 1.0;
        else
            if (y < x && z < x)
                return -1.0;
            else return 0.0;
    }

    double gepECL3C(double x, double y, double z)
    {
        if (y >= x && z >= x)
            return 1.0;
        else
            if (y <= -x && z <= -x)
                return -1.0;
            else return 0.0;
    }

    double gepECL3D(double a, double b, double c, double d)
    {
        double minValue = Math.min(a,b);
        double maxValue = Math.max(a,b);
        if (c >= maxValue && d >= maxValue)
            return 1.0;
        else
            if (c <= minValue && d <= minValue)
                return -1.0;
            else return 0.0;
    }

    double gepAMin2(double x, double y)
    {
        if (x < y)
            return 0.0;
        else
            return 1.0;
    }

    double gepAMin3(double x, double y, double z)
    {
        double temp = x;
        double argMin = 0.0;    
        if (temp >= y)
        {
            temp = y;
            argMin = 1.0;
        }
        if (temp >= z)
        {
            argMin = 2.0;
        }
        return argMin;
    }

    double gepAMin4(double a, double b, double c, double d)
    {
        double temp = a;
        double argMin = 0.0;    
        if (temp >= b)
        {
            temp = b;
            argMin = 1.0;
        }
        if (temp >= c)
        {
            temp = c;
            argMin = 2.0;
        }
        if (temp >= d)
        {
            argMin = 3.0;
        }
        return argMin;
    }

    double gepAMax2(double x, double y)
    {
        if (x >= y)
            return 0.0;
        else
            return 1.0;
    }

    double gepAMax3(double x, double y, double z)
    {
        double temp = x;
        double argMax = 0.0;    
        if (temp < y)
        {
            temp = y;
            argMax = 1.0;
        }
        if (temp < z)
        {
            argMax = 2.0;
        }
        return argMax;
    }

    double gepAMax4(double a, double b, double c, double d)
    {
        double temp = a;
        double argMax = 0.0;    
        if (temp < b)
        {
            temp = b;
            argMax = 1.0;
        }
        if (temp < c)
        {
            temp = c;
            argMax = 2.0;
        }
        if (temp < d)
        {
            argMax = 3.0;
        }
        return argMax;
    }

Author

Comments

There are currently no comments on this article.

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

← Older Newer →