-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreal.c
62 lines (54 loc) · 988 Bytes
/
real.c
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
62
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include "real.h"
struct REAL
{
double value;
};
REAL *
newREAL(double x)
{
REAL *p = malloc(sizeof(REAL));
assert(p != 0);
p->value = x;
return p;
}
double
getREAL(REAL *v)
{
return v->value;
}
double
setREAL(REAL *v,double x)
{
double old = v->value;
v->value = x;
return old;
}
void
displayREAL(void *v,FILE *fp)
{
fprintf(fp,"%f",getREAL((REAL *) v));
}
int
compareREAL(void *v,void *w) {
if (getREAL(v) > getREAL(w)) {return 1;}
else if (getREAL(w) > getREAL(v)) {return -1;}
else {return 0;}
}
int
rcompareREAL(void *v,void *w) {
if (getREAL(v) > getREAL(w)) {return -1;}
else if (getREAL(w) > getREAL(v)) {return 1;}
else {return 0;}
}
void
freeREAL(void *v)
{
// printf("REAL FREEING: ");
// displayREAL(v, stdout);
// printf("\n");
free((REAL *) v);
}