As far as the new 39 math functions are concerned, the only difference between the C++ code and the C code is in the declaration of constants. And since in C we don't have constants, we'll have to declare the SLACK constants that are used in the code of some of the new mapper functions (Map3A, Map4A, Map5A and Map6A) as a double. So the C Grammar is slightly different from the C++ Grammar in this one aspect.
And here's the C code for all the new 39 math functions that are going to be added to the built-in math functions of GeneXproTools with this new mini-release (see how I'm generating the code automatically in the post "Function Design: Programming Languages"):
{
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)
{
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)
{
// evaluate minValue(x,y) and maxValue(x,y)
double minValue = x;
double maxValue = y;
if (minValue > y)
{
minValue = y;
maxValue = x;
}
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)
{
// evaluate minValue(a,b,c) and maxValue(a,b,c)
//
// evaluate minValue(a,b,c)
double minValue = a;
if (minValue > b)
minValue = b;
if (minValue > c)
minValue = c;
// evaluate maxValue(a,b,c)
double maxValue = a;
if (maxValue < b)
maxValue = b;
if (maxValue < c)
maxValue = 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)
{
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)
{
// evaluate minValue(x,y), maxValue(x,y) and midrange
double minValue = x;
double maxValue = y;
if (minValue > y)
{
minValue = y;
maxValue = x;
}
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)
{
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)
{
// evaluate minValue(x,y), maxValue(x,y), midpoint1, midpoint2
double minValue = x;
double maxValue = y;
if (minValue > y)
{
minValue = y;
maxValue = x;
}
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)
{
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)
{
// evaluate minValue(x,y), maxValue(x,y), midrange, midpoint1, midpoint2
double minValue = x;
double maxValue = y;
if (minValue > y)
{
minValue = y;
maxValue = x;
}
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)
{
// evaluate minValue(a,b) and maxValue(a,b)
double minValue = a;
double maxValue = b;
if (minValue > b)
{
minValue = b;
maxValue = a;
}
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;
}
Comments
There are currently no comments on this article.
Comment
your_ip_is_blacklisted_by sbl.spamhaus.org