Re: unary plus - Mailing list pgsql-patches

From Marko Kreen
Subject Re: unary plus
Date
Msg-id 20010601235816.C29129@l-t.ee
Whole thread Raw
In response to Re: unary plus  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: unary plus
Re: unary plus
List pgsql-patches
On Fri, Jun 01, 2001 at 05:09:26PM -0400, Tom Lane wrote:
> Marko Kreen <marko@l-t.ee> writes:
> > This is unary plus.  One time somebody complained about it,
> > then some time later thought about it and implemented it.
>
> I'd vote against the gram.y part of this change (doUnaryPlus),
> but the rest looks OK.

Ok, I ripped that part out.

--
marko


Index: src/backend/utils/adt/float.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/adt/float.c,v
retrieving revision 1.71
diff -c -r1.71 float.c
*** src/backend/utils/adt/float.c    2001/05/03 19:00:36    1.71
--- src/backend/utils/adt/float.c    2001/06/01 19:30:47
***************
*** 15,23 ****
  /*----------
   * OLD COMMENTS
   *        Basic float4 ops:
!  *         float4in, float4out, float4abs, float4um
   *        Basic float8 ops:
!  *         float8in, float8out, float8abs, float8um
   *        Arithmetic operators:
   *         float4pl, float4mi, float4mul, float4div
   *         float8pl, float8mi, float8mul, float8div
--- 15,23 ----
  /*----------
   * OLD COMMENTS
   *        Basic float4 ops:
!  *         float4in, float4out, float4abs, float4um, float4up
   *        Basic float8 ops:
!  *         float8in, float8out, float8abs, float8um, float8up
   *        Arithmetic operators:
   *         float4pl, float4mi, float4mul, float4div
   *         float8pl, float8mi, float8mul, float8div
***************
*** 324,329 ****
--- 324,336 ----
  }

  Datum
+ float4up(PG_FUNCTION_ARGS)
+ {
+     float4        arg = PG_GETARG_FLOAT4(0);
+     PG_RETURN_FLOAT4(arg);
+ }
+
+ Datum
  float4larger(PG_FUNCTION_ARGS)
  {
      float4        arg1 = PG_GETARG_FLOAT4(0);
***************
*** 380,385 ****
--- 387,399 ----

      CheckFloat8Val(result);
      PG_RETURN_FLOAT8(result);
+ }
+
+ Datum
+ float8up(PG_FUNCTION_ARGS)
+ {
+     float8        arg = PG_GETARG_FLOAT8(0);
+     PG_RETURN_FLOAT8(arg);
  }

  Datum
Index: src/backend/utils/adt/int.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/adt/int.c,v
retrieving revision 1.46
diff -c -r1.46 int.c
*** src/backend/utils/adt/int.c    2001/03/22 03:59:51    1.46
--- src/backend/utils/adt/int.c    2001/06/01 19:30:47
***************
*** 564,569 ****
--- 564,577 ----
  }

  Datum
+ int4up(PG_FUNCTION_ARGS)
+ {
+     int32        arg = PG_GETARG_INT32(0);
+
+     PG_RETURN_INT32(arg);
+ }
+
+ Datum
  int4pl(PG_FUNCTION_ARGS)
  {
      int32        arg1 = PG_GETARG_INT32(0);
***************
*** 613,618 ****
--- 621,634 ----
      int16        arg = PG_GETARG_INT16(0);

      PG_RETURN_INT16(-arg);
+ }
+
+ Datum
+ int2up(PG_FUNCTION_ARGS)
+ {
+     int16        arg = PG_GETARG_INT16(0);
+
+     PG_RETURN_INT16(arg);
  }

  Datum
Index: src/backend/utils/adt/int8.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/adt/int8.c,v
retrieving revision 1.29
diff -c -r1.29 int8.c
*** src/backend/utils/adt/int8.c    2001/03/22 03:59:51    1.29
--- src/backend/utils/adt/int8.c    2001/06/01 19:30:48
***************
*** 413,418 ****
--- 413,426 ----
  }

  Datum
+ int8up(PG_FUNCTION_ARGS)
+ {
+     int64        val = PG_GETARG_INT64(0);
+
+     PG_RETURN_INT64(val);
+ }
+
+ Datum
  int8pl(PG_FUNCTION_ARGS)
  {
      int64        val1 = PG_GETARG_INT64(0);
Index: src/backend/utils/adt/numeric.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/adt/numeric.c,v
retrieving revision 1.41
diff -c -r1.41 numeric.c
*** src/backend/utils/adt/numeric.c    2001/05/03 19:00:36    1.41
--- src/backend/utils/adt/numeric.c    2001/06/01 19:30:53
***************
*** 406,411 ****
--- 406,424 ----


  Datum
+ numeric_uplus(PG_FUNCTION_ARGS)
+ {
+     Numeric        num = PG_GETARG_NUMERIC(0);
+     Numeric        res;
+
+     res = (Numeric) palloc(num->varlen);
+     memcpy(res, num, num->varlen);
+
+     PG_RETURN_NUMERIC(res);
+ }
+
+
+ Datum
  numeric_sign(PG_FUNCTION_ARGS)
  {
      Numeric        num = PG_GETARG_NUMERIC(0);
Index: src/include/catalog/pg_operator.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/catalog/pg_operator.h,v
retrieving revision 1.88
diff -c -r1.88 pg_operator.h
*** src/include/catalog/pg_operator.h    2001/03/22 04:00:39    1.88
--- src/include/catalog/pg_operator.h    2001/06/01 19:30:57
***************
*** 794,799 ****
--- 794,806 ----
  DATA(insert OID = 1890 ( "<<"       PGUID 0 b t f  20  23  20     0      0   0  0 int8shl - - ));
  DATA(insert OID = 1891 ( ">>"       PGUID 0 b t f  20  23  20     0      0   0  0 int8shr - - ));

+ DATA(insert OID = 1916 (  "+"       PGUID 0 l t f   0  20  20    0   0   0   0 int8up - - ));
+ DATA(insert OID = 1917 (  "+"       PGUID 0 l t f   0  21  21    0   0   0   0 int2up - - ));
+ DATA(insert OID = 1918 (  "+"       PGUID 0 l t f   0  23  23    0   0   0   0 int4up - - ));
+ DATA(insert OID = 1919 (  "+"       PGUID 0 l t f   0  700 700    0   0   0   0 float4up - - ));
+ DATA(insert OID = 1920 (  "+"       PGUID 0 l t f   0  701 701    0   0   0   0 float8up - - ));
+ DATA(insert OID = 1921 (  "+"       PGUID 0 l t f   0 1700 1700  0   0    0    0 numeric_uplus - - ));
+
  /*
   * function prototypes
   */
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.188
diff -c -r1.188 pg_proc.h
*** src/include/catalog/pg_proc.h    2001/05/24 09:29:29    1.188
--- src/include/catalog/pg_proc.h    2001/06/01 19:31:05
***************
*** 2614,2619 ****
--- 2614,2632 ----
  DATA(insert OID = 1909 (  int8shr           PGUID 12 f t t t 2 f 20 "20 23" 100 0 0 100    int8shr - ));
  DESCR("binary shift right");

