diff --git a/Makefile.am b/Makefile.am index a1d83697b..fe5940bc9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,7 @@ SUBDIRS = \ @imageimlib_dir@ \ @dbus_dir@ \ @gsl_dir@ \ + @gmp_dir@ \ @ncurses_dir@ \ @media_dir@ \ @jit_dir@ \ diff --git a/configure.ac b/configure.ac index 2b20acde6..f12d8ed3d 100644 --- a/configure.ac +++ b/configure.ac @@ -37,6 +37,7 @@ GB_CONFIG_SUBDIRS(imageio, gb.image.io) GB_CONFIG_SUBDIRS(imageimlib, gb.image.imlib) GB_CONFIG_SUBDIRS(dbus, gb.dbus) GB_CONFIG_SUBDIRS(gsl, gb.gsl) +GB_CONFIG_SUBDIRS(gmp, gb.gmp) GB_CONFIG_SUBDIRS(ncurses, gb.ncurses) GB_CONFIG_SUBDIRS(media, gb.media) GB_CONFIG_SUBDIRS(jit, gb.jit) diff --git a/gb.gmp/src/Makefile.am b/gb.gmp/src/Makefile.am index 39518f992..d5d311868 100644 --- a/gb.gmp/src/Makefile.am +++ b/gb.gmp/src/Makefile.am @@ -7,4 +7,6 @@ gb_gmp_la_LIBADD = @GMP_LIB@ gb_gmp_la_LDFLAGS = -module @LD_FLAGS@ @GMP_LDFLAGS@ gb_gmp_la_CPPFLAGS = @GMP_INC@ -gb_gmp_la_SOURCES = main.c main.h +gb_gmp_la_SOURCES = \ + main.c main.h \ + c_bigint.c c_bigint.h diff --git a/gb.gmp/src/main.c b/gb.gmp/src/main.c index 8b6f900aa..2c539793a 100644 --- a/gb.gmp/src/main.c +++ b/gb.gmp/src/main.c @@ -26,3 +26,55 @@ #define __MAIN_C #include "main.h" + +#include "c_bigint.h" + +GB_INTERFACE GB EXPORT; + +GB_DESC *GB_CLASSES[] EXPORT = +{ + BigIntDesc, + NULL // Must have a null entry for the end of the structure +}; + +GB_CLASS CLASS_BigInt; + +/*static void error_handler(const char *reason, const char *file, int line, int gsl_errno) +{ + //fprintf(stderr, "gb.gsl: error: %s: %s\n", gsl_strerror(gsl_errno), reason); + GB.Error("&1: &2", gsl_strerror(gsl_errno), reason); +}*/ + +static void *my_malloc(size_t n) +{ + void *p; + GB.Alloc(&p, n); + return p; +} + +static void my_free(void *p, size_t n) +{ + GB.Free(&p); +} + +static void *my_realloc(void *p, size_t old, size_t n) +{ + GB.Realloc(&p, n); + return p; +} + +int EXPORT GB_INIT(void) +{ + CLASS_BigInt = GB.FindClass("BigInt"); + + mp_set_memory_functions(my_malloc, my_realloc, my_free); + + //gsl_set_error_handler(error_handler); + + return 0; +} + +void EXPORT GB_EXIT() +{ + +} diff --git a/gb.gmp/src/main.h b/gb.gmp/src/main.h index 40b8f2bfc..76413660c 100644 --- a/gb.gmp/src/main.h +++ b/gb.gmp/src/main.h @@ -27,9 +27,12 @@ #define __MAIN_H #include "gambas.h" +#include "gb_common.h" +#include #ifndef __MAIN_C extern GB_INTERFACE GB; +extern GB_CLASS CLASS_BigInt; #endif #endif /* __MAIN_H */ diff --git a/gb.gsl/src/c_complex.c b/gb.gsl/src/c_complex.c index 72f2391d2..6992bc96f 100644 --- a/gb.gsl/src/c_complex.c +++ b/gb.gsl/src/c_complex.c @@ -172,9 +172,14 @@ static CCOMPLEX *_neg(CCOMPLEX *a) return COMPLEX_create(gsl_complex_negative(a->number)); } -static double _abs(CCOMPLEX *a) +static CCOMPLEX *_abs(CCOMPLEX *a) { - return gsl_complex_abs(a->number); + gsl_complex n; + + n.dat[0] = gsl_complex_abs(a->number); + n.dat[1] = 0; + + return COMPLEX_create(n); } /*static CCOMPLEX *_powi(CCOMPLEX *a, int i) diff --git a/main/gbx/gbx_exec.h b/main/gbx/gbx_exec.h index 0963e344d..bc08e1d89 100644 --- a/main/gbx/gbx_exec.h +++ b/main/gbx/gbx_exec.h @@ -312,7 +312,7 @@ int EXEC_check_operator(VALUE *P1, VALUE *P2, uchar op); void EXEC_operator(uchar what, uchar op, VALUE *P1, VALUE *P2); void EXEC_operator_object_add_quick(VALUE *P1, double val); bool EXEC_comparator(uchar what, uchar op, VALUE *P1, VALUE *P2); -void EXEC_operator_object_abs(VALUE *P1); +//void EXEC_operator_object_abs(VALUE *P1); void EXEC_operator_object_single(uchar op, VALUE *P1); #endif /* */ diff --git a/main/gbx/gbx_exec_operator.c b/main/gbx/gbx_exec_operator.c index a0b0bc8ad..a904bccb0 100644 --- a/main/gbx/gbx_exec_operator.c +++ b/main/gbx/gbx_exec_operator.c @@ -304,6 +304,7 @@ __END: return result; } +#if 0 void EXEC_operator_object_abs(VALUE *P1) { if (P1->_object.object) @@ -323,6 +324,7 @@ void EXEC_operator_object_abs(VALUE *P1) PROPAGATE(); } } +#endif void EXEC_operator_object_single(uchar op, VALUE *P1) { diff --git a/main/gbx/gbx_subr_math.c b/main/gbx/gbx_subr_math.c index d71e0ed58..4feb4b3b8 100644 --- a/main/gbx/gbx_subr_math.c +++ b/main/gbx/gbx_subr_math.c @@ -764,7 +764,7 @@ __FLOAT: __OBJECT: - EXEC_operator_object_abs(P1); + EXEC_operator_object_single(CO_ABS, P1); return; __VARIANT: diff --git a/main/lib/complex/ccomplex.c b/main/lib/complex/ccomplex.c index 084b3f621..0f5873a2b 100644 --- a/main/lib/complex/ccomplex.c +++ b/main/lib/complex/ccomplex.c @@ -157,9 +157,9 @@ static int _equalf(CCOMPLEX *a, double f, bool invert) return RE(a) == f && IM(a) == 0; } -static double _abs(CCOMPLEX *a) +static CCOMPLEX *_abs(CCOMPLEX *a) { - return ABS(a); + return COMPLEX_make(a, ABS(a), 0); } static CCOMPLEX *_neg(CCOMPLEX *a) diff --git a/main/share/gambas.h b/main/share/gambas.h index 4305f9bca..d12b0e091 100644 --- a/main/share/gambas.h +++ b/main/share/gambas.h @@ -311,6 +311,7 @@ typedef /* Predefined errors constants */ #define GB_ERR_TYPE ((char *)6) +#define GB_ERR_OVERFLOW ((char *)7) #define GB_ERR_NSYMBOL ((char *)11) #define GB_ERR_NPROPERTY ((char *)17) #define GB_ERR_ARG ((char *)20) @@ -852,7 +853,7 @@ typedef void *(*powf)(void *, double, bool); void *(*powo)(void *, void *, bool); void *(*neg)(void *); - double (*abs)(void *); + void *(*abs)(void *); intptr_t _reserved; } PACKED