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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* Copyright (C) 2000, Imperial College
*
* This file is part of the Imperial College Exact Real Arithmetic Library.
* See the copyright notice included in the distribution for conditions
* of use.
*/
#include <stdio.h>
#include "real.h"
#include "real-impl.h"
/*
* Functions for allocating and managing vector LFTs in the heap.
*/
Vec *
allocVec()
{
Vec *vec;
if ((vec = (Vec *) malloc (sizeof(Vec))) == NULL)
Error(FATAL, E_INT, "allocVec", "malloc failed");
#ifdef DAVINCI
newNodeId(vec);
#else
#ifdef TRACE
newNodeId(vec);
#endif
#endif
vec->tag.type = VECTOR;
vec->tag.dumped = FALSE;
vec->strm = (Real) NULL;
#ifdef DAVINCI
beginGraphUpdate();
newNode(vec, VECTOR);
endGraphUpdate();
#endif
return vec;
}
/*
* The next family of functions are one level up. They allocate structures
* in the heap for lfts and also initialize both the entries in the lft
* as well as the pointers to the heap objects to which the lft is being
* applied.
*/
/*
* Create a vector with small entries. A vector is a rational. We might
* wish to disallow 0/0.
*/
Real
vector_Int(int a, int b)
{
Vec *vec;
if ((a == 0) && (b == 0))
Error(FATAL, E_INT, "vector_Int", "zero column vector");
vec = allocVec();
mpz_init_set_si(vec->vec[0], a);
mpz_init_set_si(vec->vec[1], b);
canonVector(vec->vec);
if (vectorSign(vec->vec) == 0)
vec->tag.isSigned = TRUE;
else
vec->tag.isSigned = FALSE;
return (Real) vec;
}
Real
vector_Z(mpz_t a, mpz_t b)
{
Vec *vec;
if ((mpz_sgn(a) == 0) && (mpz_sgn(b) == 0))
Error(FATAL, E_INT, "vector_Z", "zero column vector");
vec = allocVec();
mpz_init_set(vec->vec[0], a);
mpz_init_set(vec->vec[1], b);
canonVector(vec->vec);
if (vectorSign(vec->vec) == 0)
vec->tag.isSigned = TRUE;
else
vec->tag.isSigned = FALSE;
return (Real) vec;
}
|