[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] sinh, cosh, tanh und Variationen hinzugefügt



+ sinh, cosh, tanh, sinhf, coshf, tanhf, sinhl, coshl, tanhl

Signed-off-by: Patrick Pokatilo <shyxormz@xxxxxxxxxx>
---
 src/modules/include/math.h          |   12 +++++++-
 src/modules/lib/stdlibc/math/fcos.c |   40 +++++++++++++++++++++++++++
 src/modules/lib/stdlibc/math/fsin.c |   52 +++++++++++++++++++++++++++++++++++
 src/modules/lib/stdlibc/math/ftan.c |   32 +++++++++++++++++++++
 4 files changed, 135 insertions(+), 1 deletions(-)

diff --git a/src/modules/include/math.h b/src/modules/include/math.h
index 968411b..8aa389c 100644
--- a/src/modules/include/math.h
+++ b/src/modules/include/math.h
@@ -32,6 +32,8 @@
 #define NAN         (__builtin_nanf (""))
 #define INFINITY    (__builtin_inff ())
 #define HUGE_VAL    (__builtin_huge_val())
+#define HUGE_VALF   (__builtin_huge_valf())
+#define HUGE_VALL   (__builtin_huge_vall())
 #define MAXFLOAT    3.4028234663852886e+38
 
 
@@ -96,7 +98,15 @@ long double asinl(long double);
 double      acos(double);
 float       acosf(float);
 long double acosl(long double);
-
+double      sinh(double);
+float       sinhf(float);
+long double sinhl(long double);
+double      cosh(double);
+float       coshf(float);
+long double coshl(long double);
+double      tanh(double);
+float       tanhf(float);
+long double tanhl(long double);
 
 double      floor(double x);
 float       floorf(float x);
diff --git a/src/modules/lib/stdlibc/math/fcos.c b/src/modules/lib/stdlibc/math/fcos.c
index ff69b2c..5797908 100644
--- a/src/modules/lib/stdlibc/math/fcos.c
+++ b/src/modules/lib/stdlibc/math/fcos.c
@@ -82,4 +82,44 @@ long double acosl(long double x) {
     return res;
 }
 
+double cosh(double x) {
+    if (x == NAN) {
+        return NAN;
+    }
+    double res = (exp(x) + exp(-x)) / 2.0;
+    if (((res == INFINITY) || (res == -INFINITY))
+        && (x != INFINITY) && (x != - INFINITY))
+    {
+        errno = ERANGE;
+        return HUGE_VAL;
+    }
+    return res;
+}
+
+float coshf(float x) {
+    if (x == NAN) {
+        return NAN;
+    }
+    float res = (expf(x) + expf(-x)) / 2.0f;
+    if (((res == INFINITY) || (res == -INFINITY))
+        && (x != INFINITY) && (x != - INFINITY))
+    {
+        errno = ERANGE;
+        return HUGE_VALF;
+    }
+    return res;
+}
 
+long double coshl(long double x) {
+    if (x == NAN) {
+        return NAN;
+    }
+    long double res = (expl(x) + expl(-x)) / 2.0L;
+    if (((res == INFINITY) || (res == -INFINITY))
+        && (x != INFINITY) && (x != - INFINITY))
+    {
+        errno = ERANGE;
+        return HUGE_VALL;
+    }
+    return res;
+}
diff --git a/src/modules/lib/stdlibc/math/fsin.c b/src/modules/lib/stdlibc/math/fsin.c
index e274d5a..cbb2ee8 100644
--- a/src/modules/lib/stdlibc/math/fsin.c
+++ b/src/modules/lib/stdlibc/math/fsin.c
@@ -80,4 +80,56 @@ long double asinl(long double x) {
     return res;
 }
 
+double sinh(double x) {
+    if (x == NAN) {
+        return NAN;
+    }
+    double res = (exp(x) - exp(-x)) / 2.0;
+    if (((res == INFINITY) || (res == -INFINITY))
+        && (x != INFINITY) && (x != - INFINITY))
+    {
+        errno = ERANGE;
+        if (x > 0.0) {
+            return HUGE_VAL;
+        } else {
+            return -HUGE_VAL;
+        }
+    }
+    return res;
+}
+
+float sinhf(float x) {
+    if (x == NAN) {
+        return NAN;
+    }
+    float res = (expf(x) - expf(-x)) / 2.0f;
+    if (((res == INFINITY) || (res == -INFINITY))
+        && (x != INFINITY) && (x != - INFINITY))
+    {
+        errno = ERANGE;
+        if (x > 0.0f) {
+            return HUGE_VALF;
+        } else {
+            return -HUGE_VALF;
+        }
+    }
+    return res;
+}
 
+long double sinhl(long double x) {
+    if (x == NAN) {
+        return NAN;
+    }
+    long double res = (expl(x) - expl(-x)) / 2.0L;
+    if (((res == INFINITY) || (res == -INFINITY))
+        && (x != INFINITY) && (x != - INFINITY))
+    {
+        errno = ERANGE;
+        if (x > 0.0L) {
+            return HUGE_VALL;
+        } else {
+            return -HUGE_VALL;
+        }
+    }
+    return res;
+}
diff --git a/src/modules/lib/stdlibc/math/ftan.c b/src/modules/lib/stdlibc/math/ftan.c
index 3919ee7..4990c41 100644
--- a/src/modules/lib/stdlibc/math/ftan.c
+++ b/src/modules/lib/stdlibc/math/ftan.c
@@ -98,3 +98,35 @@ long double atan2l(long double x, long double y) {
     return res;
 }
 
+double tanh(double x) {
+    if (x == NAN) {
+        return NAN;
+    } else if (x == INFINITY) {
+        return 1.0;
+    } else if (x == -INFINITY) {
+       return -1.0;
+    }
+    return sinh(x) / cosh(x);
+}
+
+float tanhf(float x) {
+    if (x == NAN) {
+        return NAN;
+    } else if (x == INFINITY) {
+        return 1.0f;
+    } else if (x == -INFINITY) {
+       return -1.0f;
+    }
+    return sinhf(x) / coshf(x);
+}
+
+long double tanhl(long double x) {
+    if (x == NAN) {
+        return NAN;
+    } else if (x == INFINITY) {
+        return 1.0L;
+    } else if (x == -INFINITY) {
+       return -1.0L;
+    }
+    return sinhl(x) / coshl(x);
+}
-- 
1.7.0.4