summaryrefslogtreecommitdiff
path: root/src/math/sqrt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/sqrt.c')
-rw-r--r--src/math/sqrt.c34
1 files changed, 34 insertions, 0 deletions
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)
+*/