






streamin in;
streamout out;
float a;
float sgn;
float res;
/ / get the sign
sgn = -1;
sgn = sgn + (in>=0) & 2;
/ / this approximates tanh in the -0.5 to 0.5 interval. We multiply by 20 to obtain
/ / a more “to the limit” values, suitable for a kind of basic “valve distrosion”
/ / substitute 20 by 2 for mathematically correct values in -1 .. 1 interval
a = 20 * in*sgn;
/ / aproximate tanh by taylor series of e^x
a=6+a*(6+a*(3+a));
res = sgn*(a-6)/(a+6);