Skip to content
This repository
Browse code

TMP commit for op family

  • Loading branch information...
commit 9462bdc13fdf5ce228717fb595f4ee8b2477ccd5 1 parent 601ff9c
Daniele Varrazzo authored
16  pgmp.pysql
@@ -254,11 +254,19 @@ CREATE OPERATOR ^ (
254 254
 
255 255
 !! PYON
256 256
 
257  
-def bop(sym, fname, comm=None, neg=None,
  257
+def bop(sym, fname, larg=None, rarg=None, comm=None, neg=None,
258 258
         selectivity=None, hashes=False, merges=False):
259 259
     """Create an operator on `base_type` returning a bool"""
260  
-    func('%s_%s' % (base_type, fname), 
261  
-        base_type + " " + base_type, argout='boolean')
  260
+    _fname, fname = fname, None
  261
+    if larg is None and rarg is None:
  262
+        fname = '%s_%s' % (base_type, _fname)
  263
+
  264
+    if larg is None: larg = base_type
  265
+    if rarg is None: rarg = base_type
  266
+    if fname is None:
  267
+        fname = '%s_%s_%s' % (larg, rarg, _fname)
  268
+
  269
+    func(fname, larg + " " + rarg, argout='boolean')
262 270
 
263 271
     comm_map = {'=': '=', '<>': '<>', '>': '<', '>=': '<=', '<': '>', '<=': '>='}
264 272
     if not comm: comm = comm_map.get(sym)
@@ -276,7 +284,7 @@ def bop(sym, fname, comm=None, neg=None,
276 284
     print "CREATE OPERATOR %s (" % sym
277 285
     print "    LEFTARG =", base_type
278 286
     print "    , RIGHTARG =", base_type
279  
-    print "    , PROCEDURE = %s_%s" % (base_type, fname)
  287
+    print "    , PROCEDURE = %s" % fname
280 288
     if comm:
281 289
         print "    , COMMUTATOR = %s" % comm
282 290
     if neg:
44  src/pmpq_arith.c
@@ -145,11 +145,11 @@ PGMP_PG_FUNCTION(pmpq_ ## op) \
145 145
     PGMP_GETARG_MPQ(q1, 0); \
146 146
     PGMP_GETARG_MPQ(q2, 1); \
147 147
  \
148  
-    PG_RETURN_BOOL(mpq_equal(q1, q2) rel 0); \
  148
+    PG_RETURN_BOOL(!(mpq_equal(q1, q2) rel 0)); \
149 149
 }
150 150
 
151  
-PMPQ_CMP_EQ(eq, !=)     /* note that the operators are reversed */
152  
-PMPQ_CMP_EQ(ne, ==)
  151
+PMPQ_CMP_EQ(eq, ==)
  152
+PMPQ_CMP_EQ(ne, !=)
153 153
 
154 154
 
155 155
 #define PMPQ_CMP(op, rel) \
@@ -171,6 +171,44 @@ PMPQ_CMP(lt, <)
171 171
 PMPQ_CMP(le, <=)
172 172
 
173 173
 
  174
+/* mpq-mpz cross-comparison */
  175
+
  176
+    /*
  177
+PGMP_PG_FUNCTION(pmpq_qz_cmp)
  178
+{
  179
+    const mpq_t     q1;
  180
+    const mpq_t     q2;
  181
+
  182
+    PGMP_GETARG_MPQ(q1, 0);
  183
+    PGMP_GETARG_MPZ(mpq_numref(q2), 1);
  184
+    mpz_init_set_si(mpq_denref(q2), 1L);
  185
+
  186
+    PG_RETURN_INT32(mpq_cmp(q1, q2));
  187
+}
  188
+*/
  189
+
  190
+#define PMPQ_CMP_QZ(op, rel) \
  191
+ \
  192
+PGMP_PG_FUNCTION(pmpq_qz_ ## op) \
  193
+{ \
  194
+    const mpq_t     q1; \
  195
+    const mpq_t     q2; \
  196
+ \
  197
+    PGMP_GETARG_MPQ(q1, 0); \
  198
+    PGMP_GETARG_MPZ(mpq_numref(q2), 1); \
  199
+    mpz_init_set_si(mpq_denref(q2), 1L); \
  200
+ \
  201
+    PG_RETURN_BOOL(mpq_cmp(q1, q2) rel 0); \
  202
+}
  203
+
  204
+// PMPQ_CMP_QZ(eq, ==)        /* TODO: implement eq/ne w/ mpq_equal */
  205
+// PMPQ_CMP_QZ(ne, !=)
  206
+// PMPQ_CMP_QZ(gt, >)
  207
+// PMPQ_CMP_QZ(ge, >=)
  208
+// PMPQ_CMP_QZ(lt, <)
  209
+// PMPQ_CMP_QZ(le, <=)
  210
+
  211
+
174 212
 PGMP_PG_FUNCTION(pmpq_hash)
175 213
 {
176 214
     const mpq_t     q;

0 notes on commit 9462bdc

Please sign in to comment.
Something went wrong with that request. Please try again.