aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/cfrac/pfloat.c
blob: 63f43445664c6b6a34220aa61804523d3197414d (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 *	High Precision Math Library Supplement for floating point routines
 */
#include <stdio.h>
#include <math.h>
#include "pdefs.h"
#include "pcvt.h"
#include "precision.h"

extern precision palloc();

/*
 * double to precision
 */
precision dtop(f)
   register double f;
{
   register digitPtr	 uPtr;
   register precision    u;

   u = palloc(DOUBLESIZE);		/* pretty big */
   if (u == pUndef) return u;

   if (f < 0.0) {
      f = -f;
      u->sign = true;
   } else {
      u->sign = false;
   }
   uPtr	      = u->value;
   do {
      *uPtr++ = fmod(f, (double) BASE);
      f	      = floor(f / (double) BASE);
   } while (f != 0.0);

   u->size = (uPtr - u->value);

   return presult(u);
}

/*
 *  precision to double (no overflow check)
 */
double ptod(u)
   precision	  u;
{
   register digitPtr uPtr;
   register double   f;

   (void) pparm(u);
   uPtr = u->value + u->size;
   f    = 0.0;
   do {
      f = f * (double) BASE + (double) *--uPtr;
   } while (uPtr > u->value);

   if (u->sign) f = -f;

   pdestroy(u);
   return f;
}