From 11da511c784eca003deb90c23570f0873954e0de Mon Sep 17 00:00:00 2001 From: Duncan Wilkie Date: Sat, 18 Nov 2023 06:11:09 -0600 Subject: Initial commit. --- ic-reals-6.3/base/Vector.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 ic-reals-6.3/base/Vector.c (limited to 'ic-reals-6.3/base/Vector.c') diff --git a/ic-reals-6.3/base/Vector.c b/ic-reals-6.3/base/Vector.c new file mode 100644 index 0000000..51cef26 --- /dev/null +++ b/ic-reals-6.3/base/Vector.c @@ -0,0 +1,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 +#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; +} -- cgit v1.2.3