New Math Functions in Ada

Posted
Comments None

The Ada code for the 39 new math functions of GeneXproTools was created from the C++ code. And the main reason for choosing C++ as the starting point for the Ada code was the use of "return" in both programming languages.

There are, however, quite a few differences between both languages, including the word "then" after each if statement and "end if;" at the end of each if block.

The assignment sign is also different in both languages, as are the keywords "const", "double", "int" and "else if" (which in Ada translates to "constant", "long_float", "integer" and "elsif"). And there are also differences in the comment marks and logical and conditional operators.

And finally, the declaration of functions is also very different in Ada and C++, with Ada using a declarative block for the declaration of variables and constants.

Here's the Ada code for all the new 39 math functions added to the built-in math functions of GeneXproTools 5.0 with Mini-Release 1:

    function gepRamp1(x: in long_float) return long_float is
    begin
        if (x > 0.0) then
            return x;
        else
            return 0.0;
        end if;
    end gepRamp1;

    function gepRamp2(x: in long_float) return long_float is
    begin
        if (x > 0.0) then
            return 0.0;
        else
            return x;
        end if;
    end gepRamp2;

    function gepRamp3(x: in long_float) return long_float is
    begin
        if (x > 0.0) then
            return 0.0;
        else
            return -x;
        end if;
    end gepRamp3;

    function gepRamp4(x: in long_float) return long_float is
    begin
        if (x > 0.0) then
            return -x;
        else
            return 0.0;
        end if;
    end gepRamp4;

    function gepStep1(x: in long_float) return long_float is
    begin
        if (x > 0.0) then
            return 1.0;
        else
            return -1.0;
        end if;
    end gepStep1;

    function gepStep2(x: in long_float) return long_float is
    begin
        if (x > 0.0) then
            return 1.0;
        else
            return 0.0;
        end if;
    end gepStep2;

    function gepStep3(x: in long_float) return long_float is
    begin
        if (x >= 1.0) then
            return 1.0;
        elsif (x <= -1.0) then
            return -1.0;
        else
            return x;
        end if;
    end gepStep3;

    function gepStep4(x: in long_float) return long_float is
    begin
        if (x >= 1.0) then
            return 1.0;
        elsif (x <= 0.0) then
            return 0.0;
        else
            return x;
        end if;
    end gepStep4;

    function gepCL2A(x, y: in long_float) return long_float is
    begin
        if ((x > 0.0) and then (y > 0.0)) then
            return 1.0;
        else
            return -1.0;
        end if;
    end gepCL2A;

    function gepCL2B(x, y: in long_float) return long_float is
    begin
        if ((x >= 0.0) and then (y < 0.0)) then
            return -1.0;
        else
            return 1.0;
        end if;
    end gepCL2B;

    function gepCL2C(x, y: in long_float) return long_float is
    begin
        if ((x > 1.0) and then (y < -1.0)) then
            return -1.0;
        else
            return 1.0;
        end if;
    end gepCL2C;

    function gepCL2D(x, y: in long_float) return long_float is
    begin
        if ((x > 0.0) and then (y > 0.0)) then
            return 1.0;
        else
            return 0.0;
        end if;
    end gepCL2D;

    function gepCL2E(x, y: in long_float) return long_float is
    begin
        if ((x >= 0.0) and then (y <= 0.0)) then
            return 0.0;
        else
            return 1.0;
        end if;
    end gepCL2E;

    function gepCL2F(x, y: in long_float) return long_float is
    begin
        if ((x > 1.0) and then (y < -1.0)) then
            return 0.0;
        else
            return 1.0;
        end if;
    end gepCL2F;

    function gepCL3A(x, y: in long_float) return long_float is
    begin
        if ((x > 0.0) and then (y < 0.0)) then
            return 1.0;
        elsif ((x < 0.0) and then (y > 0.0)) then
            return -1.0;
        else
            return 0.0;
        end if;
    end gepCL3A;

    function gepCL3B(x, y: in long_float) return long_float is
    begin
        if ((x >= 1.0) and then (y >= 1.0)) then
            return 1.0;
        elsif ((x <= -1.0) and then (y <= -1.0)) then
            return -1.0;
        else
            return 0.0;
        end if;
    end gepCL3B;

    function gepCL3C(x, y: in long_float) return long_float is
    begin
        if ((x > 0.0) and then (y > 0.0)) then
            return 1.0;
        elsif ((x < 0.0) and then (y < 0.0)) then
            return -1.0;
        else
            return 0.0;
        end if;
    end gepCL3C;

    function gepMap3A(x, y: in long_float) return long_float is
        SLACK: constant long_float := 10.0;
        outVal: long_float := 0.0;
    begin
        if (y < (x - SLACK)) then
            outVal := -1.0;
        elsif (y > (x + SLACK)) then
            outVal := 1.0;
        end if;
        return outVal;
    end gepMap3A;

    function gepMap3B(x, y, z: in long_float) return long_float is
        minValue: long_float := x;
        maxValue: long_float := y;
        outVal: long_float := 0.0;
    begin
        if (minValue > y) then
            minValue := y;
            maxValue := x;
        end if;
        
        if (z < minValue) then
            outVal := -1.0;
        elsif (z > maxValue) then
            outVal := 1.0;
        end if;
        return outVal;
    end gepMap3B;

    function gepMap3C(a, b, c, d: in long_float) return long_float is
        minValue: long_float := a;
        maxValue: long_float := a;
        outVal: long_float := 0.0;
    begin
        -- evaluate minValue(a,b,c) and maxValue(a,b,c)
        --
        -- evaluate minValue(a,b,c)
        if (minValue > b) then
            minValue := b;
        end if;
        if (minValue > c) then
            minValue := c;
        end if;
        -- evaluate maxValue(a,b,c)
        if (maxValue < b) then
            maxValue := b;
        end if;
        if (maxValue < c) then
            maxValue := c;
        end if;

        if (d < minValue) then
            outVal := -1.0;
        elsif (d > maxValue) then
            outVal := 1.0;
        end if;
        return outVal;
    end gepMap3C;

    function gepMap4A(x, y: in long_float) return long_float is
        SLACK: constant long_float := 10.0;
        outVal: long_float := 0.0;
    begin
        if (y < (x - SLACK)) then
            outVal := 0.0;
        elsif ((y >= (x - SLACK)) and then (y < x)) then
            outVal := 1.0;
        elsif ((y >= x) and then (y < (x + SLACK))) then
            outVal := 2.0;
        elsif (y >= (x + SLACK)) then
            outVal := 3.0;
        end if;
        return outVal;
    end gepMap4A;

    function gepMap4B(x, y, z: in long_float) return long_float is
        minValue: long_float := x;
        maxValue: long_float := y;
        midrange: long_float;
        outVal: long_float := 0.0;
    begin
        -- evaluate minValue(x,y), maxValue(x,y) and midrange
        if (minValue > y) then
            minValue := y;
            maxValue := x;
        end if;
        midrange := (maxValue + minValue)/2.0;
        
        if (z < minValue) then
            outVal := 0.0;
        elsif ((z >= minValue) and then (z < midrange)) then
            outVal := 1.0;
        elsif ((z >= midrange) and then (z < maxValue)) then
            outVal := 2.0;
        elsif (z >= maxValue) then
            outVal := 3.0;
        end if;
        return outVal;
    end gepMap4B;

    function gepMap4C(a, b, c, d: in long_float) return long_float is
        minValue: long_float := a;
        maxValue: long_float := a;
        argMin: integer := 0;
        argMax: integer := 0;
        midleValue: long_float := c;
        outVal: long_float := 0.0;
    begin
        -- evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
        --
        -- evaluate minValue(a,b,c)
        if (minValue > b) then
            minValue := b;
            argMin := 1;
        end if;
        if (minValue > c) then
            minValue := c;
            argMin := 2;
        end if;
        -- evaluate maxValue(a,b,c)
        if (maxValue < b) then
            maxValue := b;
            argMax := 1;
        end if;
        if (maxValue < c) then
            maxValue := c;
            argMax := 2;
        end if;
        -- evaluate midleValue(a,b,c)
        if ((0 /= argMin) and then (0 /= argMax)) then
            midleValue := a;
        end if;
        if ((1 /= argMin) and then (1 /= argMax)) then
            midleValue := b;
        end if;

        if (d < minValue) then
            outVal := 0.0;
        elsif ((d >= minValue) and then (d < midleValue)) then
            outVal := 1.0;
        elsif ((d >= midleValue) and then (d < maxValue)) then
            outVal := 2.0;
        elsif (d >= maxValue) then
            outVal := 3.0;
        end if;
        return outVal;
    end gepMap4C;

    function gepMap5A(x, y: in long_float) return long_float is
        SLACK: constant long_float := 15.0;
        outVal: long_float := 0.0;
    begin
        if (y < (x - SLACK)) then
            outVal := 0.0;
        elsif ((y >= (x - SLACK)) and then (y < (x - SLACK/3.0))) then
            outVal := 1.0;
        elsif ((y >= (x - SLACK/3.0)) and then (y < (x + SLACK/3.0))) then
            outVal := 2.0;
        elsif ((y >= (x + SLACK/3.0)) and then (y < (x + SLACK))) then
            outVal := 3.0;
        elsif (y >= (x + SLACK)) then
            outVal := 4.0;
        end if;
        return outVal;
    end gepMap5A;

    function gepMap5B(x, y, z: in long_float) return long_float is
        minValue: long_float := x;
        maxValue: long_float := y;
        intervalLength: long_float;
        midpoint1: long_float;
        midpoint2: long_float;
        outVal: long_float := 0.0;
    begin
        -- evaluate minValue(x,y), maxValue(x,y), midpoint1, midpoint2
        if (minValue > y) then
            minValue := y;
            maxValue := x;
        end if;
        intervalLength := (maxValue - minValue)/3.0;
        midpoint1 := minValue + intervalLength;
        midpoint2 := minValue + 2.0*intervalLength;
        
        if (z < minValue) then
            outVal := 0.0;
        elsif ((z >= minValue) and then (z < midpoint1)) then
            outVal := 1.0;
        elsif ((z >= midpoint1) and then (z < midpoint2)) then
            outVal := 2.0;
        elsif ((z >= midpoint2) and then (z < maxValue)) then
            outVal := 3.0;
        elsif (z >= maxValue) then
            outVal := 4.0;
        end if;
        return outVal;
    end gepMap5B;

    function gepMap5C(a, b, c, d: in long_float) return long_float is
        minValue: long_float := a;
        maxValue: long_float := a;
        argMin: integer := 0;
        argMax: integer := 0;
        midleValue: long_float := c;
        midrange1: long_float;
        midrange2: long_float;
        outVal: long_float := 0.0;
    begin
        -- evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        --
        -- evaluate minValue(a,b,c)
        if (minValue > b) then
            minValue := b;
            argMin := 1;
        end if;
        if (minValue > c) then
            minValue := c;
            argMin := 2;
        end if;
        -- evaluate maxValue(a,b,c)
        if (maxValue < b) then
            maxValue := b;
            argMax := 1;
        end if;
        if (maxValue < c) then
            maxValue := c;
            argMax := 2;
        end if;
        -- evaluate midleValue(a,b,c)
        if ((0 /= argMin) and then (0 /= argMax)) then
            midleValue := a;
        end if;
        if ((1 /= argMin) and then (1 /= argMax)) then
            midleValue := b;
        end if;
        -- evaluate midrange1 and midrange2
        midrange1 := (minValue + midleValue)/2.0;
        midrange2 := (midleValue + maxValue)/2.0;

        if (d < minValue) then
            outVal := 0.0;
        elsif ((d >= minValue) and then (d < midrange1)) then
            outVal := 1.0;
        elsif ((d >= midrange1) and then (d < midrange2)) then
            outVal := 2.0;
        elsif ((d >= midrange2) and then (d < maxValue)) then
            outVal := 3.0;
        elsif (d >= maxValue) then
            outVal := 4.0;
        end if;
        return outVal;
    end gepMap5C;

    function gepMap6A(x, y: in long_float) return long_float is
        SLACK: constant long_float := 10.0;
        outVal: long_float := 0.0;
    begin
        if (y < (x - SLACK)) then
            outVal := 0.0;
        elsif ((y >= (x - SLACK)) and then (y < (x - SLACK/2.0))) then
            outVal := 1.0;
        elsif ((y >= (x - SLACK/2.0)) and then (y < x)) then
            outVal := 2.0;
        elsif ((y >= x) and then (y < (x + SLACK/2.0))) then
            outVal := 3.0;
        elsif ((y >= (x + SLACK/2.0)) and then (y < (x + SLACK))) then
            outVal := 4.0;
        elsif (y >= (x + SLACK)) then
            outVal := 5.0;
        end if;
        return outVal;
    end gepMap6A;

    function gepMap6B(x, y, z: in long_float) return long_float is
        minValue: long_float := x;
        maxValue: long_float := y;
        midrange: long_float;
        midpoint1: long_float;
        midpoint2: long_float;
        outVal: long_float := 0.0;
    begin
        -- evaluate minValue(x,y), maxValue(x,y), midrange, midpoint1, midpoint2
        if (minValue > y) then
            minValue := y;
            maxValue := x;
        end if;
        midrange := (minValue + maxValue)/2.0;
        midpoint1 := (minValue + midrange)/2.0;
        midpoint2 := (midrange + maxValue)/2.0;
        
        if (z < minValue) then
            outVal := 0.0;
        elsif ((z >= minValue) and then (z < midpoint1)) then
            outVal := 1.0;
        elsif ((z >= midpoint1) and then (z < midrange)) then
            outVal := 2.0;
        elsif ((z >= midrange) and then (z < midpoint2)) then
            outVal := 3.0;
        elsif ((z >= midpoint2) and then (z < maxValue)) then
            outVal := 4.0;
        elsif (z >= maxValue) then
            outVal := 5.0;
        end if;
        return outVal;
    end gepMap6B;

    function gepMap6C(a, b, c, d: in long_float) return long_float is
        minValue: long_float := a;
        maxValue: long_float := a;
        argMin: integer := 0;
        argMax: integer := 0;
        midleValue: long_float := c;
        midrange1: long_float;
        midrange2: long_float;
        outVal: long_float := 0.0;
    begin
        -- evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        --
        -- evaluate minValue(a,b,c)
        if (minValue > b) then
            minValue := b;
            argMin := 1;
        end if;
        if (minValue > c) then
            minValue := c;
            argMin := 2;
        end if;
        -- evaluate maxValue(a,b,c)
        if (maxValue < b) then
            maxValue := b;
            argMax := 1;
        end if;
        if (maxValue < c) then
            maxValue := c;
            argMax := 2;
        end if;
        -- evaluate midleValue(a,b,c)
        if ((0 /= argMin) and then (0 /= argMax)) then
            midleValue := a;
        end if;
        if ((1 /= argMin) and then (1 /= argMax)) then
            midleValue := b;
        end if;
        -- evaluate midrange1 and midrange2
        midrange1 := (minValue + midleValue)/2.0;
        midrange2 := (midleValue + maxValue)/2.0;

        if (d < minValue) then
            outVal := 0.0;
        elsif ((d >= minValue) and then (d < midrange1)) then
            outVal := 1.0;
        elsif ((d >= midrange1) and then (d < midleValue)) then
            outVal := 2.0;
        elsif ((d >= midleValue) and then (d < midrange2)) then
            outVal := 3.0;
        elsif ((d >= midrange2) and then (d < maxValue)) then
            outVal := 4.0;
        elsif (d >= maxValue) then
            outVal := 5.0;
        end if;
        return outVal;
    end gepMap6C;

    function gepECL3A(x, y, z: in long_float) return long_float is
    begin
        if ((y > x) and then (z < x)) then
            return 1.0;
        elsif ((y < x) and then (z > x)) then
            return -1.0;
        else
            return 0.0;
        end if;
    end gepECL3A;

    function gepECL3B(x, y, z: in long_float) return long_float is
    begin
        if ((y > x) and then (z > x)) then
            return 1.0;
        elsif ((y < x) and then (z < x)) then
            return -1.0;
        else
            return 0.0;
        end if;
    end gepECL3B;

    function gepECL3C(x, y, z: in long_float) return long_float is
    begin
        if ((y >= x) and then (z >= x)) then
            return 1.0;
        elsif ((y <= -x) and then (z <= -x)) then
            return -1.0;
        else
            return 0.0;
        end if;
    end gepECL3C;

    function gepECL3D(a, b, c, d: in long_float) return long_float is
        minValue: long_float := a;
        maxValue: long_float := b;
    begin
        if (minValue > b) then
            minValue := b;
            maxValue := a;
        end if;

        if ((c >= maxValue) and then (d >= maxValue)) then
            return 1.0;
        elsif ((c <= minValue) and then (d <= minValue)) then
            return -1.0;
        else
            return 0.0;
        end if;
    end gepECL3D;

    function gepAMin2(x, y: in long_float) return long_float is
    begin
        if (x < y) then
            return 0.0;
        else
            return 1.0;
        end if;
    end gepAMin2;

    function gepAMin3(x, y, z: in long_float) return long_float is
        temp: long_float := x;
        argMin: long_float := 0.0;    
    begin
        if (temp >= y) then
            temp := y;
            argMin := 1.0;
        end if;
        if (temp >= z) then
            argMin := 2.0;
        end if;
        return argMin;
    end gepAMin3;

    function gepAMin4(a, b, c, d: in long_float) return long_float is
        temp: long_float := a;
        argMin: long_float := 0.0;    
    begin
        if (temp >= b) then
            temp := b;
            argMin := 1.0;
        end if;
        if (temp >= c) then
            temp := c;
            argMin := 2.0;
        end if;
        if (temp >= d) then
            argMin := 3.0;
        end if;
        return argMin;
    end gepAMin4;

    function gepAMax2(x, y: in long_float) return long_float is
    begin
        if (x >= y) then
            return 0.0;
        else
            return 1.0;
        end if;
    end gepAMax2;

    function gepAMax3(x, y, z: in long_float) return long_float is
        temp: long_float := x;
        argMax: long_float := 0.0;    
    begin
        if (temp < y) then
            temp := y;
            argMax := 1.0;
        end if;
        if (temp < z) then
            argMax := 2.0;
        end if;
        return argMax;
    end gepAMax3;

    function gepAMax4(a, b, c, d: in long_float) return long_float is
        temp: long_float := a;
        argMax: long_float := 0.0;    
    begin
        if (temp < b) then
            temp := b;
            argMax := 1.0;
        end if;
        if (temp < c) then
            temp := c;
            argMax := 2.0;
        end if;
        if (temp < d) then
            argMax := 3.0;
        end if;
        return argMax;
    end gepAMax4;

Author

Comments

There are currently no comments on this article.

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

← Older Newer →