aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/cfrac/ptou.c
blob: b8ca07b15b54f115dbb6a42c4282a129a03a7f19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}