+ DATA(insert OID = 1910 (  int8up           PGUID 12 f t t t 1 f 20  "20"   100 0 0 100  int8up - ));
+ DESCR("unary plus");
+ DATA(insert OID = 1911 (  int2up           PGUID 12 f t t t 1 f 21  "21"   100 0 0 100  int2up - ));
+ DESCR("unary plus");
+ DATA(insert OID = 1912 (  int4up           PGUID 12 f t t t 1 f 23  "23"   100 0 0 100  int4up - ));
+ DESCR("unary plus");
+ DATA(insert OID = 1913 (  float4up           PGUID 12 f t t t 1 f 700 "700"  100 0 0 100  float4up - ));
+ DESCR("unary plus");
+ DATA(insert OID = 1914 (  float8up           PGUID 12 f t t t 1 f 701 "701"  100 0 0 100  float8up - ));
+ DESCR("unary plus");
+ DATA(insert OID = 1915 (  numeric_uplus       PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100  numeric_uplus - ));
+ DESCR("unary plus");
+
  /*
   * prototypes for functions pg_proc.c
   */
Index: src/include/utils/builtins.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/builtins.h,v
retrieving revision 1.148
diff -c -r1.148 builtins.h
*** src/include/utils/builtins.h    2001/03/22 04:01:11    1.148
--- src/include/utils/builtins.h    2001/06/01 19:31:06
***************
*** 96,101 ****
--- 96,102 ----
  extern Datum int42gt(PG_FUNCTION_ARGS);
  extern Datum int42ge(PG_FUNCTION_ARGS);
  extern Datum int4um(PG_FUNCTION_ARGS);
