aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/cfrac/psqrt.c
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-08-24 17:57:51 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-08-24 17:57:51 +0200
commit77ac9ce0a5c55d4f79f8fb8f7daa59ddb53cb507 (patch)
tree93d4e30a207265af03394d347bfff76ba677f3ce /src/benchmarks/cfrac/psqrt.c
parent971adefadb94e8780b1a73f08ed11d76c2ead8a2 (diff)
downloadallocbench-77ac9ce0a5c55d4f79f8fb8f7daa59ddb53cb507.tar.gz
allocbench-77ac9ce0a5c55d4f79f8fb8f7daa59ddb53cb507.zip
add cfrac benchmark
Diffstat (limited to 'src/benchmarks/cfrac/psqrt.c')
-rw-r--r--src/benchmarks/cfrac/psqrt.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/benchmarks/cfrac/psqrt.c b/src/benchmarks/cfrac/psqrt.c
new file mode 100644
index 0000000..00531a6
--- /dev/null
+++ b/src/benchmarks/cfrac/psqrt.c
@@ -0,0 +1,29 @@
+#include "precision.h"
+
+/*
+ * Square root
+ */
+precision psqrt(y)
+ precision y;
+{
+ int i;
+ precision x = pUndef, lastx = pUndef;
+
+ i = pcmpz(pparm(y));
+ if (i == 0) { /* if y == 0 */
+ pset(&lastx, pzero);
+ } else if (i < 0) { /* if y negative */
+ pset(&x, errorp(PDOMAIN, "psqrt", "negative argument"));
+ } else {
+ pset(&x, y);
+ do {
+ pset(&lastx, x);
+ pset(&x, phalf(padd(x, pdiv(y, x))));
+ } while (plt(x, lastx));
+ }
+
+ pdestroy(x);
+
+ pdestroy(y);
+ return presult(lastx);
+}