Changeset: 779b1a427c0e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/779b1a427c0e
Modified Files:
        monetdb5/modules/kernel/batmmath.c
        monetdb5/modules/kernel/mmath.c
        monetdb5/modules/kernel/mmath_private.h
        monetdb_config.h.in
        sql/test/SQLancer/Tests/sqlancer13.test
Branch: default
Log Message:

float vs double cleanup. Use C99 float version for floats, thus avoiding 
upcasts to doubles. As we are C99 compliant now, we don't need to check for 
cbrt function


diffs (257 lines):

diff --git a/monetdb5/modules/kernel/batmmath.c 
b/monetdb5/modules/kernel/batmmath.c
--- a/monetdb5/modules/kernel/batmmath.c
+++ b/monetdb5/modules/kernel/batmmath.c
@@ -367,54 +367,6 @@ CMDscience_bat_##FUNC(Client cntxt, MalB
        return CMDscienceBINARY(stk, pci, FUNC##f, FUNC, "batmmath." #FUNC); \
 }
 
-#define scienceNotImpl(FUNC)                                                   
                                \
-static str                                                                     
                                                        \
-CMDscience_bat_##FUNC(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) 
\
-{                                                                              
                                                                \
-       (void) cntxt;                                                           
                                                \
-       (void) mb;                                                              
                                                        \
-       (void) stk;                                                             
                                                        \
-       (void) pci;                                                             
                                                        \
-                                                                               
                                                                \
-       throw(MAL, "batmmath." #FUNC, SQLSTATE(0A000) PROGRAM_NYI);             
        \
-}
-
-static double
-cot(double x)
-{
-       return 1 / tan(x);
-}
-
-static float
-cotf(float x)
-{
-       return (float) (1 / tan(x));
-}
-
-static double
-radians(double x)
-{
-       return x * (M_PI / 180.0);
-}
-
-static float
-radiansf(float x)
-{
-       return (float) (x * (M_PI / 180.0));
-}
-
-static double
-degrees(double x)
-{
-       return x * (180.0 / M_PI);
-}
-
-static float
-degreesf(float x)
-{
-       return (float) (x * (180.0 / M_PI));
-}
-
 static str
 CMDscience_bat_randintarg(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
@@ -486,11 +438,7 @@ scienceImpl(log)
 scienceImpl(log10)
 scienceImpl(log2)
 scienceImpl(sqrt)
-#ifdef HAVE_CBRT
 scienceImpl(cbrt)
-#else
-scienceNotImpl(cbrt)
-#endif
 scienceImpl(ceil)
 scienceImpl(fabs)
 scienceImpl(floor)
diff --git a/monetdb5/modules/kernel/mmath.c b/monetdb5/modules/kernel/mmath.c
--- a/monetdb5/modules/kernel/mmath.c
+++ b/monetdb5/modules/kernel/mmath.c
@@ -23,9 +23,41 @@
 #include <fenv.h>
 #include "mmath_private.h"
 
-#define cot(x)                         (1 / tan(x))
-#define radians(x)                     ((x) * (M_PI / 180.0))
-#define degrees(x)                     ((x) * (180.0 / M_PI))
+double
+cot(double x)
+{
+       return 1.0 / tan(x);
+}
+
+float
+cotf(float x)
+{
+       return 1.0f / tanf(x);
+}
+
+double
+radians(double x)
+{
+       return x * (M_PI / 180.0);
+}
+
+float
+radiansf(float x)
+{
+       return x * (M_PIF / 180.0f);
+}
+
+double
+degrees(double x)
+{
+       return x * (180.0 / M_PI);
+}
+
+float
+degreesf(float x)
+{
+       return x * (180.0f / M_PIF);
+}
 
 double
 logbs(double base, double x)
@@ -54,7 +86,7 @@ MATHunary##NAME##TYPE(TYPE *res , const 
        if (is_##TYPE##_nil(*a)) {                                              
                                \
                *res = TYPE##_nil;                                              
                                        \
        } else {                                                                
                                                \
-               double a1 = *a, r;                                              
                                        \
+               TYPE a1 = *a, r;                                                
                                        \
                int e = 0, ex = 0;                                              
                                        \
                errno = 0;                                                      
                                                \
                feclearexcept(FE_ALL_EXCEPT);                                   
                        \
@@ -73,14 +105,14 @@ MATHunary##NAME##TYPE(TYPE *res , const 
                                err = "Invalid result";                         
                                \
                        throw(MAL, "mmath." #FUNC, "Math exception: %s", err);  
\
                }                                                               
                                                        \
-               *res = (TYPE) r;                                                
                                        \
+               *res = r;                                                       
                                                \
        }                                                                       
                                                        \
        return MAL_SUCCEED;                                                     
                                        \
 }
 
 #define unopM5(NAME, FUNC)                                             \
        unopbaseM5(NAME, FUNC, dbl)                                     \
-       unopbaseM5(NAME, FUNC, flt)
+       unopbaseM5(NAME, FUNC##f, flt)
 
 #define binopbaseM5(NAME, FUNC, TYPE)                                          
                \
 static str                                                                     
                                                \
@@ -89,7 +121,7 @@ MATHbinary##NAME##TYPE(TYPE *res, const 
        if (is_##TYPE##_nil(*a) || is_##TYPE##_nil(*b)) {                       
        \
                *res = TYPE##_nil;                                              
                                        \
        } else {                                                                
                                                \
-               double r1, a1 = *a, b1 = *b;                                    
                        \
+               TYPE r1, a1 = *a, b1 = *b;                                      
                                \
                int e = 0, ex = 0;                                              
                                        \
                errno = 0;                                                      
                                                \
                feclearexcept(FE_ALL_EXCEPT);                                   
                        \
@@ -108,30 +140,14 @@ MATHbinary##NAME##TYPE(TYPE *res, const 
                                err = "Invalid result";                         
                                \
                        throw(MAL, "mmath." #FUNC, "Math exception: %s", err);  
\
                }                                                               
                                                        \
-               *res= (TYPE) r1;                                                
                                        \
+               *res = r1;                                                      
                                                \
        }                                                                       
                                                        \
        return MAL_SUCCEED;                                                     
                                        \
 }
 
-#define unopM5NOT(NAME, FUNC)                                                  
                \
-static str                                                                     
                                        \
-MATHunary##NAME##dbl(dbl *res , const dbl *a)                                  
\
-{                                                                              
                                                \
-       (void)res;      \
-       (void)a;        \
-       throw(MAL, "mmath." #FUNC, SQLSTATE(0A000) PROGRAM_NYI);        \
-}                                                                              
                                                \
-static str                                                                     
                                        \
-MATHunary##NAME##flt(flt *res , const flt *a)                                  
\
-{                                                                              
                                                \
-       (void)res;      \
-       (void)a;        \
-       throw(MAL, "mmath." #FUNC, SQLSTATE(0A000) PROGRAM_NYI);        \
-}
-
 #define binopM5(NAME, FUNC)                                            \
   binopbaseM5(NAME, FUNC, dbl)                                 \
-  binopbaseM5(NAME, FUNC, flt)
+  binopbaseM5(NAME, FUNC##f, flt)
 
 #define roundM5(TYPE)                                                          
                        \
 static str                                                                     
                                        \
@@ -178,14 +194,7 @@ unopM5(_LOG,log)
 unopM5(_LOG10,log10)
 unopM5(_LOG2,log2)
 unopM5(_SQRT,sqrt)
-
-
-#ifdef HAVE_CBRT
 unopM5(_CBRT,cbrt)
-#else
-unopM5NOT(_CBRT,cbrt)
-#endif
-
 unopM5(_CEIL,ceil)
 unopM5(_FLOOR,floor)
 
diff --git a/monetdb5/modules/kernel/mmath_private.h 
b/monetdb5/modules/kernel/mmath_private.h
--- a/monetdb5/modules/kernel/mmath_private.h
+++ b/monetdb5/modules/kernel/mmath_private.h
@@ -16,6 +16,18 @@ extern random_state_engine mmath_rse
 extern MT_Lock mmath_rse_lock
 __attribute__((__visibility__("hidden")));
 
+/* cotangent value */
+extern double cot(double);
+extern float cotf(float);
+
+/* degress to radians conversion */
+extern double radians(double);
+extern float radiansf(float);
+
+/* radians to degress conversion */
+extern double degrees(double);
+extern float degreesf(float);
+
 /* return the logarigthm of the first argument with the second
  * argument as base */
 extern double logbs(double, double);
@@ -34,3 +46,6 @@ extern float logbsf(float, float);
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
+#ifndef M_PIF
+#define M_PIF 3.14159265358979323846f
+#endif
diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -168,7 +168,6 @@
 
 #define ICONV_CONST
 #define FLEXIBLE_ARRAY_MEMBER
-#define HAVE_CBRT 1
 #define ENABLE_MAPI 1
 #define HAVE_MAPI 1
 // End Section: monetdb configure defines
diff --git a/sql/test/SQLancer/Tests/sqlancer13.test 
b/sql/test/SQLancer/Tests/sqlancer13.test
--- a/sql/test/SQLancer/Tests/sqlancer13.test
+++ b/sql/test/SQLancer/Tests/sqlancer13.test
@@ -335,10 +335,10 @@ START TRANSACTION
 statement ok
 CREATE TABLE "sys"."t0" ("c4" DOUBLE NOT NULL)
 
-statement ok
+statement error
 insert into t0(c4) values(power(1770290607, case when greatest(false, true) 
then cast(5 as real) end)), (-1.722544153E9)
 
-statement ok
+statement error
 INSERT INTO t0(c4) VALUES(power(1770290607, CASE WHEN (UUID 
'aE792C3f-21e0-323f-1C8A-DfBD3aB655CF') IN (UUID 
'b30E22a2-3d7A-1003-BEB6-F9dE845bEAd1',
 UUID '6E391a40-3Fc6-F594-036D-737eCaDC937c') THEN CAST(r'jV㋕<2H' AS REAL) WHEN 
greatest(FALSE, TRUE) THEN CAST(5 AS REAL) WHEN NOT (TRUE)
 THEN + (3) WHEN NOT (TRUE) THEN least(5, 0.5809714) WHEN NOT (TRUE) THEN 
((0.022229422)*(1666367947)) END)), (-1.722544153E9)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to