+ extern Datum int4up(PG_FUNCTION_ARGS);
  extern Datum int4pl(PG_FUNCTION_ARGS);
  extern Datum int4mi(PG_FUNCTION_ARGS);
  extern Datum int4mul(PG_FUNCTION_ARGS);
***************
*** 103,108 ****
--- 104,110 ----
  extern Datum int4abs(PG_FUNCTION_ARGS);
  extern Datum int4inc(PG_FUNCTION_ARGS);
  extern Datum int2um(PG_FUNCTION_ARGS);
+ extern Datum int2up(PG_FUNCTION_ARGS);
  extern Datum int2pl(PG_FUNCTION_ARGS);
  extern Datum int2mi(PG_FUNCTION_ARGS);
  extern Datum int2mul(PG_FUNCTION_ARGS);
***************
*** 184,193 ****
--- 186,197 ----
  extern Datum float8out(PG_FUNCTION_ARGS);
  extern Datum float4abs(PG_FUNCTION_ARGS);
  extern Datum float4um(PG_FUNCTION_ARGS);
+ extern Datum float4up(PG_FUNCTION_ARGS);
  extern Datum float4larger(PG_FUNCTION_ARGS);
  extern Datum float4smaller(PG_FUNCTION_ARGS);
  extern Datum float8abs(PG_FUNCTION_ARGS);
  extern Datum float8um(PG_FUNCTION_ARGS);
+ extern Datum float8up(PG_FUNCTION_ARGS);
  extern Datum float8larger(PG_FUNCTION_ARGS);
  extern Datum float8smaller(PG_FUNCTION_ARGS);
  extern Datum float4pl(PG_FUNCTION_ARGS);
***************
*** 532,537 ****
--- 536,542 ----
  extern Datum numeric(PG_FUNCTION_ARGS);
  extern Datum numeric_abs(PG_FUNCTION_ARGS);
  extern Datum numeric_uminus(PG_FUNCTION_ARGS);
+ extern Datum numeric_uplus(PG_FUNCTION_ARGS);
  extern Datum numeric_sign(PG_FUNCTION_ARGS);
  extern Datum numeric_round(PG_FUNCTION_ARGS);
  extern Datum numeric_trunc(PG_FUNCTION_ARGS);
Index: src/include/utils/int8.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/int8.h,v
retrieving revision 1.25
diff -c -r1.25 int8.h
*** src/include/utils/int8.h    2001/01/24 19:43:28    1.25
--- src/include/utils/int8.h    2001/06/01 19:31:07
***************
*** 66,71 ****
--- 66,72 ----
  extern Datum int28ge(PG_FUNCTION_ARGS);

  extern Datum int8um(PG_FUNCTION_ARGS);
+ extern Datum int8up(PG_FUNCTION_ARGS);
  extern Datum int8pl(PG_FUNCTION_ARGS);
  extern Datum int8mi(PG_FUNCTION_ARGS);
  extern Datum int8mul(PG_FUNCTION_ARGS);

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: show all;
Next
From: Tom Lane
Date:
Subject: Re: show all;