Changeset: cfe690cd2d4d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cfe690cd2d4d Modified Files: gdk/gdk_atoms.c gdk/gdk_atoms.h gdk/gdk_calc.c gdk/gdk_calc_private.h gdk/gdk_search.c sql/test/Tests/fsum.sql sql/test/Tests/fsum.stable.err sql/test/Tests/fsum.stable.out Branch: default Log Message:
Use the floating point NaN (not-a-number) value for the NIL representation. TODO: upgrade code. diffs (198 lines): diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c --- a/gdk/gdk_atoms.c +++ b/gdk/gdk_atoms.c @@ -251,8 +251,8 @@ ATOMisdescendant(int tpe, int parent) const bte bte_nil = GDK_bte_min-1; const sht sht_nil = GDK_sht_min-1; const int int_nil = GDK_int_min-1; -const flt flt_nil = -FLT_MAX; -const dbl dbl_nil = -DBL_MAX; +const flt flt_nil = NAN; +const dbl dbl_nil = NAN; const lng lng_nil = GDK_lng_min-1; #ifdef HAVE_HGE const hge hge_nil = GDK_hge_min-1; diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h --- a/gdk/gdk_atoms.h +++ b/gdk/gdk_atoms.h @@ -90,7 +90,7 @@ gdk_export size_t escapedStr(char *dst, #define GDK_int_max INT_MAX #define GDK_int_min (INT_MIN+1) #define GDK_flt_max ((flt) FLT_MAX) -#define GDK_flt_min (-3.4028233e+38F) /* nextafterf(-FLT_MAX,0) */ +#define GDK_flt_min ((flt) -FLT_MAX) #define GDK_lng_max ((lng) LLONG_MAX) #define GDK_lng_min ((lng) LLONG_MIN+1) #ifdef HAVE_HGE @@ -99,7 +99,7 @@ gdk_export size_t escapedStr(char *dst, #define GDK_hge_min (-GDK_hge_max) #endif #define GDK_dbl_max ((dbl) DBL_MAX) -#define GDK_dbl_min (-1.7976931348623155e+308) /* nextafter(-DBL_MAX,0) */ +#define GDK_dbl_min ((dbl) -DBL_MAX) /* GDK_oid_max see below */ #define GDK_oid_min ((oid) 0) /* representation of the nil */ @@ -136,10 +136,20 @@ gdk_export const ptr ptr_nil; #define is_hge_nil(v) ((v) == hge_nil) #endif #define is_oid_nil(v) ((v) == oid_nil) -#define is_flt_nil(v) ((v) == flt_nil) -#define is_dbl_nil(v) ((v) == dbl_nil) +#define is_flt_nil(v) isnan(v) +#define is_dbl_nil(v) isnan(v) #define is_bat_nil(v) ((v) == bat_nil || (v) == 0) +#if defined(_MSC_VER) && defined(__INTEL_COMPILER) +#include <mathimf.h> +#else +#include <math.h> +#endif + +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && _MSC_VER < 1800 +#define isnan(x) _isnan(x) +#endif + /* * @- Derived types * In all algorithms across GDK, you will find switches on the types diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c --- a/gdk/gdk_calc.c +++ b/gdk/gdk_calc.c @@ -5806,9 +5806,14 @@ mul_##TYPE1##_##TYPE2##_##TYPE3(const TY dst[k] = TYPE3##_nil; \ nils++; \ } else { \ - FLTDBLMUL_CHECK(TYPE1, lft[i], TYPE2, rgt[j], \ - TYPE3, dst[k], max, \ - ON_OVERFLOW(TYPE1, TYPE2, "*")); \ + /* only check for overflow, not for underflow */ \ + dst[k] = (TYPE3) (lft[i] * rgt[j]); \ + if (isinf(dst[k]) || ABSOLUTE(dst[k]) > max) { \ + if (abort_on_error) \ + ON_OVERFLOW(TYPE1, TYPE2, "*"); \ + dst[k] = TYPE3##_nil; \ + nils++; \ + } \ } \ } \ CANDLOOP(dst, k, TYPE3##_nil, end, cnt); \ diff --git a/gdk/gdk_calc_private.h b/gdk/gdk_calc_private.h --- a/gdk/gdk_calc_private.h +++ b/gdk/gdk_calc_private.h @@ -257,17 +257,3 @@ } while (0) #endif /* HAVE___BUILTIN_ADD_OVERFLOW */ #endif /* HAVE_HGE */ - -#define FLTDBLMUL_CHECK(TYPE1, lft, TYPE2, rgt, TYPE3, dst, max, on_overflow) \ - do { \ - /* only check for overflow, not for underflow */ \ - if (ABSOLUTE(lft) > 1 && \ - (max) / ABSOLUTE(lft) < ABSOLUTE(rgt)) { \ - if (abort_on_error) \ - on_overflow; \ - (dst) = TYPE3##_nil; \ - nils++; \ - } else { \ - (dst) = (TYPE3) (lft) * (rgt); \ - } \ - } while (0) diff --git a/gdk/gdk_search.c b/gdk/gdk_search.c --- a/gdk/gdk_search.c +++ b/gdk/gdk_search.c @@ -41,6 +41,8 @@ * return BUN_NONE, and the other functions return the location of the * next larger value, or BATcount if the value being searched for is * larger (smaller if reverse sorted) than any in the column. + * + * Note that the NIL value is considered smaller than all other values. */ #include "monetdb_config.h" diff --git a/sql/test/Tests/fsum.sql b/sql/test/Tests/fsum.sql --- a/sql/test/Tests/fsum.sql +++ b/sql/test/Tests/fsum.sql @@ -3133,12 +3133,11 @@ 0.001004016064257028 16 0.001002004008016032 16 -0.001001001001001001 16 0.001 16 -select gid, sum(val) from t where gid in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 22, 31, 33, 39, 40) group by gid order by gid; +select gid, sum(val) from t where gid in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 22, 23, 31, 33, 35, 37, 39, 40) group by gid order by gid; -- these should all produce overflow select sum(val) from t where gid = 14; select sum(val) from t where gid = 20; select sum(val) from t where gid = 21; -select sum(val) from t where gid = 23; select sum(val) from t where gid = 24; select sum(val) from t where gid = 25; select sum(val) from t where gid = 26; @@ -3148,9 +3147,7 @@ select sum(val) from t where gid = 29; select sum(val) from t where gid = 30; select sum(val) from t where gid = 32; select sum(val) from t where gid = 34; -select sum(val) from t where gid = 35; select sum(val) from t where gid = 36; -select sum(val) from t where gid = 37; select sum(val) from t where gid = 38; drop table t; diff --git a/sql/test/Tests/fsum.stable.err b/sql/test/Tests/fsum.stable.err --- a/sql/test/Tests/fsum.stable.err +++ b/sql/test/Tests/fsum.stable.err @@ -39,11 +39,7 @@ MAPI = (monetdb) /var/tmp/mtest-21571/. QUERY = select sum(val) from t where gid = 21; ERROR = !overflow in calculation. CODE = 22003 -MAPI = (monetdb) /var/tmp/mtest-21571/.s.monetdb.31912 -QUERY = select sum(val) from t where gid = 23; -ERROR = !overflow in calculation. -CODE = 22003 -MAPI = (monetdb) /var/tmp/mtest-21571/.s.monetdb.31912 +MAPI = (monetdb) /var/tmp/mtest-24476/.s.monetdb.36041 QUERY = select sum(val) from t where gid = 24; ERROR = !overflow in calculation. CODE = 22003 @@ -79,19 +75,11 @@ MAPI = (monetdb) /var/tmp/mtest-21571/. QUERY = select sum(val) from t where gid = 34; ERROR = !overflow in calculation. CODE = 22003 -MAPI = (monetdb) /var/tmp/mtest-21571/.s.monetdb.31912 -QUERY = select sum(val) from t where gid = 35; -ERROR = !overflow in calculation. -CODE = 22003 -MAPI = (monetdb) /var/tmp/mtest-21571/.s.monetdb.31912 +MAPI = (monetdb) /var/tmp/mtest-24476/.s.monetdb.36041 QUERY = select sum(val) from t where gid = 36; ERROR = !overflow in calculation. CODE = 22003 -MAPI = (monetdb) /var/tmp/mtest-21571/.s.monetdb.31912 -QUERY = select sum(val) from t where gid = 37; -ERROR = !overflow in calculation. -CODE = 22003 -MAPI = (monetdb) /var/tmp/mtest-21571/.s.monetdb.31912 +MAPI = (monetdb) /var/tmp/mtest-24476/.s.monetdb.36041 QUERY = select sum(val) from t where gid = 38; ERROR = !overflow in calculation. CODE = 22003 diff --git a/sql/test/Tests/fsum.stable.out b/sql/test/Tests/fsum.stable.out --- a/sql/test/Tests/fsum.stable.out +++ b/sql/test/Tests/fsum.stable.out @@ -70,11 +70,14 @@ Ready. [ 15, 7.485470861 ] [ 16, -0.6926474306 ] [ 17, -1 ] -[ 18, 1.797693135e+308 ] -[ 19, 1.797693135e+308 ] -[ 22, 1.797693135e+308 ] +[ 18, 0 ] +[ 19, 0 ] +[ 22, 0 ] +[ 23, -1.59538627e+308 ] [ 31, 1.797693135e+308 ] [ 33, 1.797693135e+308 ] +[ 35, -1.797693135e+308 ] +[ 37, -1.797693135e+308 ] [ 39, 1.797693135e+308 ] [ 40, 1.697693135e+308 ] #drop table t; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list