[INTERPRETER]
* BUG: Fix Abs() when that operator is implemented at class level, so that it returns an object and not necesarrily a floating point value. [GB.GMP] * NEW: New component based on the Gnu Multiple Precision Arithmetic Library. Only big integers (BigInt class) are partially implemented at the moment. git-svn-id: svn://localhost/gambas/trunk@5826 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
902c13bcea
commit
4d71384869
11 changed files with 75 additions and 8 deletions
|
@ -28,6 +28,7 @@ SUBDIRS = \
|
|||
@imageimlib_dir@ \
|
||||
@dbus_dir@ \
|
||||
@gsl_dir@ \
|
||||
@gmp_dir@ \
|
||||
@ncurses_dir@ \
|
||||
@media_dir@ \
|
||||
@jit_dir@ \
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -27,9 +27,12 @@
|
|||
#define __MAIN_H
|
||||
|
||||
#include "gambas.h"
|
||||
#include "gb_common.h"
|
||||
#include <gmp.h>
|
||||
|
||||
#ifndef __MAIN_C
|
||||
extern GB_INTERFACE GB;
|
||||
extern GB_CLASS CLASS_BigInt;
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 /* */
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -764,7 +764,7 @@ __FLOAT:
|
|||
|
||||
__OBJECT:
|
||||
|
||||
EXEC_operator_object_abs(P1);
|
||||
EXEC_operator_object_single(CO_ABS, P1);
|
||||
return;
|
||||
|
||||
__VARIANT:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue