aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/cfrac/ptou.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/benchmarks/cfrac/ptou.c')
-rw-r--r--src/benchmarks/cfrac/ptou.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/benchmarks/cfrac/ptou.c b/src/benchmarks/cfrac/ptou.c
new file mode 100644
index 0000000..b8ca07b
--- /dev/null
+++ b/src/benchmarks/cfrac/ptou.c
@@ -0,0 +1,31 @@
+#include "pdefs.h"
+#include "pcvt.h"
+#include "precision.h"
+
+/*
+ * Precision to unsigned
+ */
+unsigned int ptou(u)
+ precision u;
+{
+ register digitPtr uPtr;
+ register accumulator temp;
+
+ (void) pparm(u);
+ if (u->sign) {
+ temp = (unsigned long) errorp(PDOMAIN, "ptou", "negative argument");
+ } else {
+ uPtr = u->value + u->size;
+ temp = 0;
+ do {
+ if (temp > divBase(MAXUNSIGNED - *--uPtr)) {
+ temp = (unsigned long) errorp(POVERFLOW, "ptou", "overflow");
+ break;
+ }
+ temp = mulBase(temp);
+ temp += *uPtr;
+ } while (uPtr > u->value);
+ }
+ pdestroy(u);
+ return (unsigned int) temp;
+}