about summary refs log tree commit diff
path: root/src/math/tanhf.c
diff options
context:
space:
mode:
authornsz <nsz@port70.net>2012-03-19 23:41:19 +0100
committernsz <nsz@port70.net>2012-03-19 23:41:19 +0100
commit0cbb65479147ecdaa664e88cc2a5a925f3de502f (patch)
tree7b6dc53fcec6497d55746d3cc47f167a20b7aa57 /src/math/tanhf.c
parentb03255af77776703c8d48819e824d09f6f54ba86 (diff)
downloadmusl-0cbb65479147ecdaa664e88cc2a5a925f3de502f.tar.gz
musl-0cbb65479147ecdaa664e88cc2a5a925f3de502f.tar.xz
musl-0cbb65479147ecdaa664e88cc2a5a925f3de502f.zip
code cleanup of named constants
zero, one, two, half are replaced by const literals
The policy was to use the f suffix for float consts (1.0f),
but don't use suffix for long double consts (these consts
can be exactly represented as double).
Diffstat (limited to 'src/math/tanhf.c')
-rw-r--r--src/math/tanhf.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/math/tanhf.c b/src/math/tanhf.c
index 97d0eb53..7cb459d0 100644
--- a/src/math/tanhf.c
+++ b/src/math/tanhf.c
@@ -15,7 +15,9 @@
 
 #include "libm.h"
 
-static const float one = 1.0, two = 2.0, tiny = 1.0e-30, huge = 1.0e30;
+static const float
+tiny = 1.0e-30,
+huge = 1.0e30;
 
 float tanhf(float x)
 {
@@ -28,26 +30,26 @@ float tanhf(float x)
 	/* x is INF or NaN */
 	if(ix >= 0x7f800000) {
 		if (jx >= 0)
-			return one/x + one;  /* tanh(+-inf)=+-1 */
+			return 1.0f/x + 1.0f;  /* tanh(+-inf)=+-1 */
 		else
-			return one/x - one;  /* tanh(NaN) = NaN */
+			return 1.0f/x - 1.0f;  /* tanh(NaN) = NaN */
 	}
 
 	if (ix < 0x41100000) {  /* |x| < 9 */
 		if (ix < 0x39800000) {  /* |x| < 2**-12 */
 			/* tanh(tiny) = tiny with inexact */
-			if (huge+x > one)
+			if (huge+x > 1.0f)
 				return x;
 		}
 		if (ix >= 0x3f800000) {  /* |x|>=1  */
-			t = expm1f(two*fabsf(x));
-			z = one - two/(t+two);
+			t = expm1f(2.0f*fabsf(x));
+			z = 1.0f - 2.0f/(t+2.0f);
 		} else {
-			t = expm1f(-two*fabsf(x));
-			z = -t/(t+two);
+			t = expm1f(-2.0f*fabsf(x));
+			z = -t/(t+2.0f);
 		}
 	} else {  /* |x| >= 9, return +-1 */
-		z = one - tiny;  /* raise inexact */
+		z = 1.0f - tiny;  /* raise inexact */
 	}
 	return jx >= 0 ? z : -z;
 }