Changeset: 1d5b084bb2c6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1d5b084bb2c6
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk_calc.c
monetdb5/modules/kernel/batcalc.c
monetdb5/modules/kernel/batcalc.mal
monetdb5/modules/kernel/batcalc.mal.sh
monetdb5/modules/kernel/batmmath.mx
monetdb5/modules/kernel/calc.mal
monetdb5/modules/kernel/calc.mal.sh
monetdb5/modules/kernel/mmath.mx
sql/common/sql_types.c
Branch: Jul2012
Log Message:
Implemented floating point modulo ({bat,}calc.%) in gdk_calc.c.
diffs (truncated from 1352 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1427,8 +1427,6 @@ str CMDraise(str *ret, str *msg);
str CMDregisterFunction(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
str CMDscience_bat_cst_atan2_dbl(int *ret, int *bid, dbl *d);
str CMDscience_bat_cst_atan2_flt(int *ret, int *bid, flt *d);
-str CMDscience_bat_cst_fmod_dbl(int *ret, int *bid, dbl *d);
-str CMDscience_bat_cst_fmod_flt(int *ret, int *bid, flt *d);
str CMDscience_bat_cst_pow_dbl(int *ret, int *bid, dbl *d);
str CMDscience_bat_cst_pow_flt(int *ret, int *bid, flt *d);
str CMDscience_bat_dbl_acos(int *ret, int *bid);
@@ -1790,8 +1788,6 @@ str MANUALhelp(Client cntxt, MalBlkPtr m
str MANUALsearch(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
str MATHbinary_ATAN2dbl(dbl *res, dbl *a, dbl *b);
str MATHbinary_ATAN2flt(flt *res, flt *a, flt *b);
-str MATHbinary_FMODdbl(dbl *res, dbl *a, dbl *b);
-str MATHbinary_FMODflt(flt *res, flt *a, flt *b);
str MATHbinary_POWdbl(dbl *res, dbl *a, dbl *b);
str MATHbinary_POWflt(flt *res, flt *a, flt *b);
str MATHbinary_ROUNDdbl(dbl *res, dbl *a, int *b);
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -20,6 +20,7 @@
#include "monetdb_config.h"
#include "gdk.h"
#include "gdk_private.h"
+#include <math.h>
/* Define symbol FULL_IMPLEMENTATION to get implementations for all
* sensible output types for +, -, *, /. Without the symbol, all
@@ -5711,7 +5712,10 @@ VARcalcdiv(ValPtr ret, const ValRecord *
#define MOD_3TYPE(TYPE1, TYPE2, TYPE3) \
static BUN \
- mod_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, const
TYPE2 *rgt, int incr2, TYPE3 *dst, BUN cnt, int abort_on_error) \
+ mod_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
+ const TYPE2 *rgt, int incr2, \
+ TYPE3 *dst, BUN cnt, \
+ int abort_on_error) \
{ \
BUN i, j, k; \
BUN nils = 0; \
@@ -5732,6 +5736,33 @@ VARcalcdiv(ValPtr ret, const ValRecord *
return nils; \
}
+#define FMOD_3TYPE(TYPE1, TYPE2, TYPE3, FUNC) \
+ static BUN \
+ mod_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
+ const TYPE2 *rgt, int incr2, \
+ TYPE3 *dst, BUN cnt, \
+ int abort_on_error) \
+ { \
+ BUN i, j, k; \
+ BUN nils = 0; \
+ \
+ for (i = j = k = 0; k < cnt; i += incr1, j += incr2, k++) { \
+ if (lft[i] == TYPE1##_nil || rgt[j] == TYPE2##_nil) { \
+ dst[k] = TYPE3##_nil; \
+ nils++; \
+ } else if (rgt[j] == 0) { \
+ if (abort_on_error) \
+ return BUN_NONE; \
+ dst[k] = TYPE3##_nil; \
+ nils++; \
+ } else { \
+ dst[k] = (TYPE3) FUNC((TYPE3) lft[i], \
+ (TYPE3) rgt[j]); \
+ } \
+ } \
+ return nils; \
+ }
+
MOD_3TYPE(bte, bte, bte)
#ifdef FULL_IMPLEMENTATION
MOD_3TYPE(bte, bte, sht)
@@ -5813,6 +5844,27 @@ MOD_3TYPE(lng, int, lng)
#endif
MOD_3TYPE(lng, lng, lng)
+FMOD_3TYPE(bte, flt, flt, fmodf)
+FMOD_3TYPE(sht, flt, flt, fmodf)
+FMOD_3TYPE(int, flt, flt, fmodf)
+FMOD_3TYPE(lng, flt, flt, fmodf)
+FMOD_3TYPE(flt, bte, flt, fmodf)
+FMOD_3TYPE(flt, sht, flt, fmodf)
+FMOD_3TYPE(flt, int, flt, fmodf)
+FMOD_3TYPE(flt, lng, flt, fmodf)
+FMOD_3TYPE(flt, flt, flt, fmodf)
+FMOD_3TYPE(bte, dbl, dbl, fmod)
+FMOD_3TYPE(sht, dbl, dbl, fmod)
+FMOD_3TYPE(int, dbl, dbl, fmod)
+FMOD_3TYPE(lng, dbl, dbl, fmod)
+FMOD_3TYPE(flt, dbl, dbl, fmod)
+FMOD_3TYPE(dbl, bte, dbl, fmod)
+FMOD_3TYPE(dbl, sht, dbl, fmod)
+FMOD_3TYPE(dbl, int, dbl, fmod)
+FMOD_3TYPE(dbl, lng, dbl, fmod)
+FMOD_3TYPE(dbl, flt, dbl, fmod)
+FMOD_3TYPE(dbl, dbl, dbl, fmod)
+
static BUN
mod_typeswitchloop(const void *lft, int tp1, int incr1,
const void *rgt, int tp2, int incr2,
@@ -5936,6 +5988,28 @@ mod_typeswitchloop(const void *lft, int
goto unsupported;
}
break;
+ case TYPE_flt:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_bte_flt_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_dbl:
+ switch (ATOMstorage(tp)) {
+ case TYPE_dbl:
+ nils = mod_bte_dbl_dbl(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
default:
goto unsupported;
}
@@ -6039,6 +6113,28 @@ mod_typeswitchloop(const void *lft, int
goto unsupported;
}
break;
+ case TYPE_flt:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_sht_flt_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_dbl:
+ switch (ATOMstorage(tp)) {
+ case TYPE_dbl:
+ nils = mod_sht_dbl_dbl(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
default:
goto unsupported;
}
@@ -6132,6 +6228,28 @@ mod_typeswitchloop(const void *lft, int
goto unsupported;
}
break;
+ case TYPE_flt:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_int_flt_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_dbl:
+ switch (ATOMstorage(tp)) {
+ case TYPE_dbl:
+ nils = mod_int_dbl_dbl(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
default:
goto unsupported;
}
@@ -6218,6 +6336,172 @@ mod_typeswitchloop(const void *lft, int
goto unsupported;
}
break;
+ case TYPE_flt:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_lng_flt_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_dbl:
+ switch (ATOMstorage(tp)) {
+ case TYPE_dbl:
+ nils = mod_lng_dbl_dbl(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_flt:
+ switch (ATOMstorage(tp2)) {
+ case TYPE_bte:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_flt_bte_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_sht:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_flt_sht_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_int:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_flt_int_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_lng:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_flt_lng_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_flt:
+ switch (ATOMstorage(tp)) {
+ case TYPE_flt:
+ nils = mod_flt_flt_flt(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_dbl:
+ switch (ATOMstorage(tp)) {
+ case TYPE_dbl:
+ nils = mod_flt_dbl_dbl(lft, incr1, rgt, incr2,
+ dst, cnt,
+ abort_on_error);
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ default:
+ goto unsupported;
+ }
+ break;
+ case TYPE_dbl:
+ switch (ATOMstorage(tp2)) {
+ case TYPE_bte:
+ switch (ATOMstorage(tp)) {
+ case TYPE_dbl:
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list