[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH] Libc: Erstes Stueck richtige libm
From: patrick <patrick@xxxxxxxxxxxxxxxx>
+ Libc: Erstes Stueck richtige libm
Signed-off-by: Patrick Kaufmann <patrick@xxxxxxxxxx>
---
src/modules/include/math.h | 94 ++++++++++++++++++++-----
src/modules/lib/stdlibc/math.c | 45 ------------
src/modules/lib/stdlibc/math/fabs.c | 67 +++++++++++++++++
src/modules/lib/stdlibc/math/fcos.c | 85 ++++++++++++++++++++++
src/modules/lib/stdlibc/math/fexp.c | 72 ++++++++++++++++++
src/modules/lib/stdlibc/math/fldexp.c | 58 +++++++++++++++
src/modules/lib/stdlibc/math/flog.c | 128 +++++++++++++++++++++++++++++++++
src/modules/lib/stdlibc/math/fsin.c | 83 +++++++++++++++++++++
src/modules/lib/stdlibc/math/fsqrt.c | 64 ++++++++++++++++
src/modules/lib/stdlibc/math/ftan.c | 101 ++++++++++++++++++++++++++
10 files changed, 735 insertions(+), 62 deletions(-)
delete mode 100644 src/modules/lib/stdlibc/math.c
create mode 100644 src/modules/lib/stdlibc/math/fabs.c
create mode 100644 src/modules/lib/stdlibc/math/fcos.c
create mode 100644 src/modules/lib/stdlibc/math/fexp.c
create mode 100644 src/modules/lib/stdlibc/math/fldexp.c
create mode 100644 src/modules/lib/stdlibc/math/flog.c
create mode 100644 src/modules/lib/stdlibc/math/fsin.c
create mode 100644 src/modules/lib/stdlibc/math/fsqrt.c
create mode 100644 src/modules/lib/stdlibc/math/ftan.c
diff --git a/src/modules/include/math.h b/src/modules/include/math.h
index 8be2d9c..49083ab 100644
--- a/src/modules/include/math.h
+++ b/src/modules/include/math.h
@@ -1,8 +1,8 @@
-/*
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
*
* This code is derived from software contributed to the tyndur Project
- * by Antoine Kaufmann.
+ * by Patrick Kaufmann.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -13,26 +13,86 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
+ */
#ifndef _MATH_H_
#define _MATH_H_
-#include <lost/config.h>
-// Betrag einer reelen Zahl errechen
-#ifndef CONFIG_LIBC_NO_STUBS
-double fabs(double x);
-#endif
+#define NAN (__builtin_nanf (""))
+#define INFINITY (__builtin_inff ())
+#define HUGE_VAL (__builtin_huge_val())
+#define MAXFLOAT 3.4028234663852886e+38
+
+
+#define M_E 2.71828182845904523536
+#define M_LOG2E 1.44269504088896340735
+#define M_LOG10E 0.43429448190325182765
+#define M_LN2 0.69314718055994530942
+#define M_LN10 2.30258509299404568402
+#define M_PI 3.14159265358979323846
+#define M_PI_2 1.57079632679489661923
+#define M_PI_4 0.78539816339744830962
+#define M_1_PI 0.31830988618379067154
+#define M_2_PI 0.63661977236758134308
+#define M_2_SQRTPI 1.12837916709551257390
+#define M_SQRT2 1.41421356237309504880
+#define M_SQRT1_2 0.70710678118654752440
+
+
+
+double tan(double);
+float tanf(float);
+long double tanl(long double);
+double sqrt(double);
+float sqrtf(float);
+long double sqrtl(long double);
+double sin(double);
+float sinf(float);
+long double sinl(long double);
+double log2(double);
+float log2f(float);
+long double log2l(long double);
+double log10(double);
+float log10f(float);
+long double log10l(long double);
+double log(double);
+float logf(float);
+long double logl(long double);
+double ldexp(double, int);
+float ldexpf(float, int);
+long double ldexpl(long double, int);
+double fabs(double);
+float fabsf(float);
+long double fabsl(long double);
+double exp(double);
+float expf(float);
+long double expl(long double);
+double cos(double);
+float cosf(float);
+long double cosl(long double);
+double atan(double);
+float atanf(float);
+long double atanl(long double);
+double atan2(double, double);
+float atan2f(float, float);
+long double atan2l(long double, long double);
+double asin(double);
+float asinf(float);
+long double asinl(long double);
+double acos(double);
+float acosf(float);
+long double acosl(long double);
#endif
+
diff --git a/src/modules/lib/stdlibc/math.c b/src/modules/lib/stdlibc/math.c
deleted file mode 100644
index 76d437f..0000000
--- a/src/modules/lib/stdlibc/math.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Antoine Kaufmann.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <math.h>
-#include <lost/config.h>
-
-// FIXME: Nur bis der Float-Kram vom Kernel unterstuetzt wird
-#ifndef CONFIG_LIBC_NO_STUBS
-
-/**
- * Betrag einer reellen Zahl errechnen
- */
-double fabs(double x)
-{
- return ((x < 0) ? -x : x);
-}
-
-#endif
-
diff --git a/src/modules/lib/stdlibc/math/fabs.c b/src/modules/lib/stdlibc/math/fabs.c
new file mode 100644
index 0000000..59633da
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/fabs.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Patrick Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+#include <errno.h>
+
+double fabs(double x)
+{
+ double res;
+ if (x < 0.0) {
+ res = -x;
+ }
+ else {
+ res = x;
+ }
+ return res;
+}
+
+float fabsf(float x)
+{
+ float res;
+ if (x < 0.0) {
+ res = -x;
+ }
+ else {
+ res = x;
+ }
+ return res;
+}
+
+long double fabsl(long double x)
+{
+ long double res;
+ if (x < 0.0) {
+ res = -x;
+ }
+ else {
+ res = x;
+ }
+ return res;
+}
+
diff --git a/src/modules/lib/stdlibc/math/fcos.c b/src/modules/lib/stdlibc/math/fcos.c
new file mode 100644
index 0000000..06d2d7d
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/fcos.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Patrick Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+#include <errno.h>
+
+#define pio2 1.570796326794896619
+
+double cos(double x)
+{
+ double res;
+ asm("fcos;" : "=t" (res) : "0" (x));
+ return res;
+}
+
+float cosf(float x)
+{
+ float res;
+ asm("fcos" : "=t" (res) : "0" (x));
+ return res;
+}
+
+long double cosl(long double x)
+{
+ long double res;
+ asm("fcos" : "=t" (res) : "0" (x));
+ return res;
+}
+
+double acos(double x) {
+ double res;
+ if (x <= -1 || x >= 1) {
+ errno = EDOM;
+ return NAN;
+ }
+ res = pio2 - asin(x);
+ return res;
+}
+
+float acosf(float x) {
+ float res;
+ if (x <= -1 || x >= 1) {
+ errno = EDOM;
+ return NAN;
+ }
+ res = pio2 - asin(x);
+ return res;
+}
+
+long double acosl(long double x) {
+ long double res;
+ if (x <= -1 || x >= 1) {
+ errno = EDOM;
+ return NAN;
+ }
+ res = pio2 - asin(x);
+ return res;
+}
+
+
diff --git a/src/modules/lib/stdlibc/math/fexp.c b/src/modules/lib/stdlibc/math/fexp.c
new file mode 100644
index 0000000..9d7fc3d
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/fexp.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Patrick Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+#include <errno.h>
+
+double exp(double x)
+{
+ return expl(x);
+}
+
+float expf(float x)
+{
+ return expl(x);
+}
+
+long double expl(long double x)
+{
+ long double res;
+ asm(// st0 = x
+ "fldl2e;" // Laedt log2e
+ // st0 log2(e), st1 = x
+ "fmulp;" // Multipliziert mit x
+ // st0 = x*log2(e)
+ "fld %%st(0);" //
+ // st0 = st1 = x*log2(e)
+ "frndint;"
+ // st0 = int(x*log2(e)), st1 = x*log2(e)
+ "fld1;"
+ // st0 = 1, st1 = int(x*log2(e)), st2 = x*log2(e)
+ "fscale;"
+ // st0 = 2**(int(x*log2(e))), st1 = int(x*log2(e)), st2 = x*log2(e)
+ "fxch %%st(2);"
+ // st0 = x*log2(e), st1 = int(x*log2(e)), st2 = 2**(int(x*log2(e)))
+ "fsubp %%st(1);"
+ // st0 = x*log2(e) - int(x*log2(e)), st1 = 2**(int(x*log2(e)))
+ "f2xm1;"
+ // st0 = 2**(x*log2(e) - int(x*log2(e))) - 1, st1 = 2**(int(x*log2(e)))
+ "fld1;"
+ // st0 = 1, st1 = 2**(x*log2(e) - int(x*log2(e))) - 1, st2 = 2**(int(x*log2(e)))
+ "faddp;"
+ // st0 = 2**(x*log2(e) - int(x*log2(e))), st1 = 2**(int(x*log2(e)))
+ "fmulp" : "=t" (res) : "0" (x));
+
+ return res;
+}
+
diff --git a/src/modules/lib/stdlibc/math/fldexp.c b/src/modules/lib/stdlibc/math/fldexp.c
new file mode 100644
index 0000000..eaea5cc
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/fldexp.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Patrick Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+#include <errno.h>
+
+double ldexp(double x, int exp)
+{
+ double res;
+ double e = exp;
+ asm("fscale;"
+ "fst %%st(0)" : "=t" (res) : "0" (x), "u" (e));
+ return res;
+}
+
+float ldexpf(float x, int exp)
+{
+ float res;
+ float e = exp;
+ asm("fscale;"
+ "fst %%st(0)": "=t" (res) : "0" (x), "u" (e));
+ return res;
+}
+
+long double ldexpl(long double x, int exp)
+{
+ long double res;
+ long double e = exp;
+ asm("fscale;"
+ "fst %%st(0)": "=t" (res) : "0" (x), "u" (e));
+ return res;
+}
+
diff --git a/src/modules/lib/stdlibc/math/flog.c b/src/modules/lib/stdlibc/math/flog.c
new file mode 100644
index 0000000..ffe839e
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/flog.c
@@ -0,0 +1,128 @@
+#include "math.h"
+#include <errno.h>
+
+double log2(double x) {
+ double one = 1;
+ double res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fyl2x" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+}
+
+float log2f(float x)
+{
+ float one = 1;
+ float res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fyl2x" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+}
+
+
+long double log2l(long double x)
+{
+ long double one = 1;
+ long double res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fyl2x" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+}
+
+double log(double x)
+{
+ double one = 1;
+ double res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fyl2x;"
+ "fldl2e;"
+ "fdivrp" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+}
+
+float logf(float x)
+{
+ float one = 1;
+ float res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fyl2x;"
+ "fldl2e;"
+ "fdivrp" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+}
+
+long double logl(long double x)
+{
+ long double one = 1;
+ long double res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fldl2e;"
+ "fyl2x;"
+ "fdivrp" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+
+}
+
+
+double log10(double x)
+{
+ double one = 1;
+ double res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fldl2t;"
+ "fyl2x;"
+ "fdivp" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+
+}
+
+float log10f(float x)
+{
+ float one = 1;
+ float res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fldl2t;"
+ "fyl2x;"
+ "fdivp" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+
+}
+
+long double log10l(long double x)
+{
+ long double one = 1;
+ long double res;
+ if (x <= 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fldl2t;"
+ "fyl2x;"
+ "fdivp" : "=t" (res) : "0" (x), "u" (one));
+ return res;
+
+}
+
diff --git a/src/modules/lib/stdlibc/math/fsin.c b/src/modules/lib/stdlibc/math/fsin.c
new file mode 100644
index 0000000..e274d5a
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/fsin.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Patrick Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+#include <errno.h>
+
+double sin(double x)
+{
+ double res;
+ asm("fsin" : "=t" (res) : "0" (x));
+ return res;
+}
+
+float sinf(float x)
+{
+ float res;
+ asm("fsin" : "=t" (res) : "0" (x));
+ return res;
+}
+
+long double sinl(long double x)
+{
+ long double res;
+ asm("fsin" : "=t" (res) : "0" (x));
+ return res;
+}
+
+double asin(double x) {
+ double res;
+ if (x < -1 || x > 1) {
+ errno = EDOM;
+ return NAN;
+ }
+ res = 2 * atan(x / (1 + sqrt(1 - (x * x))));
+ return res;
+}
+
+float asinf(float x) {
+ float res;
+ if (x < -1 || x > 1) {
+ errno = EDOM;
+ return NAN;
+ }
+ res = 2 * atanf(x / (1 + sqrtf(1 - (x * x))));
+ return res;
+}
+
+long double asinl(long double x) {
+ long double res;
+ if (x < -1 || x > 1) {
+ errno = EDOM;
+ return NAN;
+ }
+ res = 2 * atanl(x / (1 + sqrtl(1 - (x * x))));
+ return res;
+}
+
+
diff --git a/src/modules/lib/stdlibc/math/fsqrt.c b/src/modules/lib/stdlibc/math/fsqrt.c
new file mode 100644
index 0000000..be1b2b3
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/fsqrt.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Patrick Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+#include <errno.h>
+
+long double sqrtl(long double x)
+{
+ long double res;
+ if (x < 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fsqrt" : "=t" (res) : "0" (x));
+ return res;
+}
+
+double sqrt(double x)
+{
+ double res;
+ if (x < 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fsqrt" : "=t" (res) : "0" (x));
+ return res;
+}
+
+float sqrtf(float x)
+{
+ float res;
+ if (x < 0.0) {
+ errno = EDOM;
+ return NAN;
+ }
+ asm("fsqrt" : "=t" (res) : "0" (x));
+ return res;
+}
+
diff --git a/src/modules/lib/stdlibc/math/ftan.c b/src/modules/lib/stdlibc/math/ftan.c
new file mode 100644
index 0000000..ffb113a
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/ftan.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Patrick Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+#include <errno.h>
+
+#define pi 3.1415926535897932384
+#define pio2 1.570796326794896619
+
+
+double tan(double x)
+{
+ double res;
+ asm("fptan;"
+ "fstp %%st(0)": "=t" (res) : "0" (x));
+ return res;
+}
+
+float tanf(float x)
+{
+ float res;
+ asm("fptan;"
+ "fstp %%st(0)": "=t" (res) : "0" (x));
+ return res;
+}
+
+long double tanl(long double x)
+{
+ long double res;
+ asm("fptan;"
+ "fstp %%st(0)": "=t" (res) : "0" (x));
+ return res;
+}
+
+double atan(double x)
+{
+
+ double res;
+ asm("fld1; fpatan" : "=t" (res) : "0" (x));
+ return res;
+}
+
+float atanf(float x)
+{
+ float res;
+ asm("fld1; fpatan" : "=t" (res) : "0" (x));
+ return res;
+}
+
+
+long double atanl(long double x)
+{
+ long double res;
+ asm("fld1; fpatan" : "=t" (res) : "0" (x));
+ return res;
+}
+
+double atan2(double x, double y) {
+ double res;
+ asm("fpatan" : "=t" (res) : "0" (x), "u" (y));
+ return res;
+}
+
+
+float atan2f(float x, float y) {
+ float res;
+ asm("fpatan" : "=t" (res) : "0" (x), "u" (y));
+ return res;
+}
+
+long double atan2l(long double x, long double y) {
+ long double res;
+ asm("fpatan" : "=t" (res) : "0" (x), "u" (y));
+ return res;
+}
+
--
1.6.3.3