Changeset: 0f420718090d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0f420718090d
Modified Files:
        gdk/gdk_calc.c
Branch: Jan2022
Log Message:

Do multiplications (including conversion to decimal) of floating point in long 
double.
This should help or even solve bug #7258.
Note, on some platforms (Windows), long double is the same size as
double, but it is still better than float which was used for
multiplication of float (SQL type REAL) values.


diffs (74 lines):

diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -6742,11 +6742,9 @@ mul_##TYPE1##_##TYPE2##_##TYPE3(const TY
 }
 
 #ifdef TRUNCATE_NUMBERS
-#define roundflt(x)    (x)
 #define rounddbl(x)    (x)
 #else
-#define roundflt(x)    roundf(x)
-#define rounddbl(x)    round(x)
+#define rounddbl(x)    roundl(x)
 #endif
 
 #define absbte(x)      abs(x)
@@ -6788,7 +6786,7 @@ mul_##TYPE1##_##TYPE2##_##TYPE3(                          
        \
                                dst[k] = TYPE3##_nil;                   \
                                nils++;                                 \
                        } else {                                        \
-                               double m = lft[i] * rgt[j];             \
+                               long double m = lft[i] * (long double) rgt[j]; \
                                dst[k] = (TYPE3) rounddbl(m);           \
                        }                                               \
                }                                                       \
@@ -6810,7 +6808,7 @@ mul_##TYPE1##_##TYPE2##_##TYPE3(                          
        \
                                dst[k] = TYPE3##_nil;                   \
                                nils++;                                 \
                        } else {                                        \
-                               double m = lft[i] * rgt[j];             \
+                               long double m = lft[i] * (long double) rgt[j]; \
                                dst[k] = (TYPE3) rounddbl(m);           \
                        }                                               \
                }                                                       \
@@ -9102,8 +9100,7 @@ div_##TYPE1##_##TYPE2##_##TYPE3(                          
        \
                                        dst[k] = TYPE3##_nil;           \
                                        nils++;                         \
                                } else {                                \
-                                       m = lft[i] / rgt[j];            \
-                                       dst[k] = (TYPE3) rounddbl(m);   \
+                                       dst[k] = (TYPE3) rounddbl(lft[i] / 
(long double) rgt[j]); \
                                }                                       \
                        }                                               \
                }                                                       \
@@ -9133,8 +9130,7 @@ div_##TYPE1##_##TYPE2##_##TYPE3(                          
        \
                                        dst[k] = TYPE3##_nil;           \
                                        nils++;                         \
                                } else {                                \
-                                       m = lft[i] / rgt[j];            \
-                                       dst[k] = (TYPE3) rounddbl(m);   \
+                                       dst[k] = (TYPE3) rounddbl(lft[i] / 
(long double) rgt[j]); \
                                }                                       \
                        }                                               \
                }                                                       \
@@ -15650,7 +15646,8 @@ convert_##TYPE1##_##TYPE2(const TYPE1 *s
                                dst[i] = TYPE2##_nil;                   \
                                nils++;                                 \
                        } else {                                        \
-                               dst[i] = (TYPE2) round##TYPE1(v * mul); \
+                               long double m = (long double) v * mul;  \
+                               dst[i] = (TYPE2) rounddbl(m);           \
                                if ((is_##TYPE2##_nil(dst[i]) ||        \
                                     (precision &&                      \
                                      (dst[i] >= prec ||                \
@@ -15673,7 +15670,8 @@ convert_##TYPE1##_##TYPE2(const TYPE1 *s
                                dst[i] = TYPE2##_nil;                   \
                                nils++;                                 \
                        } else {                                        \
-                               dst[i] = (TYPE2) round##TYPE1(v * mul); \
+                               long double m = (long double) v * mul;  \
+                               dst[i] = (TYPE2) rounddbl(m);           \
                                if ((is_##TYPE2##_nil(dst[i]) ||        \
                                     (precision &&                      \
                                      (dst[i] >= prec ||                \
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to