commit 802ce6d81a34db455610b4dcd7e6868d21da6fcc
parent 3c00244d3d0cfa36ad4e6e4f7f6ddb420e905892
Author: Andres Navarro <canavarro82@gmail.com>
Date: Sat, 23 Apr 2011 10:16:43 -0300
Adapted copyright notice to klisp. Added object definition in kobject.h. Started modifying imrat.h.
Diffstat:
4 files changed, 56 insertions(+), 58 deletions(-)
diff --git a/src/imath.h b/src/imath.h
@@ -57,7 +57,9 @@ typedef unsigned int mp_word;
#endif /* USE_C99 */
/* Andres Navarro: Use kobject type instead */
-/*
+typedef Bigint mpz_t, *mp_int;
+
+#if 0
typedef struct mpz {
mp_digit single;
mp_digit *digits;
@@ -65,8 +67,7 @@ typedef struct mpz {
mp_size used;
mp_sign sign;
} mpz_t, *mp_int;
-*/
-typedef Bigint mpz_t, *mp_int;
+#endif
#define MP_SINGLE(Z) ((Z)->single) /* added to correct check in mp_int_clear */
#define MP_DIGITS(Z) ((Z)->digits)
diff --git a/src/imrat.c b/src/imrat.c
@@ -1,31 +1,15 @@
/*
- Name: imrat.c
- Purpose: Arbitrary precision rational arithmetic routines.
- Author: M. J. Fromberger <http://spinning-yarns.org/michael/>
- Info: $Id: imrat.c 635 2008-01-08 18:19:40Z sting $
-
- Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation files
- (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- */
+** imrat.c
+** Arbitrary precision rational arithmetic routines.
+** See Copyright Notice in klisp.h
+*/
+
+/*
+** SOURCE NOTE: This is mostly from the IMath library, written by
+** M.J. Fromberger. It is adapted to klisp, mainly in the use of the
+** klisp allocator and fixing of digit size to 32 bits.
+** Imported from version (1.15) updated 01-Feb-2011 at 03:10 PM.
+*/
#include "imrat.h"
#include <stdlib.h>
diff --git a/src/imrat.h b/src/imrat.h
@@ -1,45 +1,42 @@
/*
- Name: imrat.h
- Purpose: Arbitrary precision rational arithmetic routines.
- Author: M. J. Fromberger <http://spinning-yarns.org/michael/>
- Info: $Id: imrat.h 635 2008-01-08 18:19:40Z sting $
-
- Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation files
- (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- */
+** imrat.h
+** Arbitrary precision rational arithmetic routines.
+** See Copyright Notice in klisp.h
+*/
+
+/*
+** SOURCE NOTE: This is mostly from the IMath library, written by
+** M.J. Fromberger. It is adapted to klisp, mainly in the use of the
+** klisp allocator and fixing of digit size to 32 bits.
+** Imported from version (1.15) updated 01-Feb-2011 at 03:10 PM.
+*/
#ifndef IMRAT_H_
#define IMRAT_H_
#include "imath.h"
+/* Andres Navarro: klisp includes */
+#include "kobject.h"
+#include "kstate.h"
+
+#ifdef USE_C99
+#include <stdint.h>
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
+/* Andres Navarro: Use kobject type instead */
+typedef Bigrat mpq_t, *mp_rat;
+
+#if 0
typedef struct mpq {
mpz_t num; /* Numerator */
mpz_t den; /* Denominator, <> 0 */
} mpq_t, *mp_rat;
+#endif
#define MP_NUMER_P(Q) (&((Q)->num)) /* Pointer to numerator */
#define MP_DENOM_P(Q) (&((Q)->den)) /* Pointer to denominator */
diff --git a/src/kobject.h b/src/kobject.h
@@ -179,10 +179,11 @@ typedef struct __attribute__ ((__packed__)) GCheader {
**
** - decide if inexact infinities and reals with no
** primary values are included in K_TDOUBLE
-** - For now we will only use fixints, bigints and exact infinities
+** - For now we will only use fixints, bigints, bigrats and exact infinities
*/
#define K_TAG_FIXINT K_MAKE_VTAG(K_TFIXINT)
#define K_TAG_BIGINT K_MAKE_VTAG(K_TBIGINT)
+#define K_TAG_BIGRAT K_MAKE_VTAG(K_TBIGRAT)
#define K_TAG_EINF K_MAKE_VTAG(K_TEINF)
#define K_TAG_IINF K_MAKE_VTAG(K_TIINF)
@@ -232,6 +233,10 @@ typedef struct __attribute__ ((__packed__)) GCheader {
#define ttisbigint(o) (tbasetype_(o) == K_TAG_BIGINT)
#define ttisinteger(o_) ({ int32_t t_ = tbasetype_(o_); \
t_ == K_TAG_FIXINT || t_ == K_TAG_BIGINT;})
+#define ttisbigrat(o) (tbasetype_(o) == K_TAG_BIGRAT)
+#define ttisrational(o) ({ int32_t t_ = tbasetype_(o_); \
+ t_ == K_TAG_BIGRAT || t_== K_TAG_BIGINT || \
+ t == K_TAG_FIXINT;})
#define ttisnumber(o) (ttype(o) <= K_LAST_NUMBER_TYPE); })
#define ttiseinf(o) (tbasetype_(o) == K_TAG_EINF)
#define ttisiinf(o) (tbasetype_(o) == K_TAG_IINF)
@@ -314,6 +319,17 @@ typedef struct __attribute__ ((__packed__)) {
unsigned char sign;
} Bigint;
+/* NOTE: Notice that both num and den aren't pointers, so, in general, to get
+ the denominator or numerator we have to make a copy, this comes from IMath.
+ If written for klisp I would have put pointers. Maybe I'll later change it
+ but for now minimal ammount of modification to IMath is desired */
+typedef struct __attribute__ ((__packed__)) {
+ CommonHeader;
+/* This is from IMath */
+ Bigint num; /* Numerator */
+ Bigint den; /* Denominator, <> 0 */
+} Bigrat;
+
/* REFACTOR: move these macros somewhere else */
/* NOTE: The use of the intermediate KCONCAT is needed to allow
expansion of the __LINE__ macro. */