summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/FP_FAST_FMA.c12
-rw-r--r--src/math/FP_FAST_FMAF.c12
-rw-r--r--src/math/FP_FAST_FMAL.c12
-rw-r--r--src/math/FP_ILOGB0.c7
-rw-r--r--src/math/FP_ILOGBNAN.c7
-rw-r--r--src/math/FP_INFINITE.c7
-rw-r--r--src/math/FP_NAN.c7
-rw-r--r--src/math/FP_NORMAL.c7
-rw-r--r--src/math/FP_SUBNORMAL.c7
-rw-r--r--src/math/FP_ZERO.c7
-rw-r--r--src/math/HUGE_VAL.c13
-rw-r--r--src/math/HUGE_VALF.c7
-rw-r--r--src/math/HUGE_VALL.c7
-rw-r--r--src/math/INFINITY.c7
-rw-r--r--src/math/MATH_ERREXCEPT.c7
-rw-r--r--src/math/MATH_ERRNO.c7
-rw-r--r--src/math/NAN.c7
-rw-r--r--src/math/acos.c35
-rw-r--r--src/math/acosh.c13
-rw-r--r--src/math/asin.c35
-rw-r--r--src/math/asinh.c13
-rw-r--r--src/math/atan.c48
-rw-r--r--src/math/atan2.c41
-rw-r--r--src/math/atanh.c13
-rw-r--r--src/math/cbrt.c13
-rw-r--r--src/math/ceil.c30
-rw-r--r--src/math/copysign.c13
-rw-r--r--src/math/cos.c51
-rw-r--r--src/math/cosh.c29
-rw-r--r--src/math/double_t.c16
-rw-r--r--src/math/erf.c13
-rw-r--r--src/math/erfc.c13
-rw-r--r--src/math/exp.c44
-rw-r--r--src/math/exp2.c13
-rw-r--r--src/math/expm1.c13
-rw-r--r--src/math/fabs.c29
-rw-r--r--src/math/fdim.c13
-rw-r--r--src/math/float_t.c16
-rw-r--r--src/math/floor.c30
-rw-r--r--src/math/fma.c13
-rw-r--r--src/math/fmax.c13
-rw-r--r--src/math/fmin.c13
-rw-r--r--src/math/fmod.c35
-rw-r--r--src/math/fpclassify.c12
-rw-r--r--src/math/frexp.c39
-rw-r--r--src/math/hypot.c13
-rw-r--r--src/math/ilogb.c13
-rw-r--r--src/math/isfinite.c12
-rw-r--r--src/math/isgreater.c7
-rw-r--r--src/math/isgreaterequal.c7
-rw-r--r--src/math/isinf.c12
-rw-r--r--src/math/isless.c7
-rw-r--r--src/math/islessequal.c7
-rw-r--r--src/math/islessgreater.c7
-rw-r--r--src/math/isnan.c12
-rw-r--r--src/math/isnormal.c12
-rw-r--r--src/math/isunordered.c7
-rw-r--r--src/math/ldexp.c30
-rw-r--r--src/math/lgamma.c13
-rw-r--r--src/math/llrint.c13
-rw-r--r--src/math/llround.c13
-rw-r--r--src/math/log.c34
-rw-r--r--src/math/log10.c34
-rw-r--r--src/math/log1p.c13
-rw-r--r--src/math/log2.c13
-rw-r--r--src/math/logb.c13
-rw-r--r--src/math/lrint.c13
-rw-r--r--src/math/lround.c13
-rw-r--r--src/math/math_errhandling.c7
-rw-r--r--src/math/modf.c33
-rw-r--r--src/math/nan.c13
-rw-r--r--src/math/nearbyint.c13
-rw-r--r--src/math/nextafter.c13
-rw-r--r--src/math/nexttoward.c13
-rw-r--r--src/math/pow.c39
-rw-r--r--src/math/remquo.c13
-rw-r--r--src/math/rint.c13
-rw-r--r--src/math/round.c13
-rw-r--r--src/math/scalbln.c23
-rw-r--r--src/math/scalbn.c13
-rw-r--r--src/math/signbit.c12
-rw-r--r--src/math/sin.c51
-rw-r--r--src/math/sinh.c29
-rw-r--r--src/math/sqrt.c34
-rw-r--r--src/math/tan.c29
-rw-r--r--src/math/tanh.c29
-rw-r--r--src/math/tgamma.c13
-rw-r--r--src/math/trunc.c13
88 files changed, 1533 insertions, 0 deletions
diff --git a/src/math/FP_FAST_FMA.c b/src/math/FP_FAST_FMA.c
new file mode 100644
index 00000000..868c9455
--- /dev/null
+++ b/src/math/FP_FAST_FMA.c
@@ -0,0 +1,12 @@
+#include <math.h>
+
+#if 0 /* if fma is generally as fast or faster than multiply and add */
+#define FP_FAST_FMA
+#else
+#undef FP_FAST_FMA
+#endif
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_FAST_FMAF.c b/src/math/FP_FAST_FMAF.c
new file mode 100644
index 00000000..7b7b88a4
--- /dev/null
+++ b/src/math/FP_FAST_FMAF.c
@@ -0,0 +1,12 @@
+#include <math.h>
+
+#if 0 /* if fmaf is generally as fast or faster than multiply and add */
+#define FP_FAST_FMAF
+#else
+#undef FP_FAST_FMAF
+#endif
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_FAST_FMAL.c b/src/math/FP_FAST_FMAL.c
new file mode 100644
index 00000000..1437ad56
--- /dev/null
+++ b/src/math/FP_FAST_FMAL.c
@@ -0,0 +1,12 @@
+#include <math.h>
+
+#if 0 /* if fmal is generally as fast or faster than multiply and add */
+#define FP_FAST_FMAL
+#else
+#undef FP_FAST_FMAL
+#endif
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_ILOGB0.c b/src/math/FP_ILOGB0.c
new file mode 100644
index 00000000..1c3f0e28
--- /dev/null
+++ b/src/math/FP_ILOGB0.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define FP_ILOGB0 INT_MIN
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_ILOGBNAN.c b/src/math/FP_ILOGBNAN.c
new file mode 100644
index 00000000..65aa04f1
--- /dev/null
+++ b/src/math/FP_ILOGBNAN.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define FP_ILOGBNAN INT_MAX
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_INFINITE.c b/src/math/FP_INFINITE.c
new file mode 100644
index 00000000..e5aadaf8
--- /dev/null
+++ b/src/math/FP_INFINITE.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define FP_INFINITE 0
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_NAN.c b/src/math/FP_NAN.c
new file mode 100644
index 00000000..804765cd
--- /dev/null
+++ b/src/math/FP_NAN.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define FP_NAN 1
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_NORMAL.c b/src/math/FP_NORMAL.c
new file mode 100644
index 00000000..171ca6bf
--- /dev/null
+++ b/src/math/FP_NORMAL.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define FP_NORMAL 2
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_SUBNORMAL.c b/src/math/FP_SUBNORMAL.c
new file mode 100644
index 00000000..500ecd14
--- /dev/null
+++ b/src/math/FP_SUBNORMAL.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define FP_SUBNORMAL 3
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/FP_ZERO.c b/src/math/FP_ZERO.c
new file mode 100644
index 00000000..54e5d323
--- /dev/null
+++ b/src/math/FP_ZERO.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define FP_ZERO 4
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/HUGE_VAL.c b/src/math/HUGE_VAL.c
new file mode 100644
index 00000000..f72afacf
--- /dev/null
+++ b/src/math/HUGE_VAL.c
@@ -0,0 +1,13 @@
+#include <math.h>
+#define HUGE_VAL (1.0) /* TODO: massive positive double */
+
+/** a huge value **/
+
+/***
+is a large positive TYPE(double), not necessarily representable as a
+TYPE(float). It is used as a sentinel value by several functions in the
+standard library.
+***/
+/*
+STDC(1)
+*/
diff --git a/src/math/HUGE_VALF.c b/src/math/HUGE_VALF.c
new file mode 100644
index 00000000..41ea0f3e
--- /dev/null
+++ b/src/math/HUGE_VALF.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define HUGE_VALF /* TODO: massive positive float */
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/HUGE_VALL.c b/src/math/HUGE_VALL.c
new file mode 100644
index 00000000..7745a373
--- /dev/null
+++ b/src/math/HUGE_VALL.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define HUGE_VALL /* TODO: massive positive long double */
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/INFINITY.c b/src/math/INFINITY.c
new file mode 100644
index 00000000..64e3ac95
--- /dev/null
+++ b/src/math/INFINITY.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define INFINITY /* TODO: positive or unsigned float infinity */
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/MATH_ERREXCEPT.c b/src/math/MATH_ERREXCEPT.c
new file mode 100644
index 00000000..1ad3a6d6
--- /dev/null
+++ b/src/math/MATH_ERREXCEPT.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define MATH_ERREXCEPT 2
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/MATH_ERRNO.c b/src/math/MATH_ERRNO.c
new file mode 100644
index 00000000..07cb5815
--- /dev/null
+++ b/src/math/MATH_ERRNO.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define MATH_ERRNO 1
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/NAN.c b/src/math/NAN.c
new file mode 100644
index 00000000..6c5d778f
--- /dev/null
+++ b/src/math/NAN.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define NAN /* TODO: float quiet NaN */
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/acos.c b/src/math/acos.c
new file mode 100644
index 00000000..a610fe2e
--- /dev/null
+++ b/src/math/acos.c
@@ -0,0 +1,35 @@
+# define TGSOURCE "std/9899-1990/math/acos.c"
+#include <math.h>
+#include "errno.h"
+#include "nonstd/tgmath.h"
+
+/** arc cosine **/
+TYPE TGFN(acos)(TYPE x)
+{
+ if (x < -1 || x > 1) {
+ errno = EDOM; /* ARGUMENT(x) not in the range [-1, +1] */
+ return TGHUGE;
+ }
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(a value in range `[0, PI()]'); */
+ return (TYPE)0.0;
+}
+
+/***
+compute the principal value of the arc cosine of ARGUMENT(x), which must be in
+the range [-1, +1].
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/acosh.c b/src/math/acosh.c
new file mode 100644
index 00000000..3e64e9d1
--- /dev/null
+++ b/src/math/acosh.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "acosh.c"
+#include "nontstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(acosh)(TYPE x)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/asin.c b/src/math/asin.c
new file mode 100644
index 00000000..4c1599fe
--- /dev/null
+++ b/src/math/asin.c
@@ -0,0 +1,35 @@
+# define TGSOURCE "asin.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** arc sine **/
+TYPE TGFN(asin)(TYPE x)
+{
+ if (x < -1.0 || x > 1.0) {
+ errno = EDOM; /* ARGUMENT(x) is not in the range [-1, +1] */
+ return TGHUGE;
+ }
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(a value in range `[-PI()/2, +PI()/2]'); */
+ return (TYPE)0.0;
+}
+
+/***
+compute the principal value of the arc sine of ARGUMENT(x), which must be in
+the range [-1, +1].
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/asinh.c b/src/math/asinh.c
new file mode 100644
index 00000000..e4086844
--- /dev/null
+++ b/src/math/asinh.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "asinh.c"
+#include "nontsd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(asinh)(TYPE x)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/atan.c b/src/math/atan.c
new file mode 100644
index 00000000..5b4b0330
--- /dev/null
+++ b/src/math/atan.c
@@ -0,0 +1,48 @@
+# define TGSOURCE "atan.c"
+#include <math.h>
+#include "errno.h"
+#include "nonstd/tgmath.h"
+
+/** arc tangent **/
+TYPE TGFN(atan)(TYPE x)
+{
+ int MAXLOOPS = 10;
+ TYPE arctan = 0.0;
+ TYPE power = 1.0;
+ int i;
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* TODO: correct input domain */
+ /* TODO: tweak number of loops */
+
+ /* arctan x = x - x^3/3 + x^5/5 - x^7/7 ... */
+ for (i = 1; i < MAXLOOPS; i++) {
+ power *= x;
+
+ if (i % 4 == 1) {
+ arctan += power / i;
+ } else if (i % 4 == 3) {
+ arctan -= power / i;
+ }
+ }
+
+ /* RETURN_SUCCESS(a value in the range `[-PI()/2, +PI()/2]'); */
+ return arctan;
+}
+
+/***
+compute the principal value of the arc tangent of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/atan2.c b/src/math/atan2.c
new file mode 100644
index 00000000..be5b9dd6
--- /dev/null
+++ b/src/math/atan2.c
@@ -0,0 +1,41 @@
+# define TGSOURCE "atan2.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+#include "nonstd/assert.h"
+
+/** arc tangent **/
+TYPE TGFN(atan2)(TYPE y, TYPE x)
+{
+ ASSERT_NONZERO(x);
+
+ if (y == 0 && x == 0) {
+ errno = EDOM; /* ARGUMENT(y) and ARGUMENT(x) are both LITERAL(0)) */
+ return TGHUGE;
+ }
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ TYPE ret = TGFN(tan)(y / x);
+ /* FIXME: quadrant */
+ /* RETURN_SUCCESS(a value in range `[-PI(), +PI()]'); */
+ return ret;
+}
+
+/***
+functions compute the principal value of the arc tangent of
+ARGUMENT(y)/ARGUMENT(x), using the signs of both to place the return value in
+the correct quadrant.
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/atanh.c b/src/math/atanh.c
new file mode 100644
index 00000000..2f5f62f1
--- /dev/null
+++ b/src/math/atanh.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "atanh.c"
+#include "nontstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(atanh)(TYPE x)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/cbrt.c b/src/math/cbrt.c
new file mode 100644
index 00000000..596cabd2
--- /dev/null
+++ b/src/math/cbrt.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "cbrt.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(cbrt)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/ceil.c b/src/math/ceil.c
new file mode 100644
index 00000000..e9f950c8
--- /dev/null
+++ b/src/math/ceil.c
@@ -0,0 +1,30 @@
+# define TGSOURCE "ceil.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** round up to nearest integer **/
+TYPE TGFN(ceil)(TYPE x)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(CEIL(ARGUMENT(x))); */
+ return x;
+}
+
+/***
+compute the smallest integral value that is not less
+than ARGUMENT(x), returning it as the same floating-point type as ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/copysign.c b/src/math/copysign.c
new file mode 100644
index 00000000..d070036b
--- /dev/null
+++ b/src/math/copysign.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "copysign.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(copysign)(TYPE x, TYPE y)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/cos.c b/src/math/cos.c
new file mode 100644
index 00000000..0690b6ee
--- /dev/null
+++ b/src/math/cos.c
@@ -0,0 +1,51 @@
+# define TGSOURCE "cos.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** cosine **/
+TYPE TGFN(cos)(TYPE x)
+{
+ int MAXLOOPS = 10;
+ int factorial = 1;
+ int i;
+ TYPE cosine = 1.0;
+ TYPE power = 1.0;
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* TODO: make sure x is in the right domain */
+ /* TODO: tweak number of loops */
+
+ /* cos x = 1 - x^2/2! + x^4/4! -x^6/6! ... */
+ for (i = 1; i < MAXLOOPS; i++) {
+ power = power * x;
+ factorial = factorial * i;
+
+ if (i % 4 == 0) {
+ cosine += power / factorial;
+ } else if (i % 4 == 2) {
+ cosine -= power / factorial;
+ }
+ }
+
+ /* RETURN_SUCCESS(the cosine of ARGUMENT(x)); */
+ return cosine;
+}
+
+/***
+compute cosine of ARGUMENT(x), in radians.
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
+
diff --git a/src/math/cosh.c b/src/math/cosh.c
new file mode 100644
index 00000000..75301cf1
--- /dev/null
+++ b/src/math/cosh.c
@@ -0,0 +1,29 @@
+# define TGSOURCE "cosh.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** hyperbolic cosine **/
+TYPE TGFN(cosh)(TYPE x)
+{
+ if (0) {
+ errno = ERANGE; /* The magnitude of ARGUMENT(x) is too large */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(the hyperbolic cosine of ARGUMENT(x)); */
+ return x;
+}
+
+/***
+compute the hyperbolic cosine of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/double_t.c b/src/math/double_t.c
new file mode 100644
index 00000000..47b1fb36
--- /dev/null
+++ b/src/math/double_t.c
@@ -0,0 +1,16 @@
+#include <math.h>
+
+#if FLT_EVAL_METHOD == 0
+typedef double double_t;
+#elif FLT_EVAL_METHOD == 1
+typedef double double_t;
+#elif FLT_EVAL_METHOD == 2
+typedef long double double_t;
+#else
+ /* implementation defined */
+#endif
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/erf.c b/src/math/erf.c
new file mode 100644
index 00000000..63525700
--- /dev/null
+++ b/src/math/erf.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "erf.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(erf)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/erfc.c b/src/math/erfc.c
new file mode 100644
index 00000000..3aef20d3
--- /dev/null
+++ b/src/math/erfc.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "erfc.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(erfc)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/exp.c b/src/math/exp.c
new file mode 100644
index 00000000..b63ecf4f
--- /dev/null
+++ b/src/math/exp.c
@@ -0,0 +1,44 @@
+# define TGSOURCE "exp.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** exponential function **/
+TYPE TGFN(exp)(TYPE x)
+{
+ int MAXLOOPS = 10;
+ int i;
+ int factorial = 1;
+ TYPE exponent = 1.0;
+ TYPE power = 1.0;
+
+ if (0) {
+ errno = ERANGE; /* The magnitude of ARGUMENT(x) is too large */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* TODO: tweak max loops */
+
+ /* exp x = 1 + x + x^2/2! + x^3/3! + x^4/4! ... */
+ for (i = 1; i < MAXLOOPS; i++) {
+ power *= x;
+ factorial *= i;
+ exponent += power / factorial;
+ }
+
+ /* RETURN_SUCCESS(the exponential function of ARGUMENT(x)); */
+ return exponent;
+}
+
+/***
+compute the exponential function of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/exp2.c b/src/math/exp2.c
new file mode 100644
index 00000000..7f67294d
--- /dev/null
+++ b/src/math/exp2.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "exp2.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(exp2)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/expm1.c b/src/math/expm1.c
new file mode 100644
index 00000000..f50c43a4
--- /dev/null
+++ b/src/math/expm1.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "expm1.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(exmp1)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/fabs.c b/src/math/fabs.c
new file mode 100644
index 00000000..abd71bb7
--- /dev/null
+++ b/src/math/fabs.c
@@ -0,0 +1,29 @@
+# define TGSOURCE "fabs.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** absolute value **/
+TYPE TGFN(fabs)(TYPE x)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(ABS(ARGUMENT(x))); */
+ return x < 0.0 ? -x : x;
+}
+
+/***
+compute the absolute value of a floating-point number ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/fdim.c b/src/math/fdim.c
new file mode 100644
index 00000000..922c5040
--- /dev/null
+++ b/src/math/fdim.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "fdim.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(fdim)(TYPE x, TYPE y)
+{
+ return x - y;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/float_t.c b/src/math/float_t.c
new file mode 100644
index 00000000..251f5b2e
--- /dev/null
+++ b/src/math/float_t.c
@@ -0,0 +1,16 @@
+#include <math.h>
+
+#if FLT_EVAL_METHOD == 0
+typedef float float_t;
+#elif FLT_EVAL_METHOD == 1
+typedef double float_t;
+#elif FLT_EVAL_METHOD == 2
+typedef long double float_t;
+#else
+ /* implementation defined */
+#endif
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/floor.c b/src/math/floor.c
new file mode 100644
index 00000000..2b2e07ab
--- /dev/null
+++ b/src/math/floor.c
@@ -0,0 +1,30 @@
+# define TGSOURCE "floor.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** round down to nearest integer **/
+TYPE TGFN(floor)(TYPE x)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(FLOOR(ARGUMENT(x))); */
+ return x;
+}
+
+/***
+compute the largest integral value that is not greater
+than ARGUMENT(x), returning it as the same floating-point type as ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/fma.c b/src/math/fma.c
new file mode 100644
index 00000000..e2827918
--- /dev/null
+++ b/src/math/fma.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "fma.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(fma)(TYPE x, TYPE y, TYPE z)
+{
+ return x - y - z;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/fmax.c b/src/math/fmax.c
new file mode 100644
index 00000000..6b056b2b
--- /dev/null
+++ b/src/math/fmax.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "fmax.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(fmax)(TYPE x, TYPE y)
+{
+ return x - y;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/fmin.c b/src/math/fmin.c
new file mode 100644
index 00000000..56966432
--- /dev/null
+++ b/src/math/fmin.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "fmin.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(fmin)(TYPE x, TYPE y)
+{
+ return x - y;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/fmod.c b/src/math/fmod.c
new file mode 100644
index 00000000..98091880
--- /dev/null
+++ b/src/math/fmod.c
@@ -0,0 +1,35 @@
+# define TGSOURCE "fmod.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** floating-point remainder **/
+TYPE TGFN(fmod)(TYPE x, TYPE y)
+{
+ if (y == 0) {
+ return 0;
+ }
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(ARGUMENT(x) - VAR(i) * ARGUMENT(y)); */
+ return x - x / y;
+}
+
+/***
+compute the floating-point remainder of ARGUMENT(x)/ARGUMENT(y).
+FIXME: I am not sure I understand this.
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+IMPLEMENTATION(Whether ARGUMENT(y) being LITERAL(0) results in a domain error or THIS() returning LITERAL(0))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/fpclassify.c b/src/math/fpclassify.c
new file mode 100644
index 00000000..da9b24af
--- /dev/null
+++ b/src/math/fpclassify.c
@@ -0,0 +1,12 @@
+#include <math.h>
+ int __fpclassifyf(float x);
+ int __fpclassifyd(double x);
+ int __fpclassifyl(long double x);
+
+#define fpclassify(x) ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) : \
+ (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) : __fpclassifyl(x))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/frexp.c b/src/math/frexp.c
new file mode 100644
index 00000000..70c87eb1
--- /dev/null
+++ b/src/math/frexp.c
@@ -0,0 +1,39 @@
+# define TGSOURCE "frexp.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** extract mantissa and exponent **/
+TYPE TGFN(frexp)(TYPE value, int *exp)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN(a value in range [1/2``,'' 1``)'', TODO: explain this); */
+ /* RETURN(LITERAL(0), ARGUMENT(x) is LITERAL(0)); */
+ (void)exp;
+ return value;
+}
+
+/***
+break floating-point numbers into a normalized fraction and an integral power
+of 2.
+
+The normalized fraction is a value in the range [1/2, 1) or 0.
+
+The integral exponent of 2 is stored in the TYPE(int) pointed to by
+ARGUMENT(exp).
+
+Multiplying the normalized fraction by 2 to the power ARGUMENT(*exp).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/hypot.c b/src/math/hypot.c
new file mode 100644
index 00000000..8a792143
--- /dev/null
+++ b/src/math/hypot.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "hypot.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(hypot)(TYPE x, TYPE y)
+{
+ return x - y;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/ilogb.c b/src/math/ilogb.c
new file mode 100644
index 00000000..ef9c0595
--- /dev/null
+++ b/src/math/ilogb.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "ilogb.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(ilogb)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isfinite.c b/src/math/isfinite.c
new file mode 100644
index 00000000..5fbf3582
--- /dev/null
+++ b/src/math/isfinite.c
@@ -0,0 +1,12 @@
+#include <math.h>
+ int __isfinitef(float x);
+ int __isfinited(double x);
+ int __isfinitel(long double x);
+
+#define isfinite(x) ((sizeof (x) == sizeof (float)) ? __isfinitef(x) : \
+ (sizeof (x) == sizeof (double)) ? __isfinited(x) : __isfinitel(x))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isgreater.c b/src/math/isgreater.c
new file mode 100644
index 00000000..672dbe6a
--- /dev/null
+++ b/src/math/isgreater.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define isgreater(x,y) ((x) > (y))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isgreaterequal.c b/src/math/isgreaterequal.c
new file mode 100644
index 00000000..de0eaaf2
--- /dev/null
+++ b/src/math/isgreaterequal.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define isgreaterequal(x,y) ((x) >= (y))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isinf.c b/src/math/isinf.c
new file mode 100644
index 00000000..031d870a
--- /dev/null
+++ b/src/math/isinf.c
@@ -0,0 +1,12 @@
+#include <math.h>
+ int __isinff(float x);
+ int __isinfd(double x);
+ int __isinfl(long double x);
+
+#define isinf(x) ((sizeof (x) == sizeof (float)) ? __isinff(x) : \
+ (sizeof (x) == sizeof (double)) ? __isinfd(x) : __isinfl(x))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isless.c b/src/math/isless.c
new file mode 100644
index 00000000..9685e84a
--- /dev/null
+++ b/src/math/isless.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define isless(x,y) ((x) < (y))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/islessequal.c b/src/math/islessequal.c
new file mode 100644
index 00000000..97ded436
--- /dev/null
+++ b/src/math/islessequal.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define islessequal(x,y) ((x) <= (y))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/islessgreater.c b/src/math/islessgreater.c
new file mode 100644
index 00000000..a2566474
--- /dev/null
+++ b/src/math/islessgreater.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define islessgreater(x,y) ((x) < (y) || (x) > (y))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isnan.c b/src/math/isnan.c
new file mode 100644
index 00000000..2ae4b4d2
--- /dev/null
+++ b/src/math/isnan.c
@@ -0,0 +1,12 @@
+#include <math.h>
+ int __isnanf(float x);
+ int __isnand(double x);
+ int __isnanl(long double x);
+
+#define isnan(x) ((sizeof (x) == sizeof (float)) ? __isnanf(x) : \
+ (sizeof (x) == sizeof (double)) ? __isnand(x) : __isnanl(x))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isnormal.c b/src/math/isnormal.c
new file mode 100644
index 00000000..f4d9e175
--- /dev/null
+++ b/src/math/isnormal.c
@@ -0,0 +1,12 @@
+#include <math.h>
+ int __isnormalf(float x);
+ int __isnormald(double x);
+ int __isnormall(long double x);
+
+#define isnormal(x) ((sizeof (x) == sizeof (float)) ? __isnormalf(x) : \
+ (sizeof (x) == sizeof (double)) ? __isnormald(x) : __isnormall(x))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/isunordered.c b/src/math/isunordered.c
new file mode 100644
index 00000000..ac8cbfff
--- /dev/null
+++ b/src/math/isunordered.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define isunordered(x,y) /* TODO */
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/ldexp.c b/src/math/ldexp.c
new file mode 100644
index 00000000..f32c1d76
--- /dev/null
+++ b/src/math/ldexp.c
@@ -0,0 +1,30 @@
+# define TGSOURCE "ldexp.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** multiply by a power of 2 **/
+TYPE TGFN(ldexp)(TYPE x, int exp)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(ARGUMENT(x) * POW(2,ARGUMENT(exp))); */
+ return x * TGFN(pow)(2, exp);
+}
+
+/***
+multiply the floating-point number specifed by ARGUMENT(x)
+by 2 raised to the power ARGUMENT(exp).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/lgamma.c b/src/math/lgamma.c
new file mode 100644
index 00000000..381dc442
--- /dev/null
+++ b/src/math/lgamma.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "lgamma.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(lgamma)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/llrint.c b/src/math/llrint.c
new file mode 100644
index 00000000..f0b9e9bf
--- /dev/null
+++ b/src/math/llrint.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "llrint.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+long long int TGFN(llrint)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/llround.c b/src/math/llround.c
new file mode 100644
index 00000000..f259cfbb
--- /dev/null
+++ b/src/math/llround.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "llround.c"
+#include "nontsd/tgmath.h"
+#include <math.h>
+
+long long int TGFN(llround)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/log.c b/src/math/log.c
new file mode 100644
index 00000000..a75fdafa
--- /dev/null
+++ b/src/math/log.c
@@ -0,0 +1,34 @@
+# define TGSOURCE "log.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** natural logarithm **/
+TYPE TGFN(log)(TYPE x)
+{
+ if (x < 0) {
+ errno = EDOM; /* ARGUMENT(x) is negative */
+ return TGHUGE;
+ }
+
+ if (x == 0) {
+ errno = ERANGE; /* ARGUMENT(x) is LITERAL(0) */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(the natural logarithm of ARGUMENT(x)); */
+ return x;
+}
+
+/***
+compute the natural logarithm of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/log10.c b/src/math/log10.c
new file mode 100644
index 00000000..5000910b
--- /dev/null
+++ b/src/math/log10.c
@@ -0,0 +1,34 @@
+# define TGSOURCE "log10.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** base-10 logarithm **/
+TYPE TGFN(log10)(TYPE x)
+{
+ if (x < 0) {
+ errno = EDOM; /* ARGUMENT(x) is negative */
+ return TGHUGE;
+ }
+
+ if (x == 0) {
+ errno = ERANGE; /* ARGUMENT(x) is LITERAL(0) */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(the base-10 logarithm of ARGUMENT(x)); */
+ return x;
+}
+
+/***
+compute the base-ten logarithm of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/log1p.c b/src/math/log1p.c
new file mode 100644
index 00000000..1ed70439
--- /dev/null
+++ b/src/math/log1p.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "log1p.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(log1p)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/log2.c b/src/math/log2.c
new file mode 100644
index 00000000..16a0363c
--- /dev/null
+++ b/src/math/log2.c
@@ -0,0 +1,13 @@
+#define TGSOURCE "log2.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(log2)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/logb.c b/src/math/logb.c
new file mode 100644
index 00000000..c14582df
--- /dev/null
+++ b/src/math/logb.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "logb.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(logb)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/lrint.c b/src/math/lrint.c
new file mode 100644
index 00000000..2ee0b986
--- /dev/null
+++ b/src/math/lrint.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "lrint.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+long int TGFN(lrint)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/lround.c b/src/math/lround.c
new file mode 100644
index 00000000..e27c1225
--- /dev/null
+++ b/src/math/lround.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "lround.c"
+#include "nontstd/tgmath.h"
+#include <math.h>
+
+long int TGFN(lround)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/math_errhandling.c b/src/math/math_errhandling.c
new file mode 100644
index 00000000..2c34327c
--- /dev/null
+++ b/src/math/math_errhandling.c
@@ -0,0 +1,7 @@
+#include <math.h>
+#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/modf.c b/src/math/modf.c
new file mode 100644
index 00000000..73c5d3f3
--- /dev/null
+++ b/src/math/modf.c
@@ -0,0 +1,33 @@
+# define TGSOURCE "modf.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** decompose floating-point numbers **/
+TYPE TGFN(modf)(TYPE value, TYPE *iptr)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(the signed fractional part of ARGUMENT(value)); */
+ (void)iptr;
+ return value;
+}
+
+/***
+break ARGUMENT(value) into integral and fractional parts.
+Each part has the same sign as ARGUMENT(value). The integral part is converted to
+the same floating-point type as ARGUMENT(value) and stored in the object pointed to
+by ARGUMENT(iptr).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/nan.c b/src/math/nan.c
new file mode 100644
index 00000000..ac96ca3d
--- /dev/null
+++ b/src/math/nan.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "nan.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(nan)(const char *tagp)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/nearbyint.c b/src/math/nearbyint.c
new file mode 100644
index 00000000..1b3a5c72
--- /dev/null
+++ b/src/math/nearbyint.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "nearbyint.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(nearbyint)(TYPE x)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/nextafter.c b/src/math/nextafter.c
new file mode 100644
index 00000000..315b184c
--- /dev/null
+++ b/src/math/nextafter.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "nextafter.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(nextafter)(TYPE x, TYPE y)
+{
+ return x - y;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/nexttoward.c b/src/math/nexttoward.c
new file mode 100644
index 00000000..6825d89b
--- /dev/null
+++ b/src/math/nexttoward.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "nexttoward.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(nexttoward)(TYPE x, TYPE y)
+{
+ return x - y;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/pow.c b/src/math/pow.c
new file mode 100644
index 00000000..4fb3aa2a
--- /dev/null
+++ b/src/math/pow.c
@@ -0,0 +1,39 @@
+# define TGSOURCE "pow.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** exponentiation **/
+TYPE TGFN(pow)(TYPE x, TYPE y)
+{
+ if (x < 0 /* && !isintegral(y) */) {
+ errno = EDOM; /* ARGUMENT(x) is negative and ARGUMENT(y) is not an integer */
+ return TGHUGE;
+ }
+
+ if (x == 0 && y <= 0) {
+ errno = EDOM; /* ARGUMENT(x) is LITERAL(0) and ARGUMENT(y) is less than or equal to LITERAL(0) */
+ return TGHUGE;
+ }
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(POW(ARGUMENT(x), ARGUMENT(y))); */
+ return x * y;
+}
+
+/***
+compute ARGUMENT(x) raised to the power ARGUMENT(y).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/remquo.c b/src/math/remquo.c
new file mode 100644
index 00000000..3aec6382
--- /dev/null
+++ b/src/math/remquo.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "remquo.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(remquo)(TYPE x, TYPE y, int *quo)
+{
+ return x - y;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/rint.c b/src/math/rint.c
new file mode 100644
index 00000000..f6ba653f
--- /dev/null
+++ b/src/math/rint.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "rint.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(rint)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/round.c b/src/math/round.c
new file mode 100644
index 00000000..504bcead
--- /dev/null
+++ b/src/math/round.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "round.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(round)(TYPE x)
+{
+ return x;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/scalbln.c b/src/math/scalbln.c
new file mode 100644
index 00000000..1c564393
--- /dev/null
+++ b/src/math/scalbln.c
@@ -0,0 +1,23 @@
+# define TGSOURCE "scalbln.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(scalbln)(TYPE x, long int n)
+{
+ return x - n;
+}
+
+/* c99
+Description
+2
+The scalbn and scalbln functions compute x × FLT_RADIX n efficiently, not
+normally by computing FLT_RADIX n explicitly. A range error may occur.
+Returns
+3
+The scalbn and scalbln functions return x × FLT_RADIX n .
+*/
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/scalbn.c b/src/math/scalbn.c
new file mode 100644
index 00000000..3bbaa431
--- /dev/null
+++ b/src/math/scalbn.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "scalbn.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(scalbn)(TYPE x, int n)
+{
+ return x - n;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/signbit.c b/src/math/signbit.c
new file mode 100644
index 00000000..7b5ba8a2
--- /dev/null
+++ b/src/math/signbit.c
@@ -0,0 +1,12 @@
+#include <math.h>
+ int __signbitf(float x);
+ int __signbitd(double x);
+ int __signbitl(long double x);
+
+#define signbit(x) ((sizeof (x) == sizeof (float)) ? __signbitf(x) : \
+ (sizeof (x) == sizeof (double)) ? __signbitd(x) : __signbitl(x))
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/sin.c b/src/math/sin.c
new file mode 100644
index 00000000..c5d127f0
--- /dev/null
+++ b/src/math/sin.c
@@ -0,0 +1,51 @@
+# define TGSOURCE "sin.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** sine **/
+TYPE TGFN(sin)(TYPE x)
+{
+ int MAXLOOPS = 10;
+ int factorial = 1;
+ int i;
+ TYPE sine = 0.0;
+ TYPE power = 1.0;
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* TODO: make sure x is in the input domain */
+ /* TODO: tweak the max number of loops */
+
+ /* RETURN_SUCCESS(the sine of ARGUMENT(x)); */
+
+ /* sin x = x - x^3/3! + x^5/5! - x^7/7! ... */
+ for (i = 1; i < MAXLOOPS; i++) {
+ power = power * x;
+ factorial = factorial * i;
+
+ if (i % 4 == 1) {
+ sine += power / factorial;
+ } else if (i % 4 == 3) {
+ sine -= power / factorial;
+ }
+ }
+
+ return sine;
+}
+
+/***
+compute sine of ARGUMENT(x), in radians.
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/sinh.c b/src/math/sinh.c
new file mode 100644
index 00000000..26363703
--- /dev/null
+++ b/src/math/sinh.c
@@ -0,0 +1,29 @@
+# define TGSOURCE "sinh.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** hyperbolic sine **/
+TYPE TGFN(sinh)(TYPE x)
+{
+ if (0) {
+ errno = ERANGE; /* The magnitude of ARGUMENT(x) is too large */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(the hyperbolic sine of ARGUMENT(x)); */
+ return x;
+}
+
+/***
+compute hyperbolic sine of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/sqrt.c b/src/math/sqrt.c
new file mode 100644
index 00000000..dd9d4433
--- /dev/null
+++ b/src/math/sqrt.c
@@ -0,0 +1,34 @@
+# define TGSOURCE "sqrt.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** square root **/
+TYPE TGFN(sqrt)(TYPE x)
+{
+ if (x < 0) {
+ errno = EDOM; /* ARGUMENT(x) is negative */
+ return TGHUGE;
+ }
+
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(SQRT(ARGUMENT(x))); */
+ return x;
+}
+
+/***
+compute the principal square root of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/tan.c b/src/math/tan.c
new file mode 100644
index 00000000..16d83d78
--- /dev/null
+++ b/src/math/tan.c
@@ -0,0 +1,29 @@
+# define TGSOURCE "tan.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** tangent **/
+TYPE TGFN(tan)(TYPE x)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(the tangent of ARGUMENT(x)); */
+ return TGFN(sin)(x) / TGFN(cos)(x);
+}
+
+/***
+compute the tanget of ARGUMENT(x), in radians.
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/tanh.c b/src/math/tanh.c
new file mode 100644
index 00000000..d2c09fe2
--- /dev/null
+++ b/src/math/tanh.c
@@ -0,0 +1,29 @@
+# define TGSOURCE "tanh.c"
+#include <math.h>
+#include "nonstd/tgmath.h"
+#include "errno.h"
+
+/** hyperbolic tangent **/
+TYPE TGFN(tanh)(TYPE x)
+{
+ if (0) {
+ errno = ERANGE; /* The result cannot be represented */
+ /* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
+ return TGHUGE;
+ }
+
+ /* RETURN_SUCCESS(the hyperbolic tangent of ARGUMENT(x)); */
+ return x;
+}
+
+/***
+compute the hyperbolic tangent of ARGUMENT(x).
+***/
+
+/*
+IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
+LINK(m)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/math/tgamma.c b/src/math/tgamma.c
new file mode 100644
index 00000000..b7c7094c
--- /dev/null
+++ b/src/math/tgamma.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "tgamma.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(tgamma)(TYPE x)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/
diff --git a/src/math/trunc.c b/src/math/trunc.c
new file mode 100644
index 00000000..d047d7f8
--- /dev/null
+++ b/src/math/trunc.c
@@ -0,0 +1,13 @@
+# define TGSOURCE "trunc.c"
+#include "nonstd/tgmath.h"
+#include <math.h>
+
+TYPE TGFN(trunc)(TYPE x)
+{
+ return 0.0;
+}
+
+/*
+STDC(199901)
+LINK(m)
+*/