Code: Select all
inline double vox_fasttanh_ultra( const double x )
{
const double ax = fabs( x );
const double x2 = x * x;
const double z = x * ( 0.773062670268356 + ax +
( 0.757118539838817 + 0.0139332362248817 * x2 * x2 ) *
x2 * ax );
return( z / ( 0.795956503022967 + fabs( z )));
}
It seems that branching on the modern CPU is still quite expensive (as it was always the case in the past), but the math is cheap - you can add a multiplication without measurable performance loss.

