### Thread: Help Needed:How to Implement tanh in C?

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2017
Posts
17
Rep Power
0

#### Help Needed:How to Implement tanh in C?

I am implementing LDPC decoder with the use of belief propagation in log domain in C language, and Hardware platform is Vivado HLS.But in Vivado HLS,
tanh function wont be supported. What would be alternate solution to tanh function, or any C Program source code to solve, via Taylor series expansion, tanh function.

for(j=0;j<ROWS_P;j++)
{
if(j!=i && h[j][0]==h[i][0])
{
temp=temp * tanhf (LLR[j]/2); // TANH function
}
Please tell me how should i calculate that tanh calculation.I am stuck with this tanh calculation, Please anyone help me
2. What accuracy do you need? You could interpolate from a look up table, you could work with Taylor series adding from smallest term to largest, restricting the domain to non-negative values of the argument noting that
tanh(-x) == -tanh(x)
I've had success with cubic splines and you can test on another computer system for the spacing of the knots to get desired accuracy.
The first 21 Bernoulli numbers are
1
-1/2
1/6
0
-1/30
0
1/42
0
-1/30
0
5/66
0
-691/2730
0
7/6
0
-3617/510
0
43867/798
0
-174611/330

which might give you desired accuracy for power series.
3. What accuracy do you need? You could interpolate from a look up table, you could work with Taylor series adding from smallest term to largest, restricting the domain to non-negative values of the argument noting that
tanh(-x) == -tanh(x)
I've had success with cubic splines and you can test on another computer system for the spacing of the knots to get desired accuracy.
The first 21 Bernoulli numbers are
1
-1/2
1/6
0
-1/30
0
1/42
0
-1/30
0
5/66
0
-691/2730
0
7/6
0
-3617/510
0
43867/798
0
-174611/330

which might give you desired accuracy for power series.

Equation 52 (or thereabout) of Maclaurin Series -- from Wolfram MathWorld