淡泊明志 宁静致远
分类:
2006-12-06 10:08:09
【C语言库函数源代码】
【本程序在Dev C++ 4.9.9.2 下编译通过】
double my_tanh(double x)
{
double
ret,temp;
if (x >
50)
return 1;
else if (x < -50)
return -1;
else
{
ret = exp(x);
temp = 1.0 / ret;
return (
(ret - temp) / (ret + temp));
}
}//计算x的双曲正切值。
int main()
{
double a = 0.5;
printf("tanh(%f) = %f\n",a,tanh(a));
printf("my_tanh(%f) =
%f\n",a,my_tanh(a));
a = -0.5;
printf("tanh(%f) = %f\n",a,tanh(a));
printf("my_tanh(%f) =
%f\n",a,my_tanh(a));
system("pause");
return 0;
}