Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb0c1c53

Browse files
committed
Integer binary operators, from Marko Kreen <marko@l-t.ee>. Renamed bitxor
operator to '#' for consistency. Parser still needs work.
1 parentfa9357d commitb0c1c53

File tree

7 files changed

+297
-8
lines changed

7 files changed

+297
-8
lines changed

‎doc/src/sgml/oper.sgml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/oper.sgml,v 1.20 2000/10/04 15:47:45 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/oper.sgml,v 1.21 2000/10/24 20:13:31 petere Exp $
33
-->
44

55
<Chapter Id="operators">
@@ -493,6 +493,36 @@ logical union
493493
<ENTRY>Cube root</ENTRY>
494494
<ENTRY>||/ 27.0</ENTRY>
495495
</ROW>
496+
<ROW>
497+
<ENTRY> & </ENTRY>
498+
<ENTRY>Binary AND</ENTRY>
499+
<ENTRY>91 & 15</ENTRY>
500+
</ROW>
501+
<ROW>
502+
<ENTRY> | </ENTRY>
503+
<ENTRY>Binary OR</ENTRY>
504+
<ENTRY>32 | 3</ENTRY>
505+
</ROW>
506+
<ROW>
507+
<ENTRY> # </ENTRY>
508+
<ENTRY>Binary XOR</ENTRY>
509+
<ENTRY>15 # 4</ENTRY>
510+
</ROW>
511+
<ROW>
512+
<ENTRY> ~ </ENTRY>
513+
<ENTRY>Binary NOT</ENTRY>
514+
<ENTRY>~1</ENTRY>
515+
</ROW>
516+
<ROW>
517+
<ENTRY> &lt;&lt; </ENTRY>
518+
<ENTRY>Binary shift left</ENTRY>
519+
<ENTRY>1 &lt;&lt; 4</ENTRY>
520+
</ROW>
521+
<ROW>
522+
<ENTRY> &gt;&gt; </ENTRY>
523+
<ENTRY>Binary shift right</ENTRY>
524+
<ENTRY>8 &gt;&gt; 2</ENTRY>
525+
</ROW>
496526
</TBODY>
497527
</TGROUP>
498528
</TABLE>

‎src/backend/utils/adt/int.c

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.42 2000/08/01 18:29:35tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.43 2000/10/24 20:14:35petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -843,3 +843,121 @@ int4smaller(PG_FUNCTION_ARGS)
843843

844844
PG_RETURN_INT32((arg1<arg2) ?arg1 :arg2);
845845
}
846+
847+
/* Binary arithmetics
848+
*
849+
*int[24]and- returns arg1 & arg2
850+
*int[24]or- returns arg1 | arg2
851+
*int[24]xor- returns arg1 # arg2
852+
*int[24]not- returns ~arg1
853+
*int[24]shl- returns arg1 << arg2
854+
*int[24]shr- returns arg1 >> arg2
855+
*/
856+
857+
Datum
858+
int4and(PG_FUNCTION_ARGS)
859+
{
860+
int32arg1=PG_GETARG_INT32(0);
861+
int32arg2=PG_GETARG_INT32(1);
862+
863+
PG_RETURN_INT32(arg1&arg2);
864+
}
865+
866+
Datum
867+
int4or(PG_FUNCTION_ARGS)
868+
{
869+
int32arg1=PG_GETARG_INT32(0);
870+
int32arg2=PG_GETARG_INT32(1);
871+
872+
PG_RETURN_INT32(arg1 |arg2);
873+
}
874+
875+
Datum
876+
int4xor(PG_FUNCTION_ARGS)
877+
{
878+
int32arg1=PG_GETARG_INT32(0);
879+
int32arg2=PG_GETARG_INT32(1);
880+
881+
PG_RETURN_INT32(arg1 ^arg2);
882+
}
883+
884+
Datum
885+
int4shl(PG_FUNCTION_ARGS)
886+
{
887+
int32arg1=PG_GETARG_INT32(0);
888+
int32arg2=PG_GETARG_INT32(1);
889+
890+
PG_RETURN_INT32(arg1 <<arg2);
891+
}
892+
893+
Datum
894+
int4shr(PG_FUNCTION_ARGS)
895+
{
896+
int32arg1=PG_GETARG_INT32(0);
897+
int32arg2=PG_GETARG_INT32(1);
898+
899+
PG_RETURN_INT32(arg1 >>arg2);
900+
}
901+
902+
Datum
903+
int4not(PG_FUNCTION_ARGS)
904+
{
905+
int32arg1=PG_GETARG_INT32(0);
906+
907+
PG_RETURN_INT32(~arg1);
908+
}
909+
910+
Datum
911+
int2and(PG_FUNCTION_ARGS)
912+
{
913+
int16arg1=PG_GETARG_INT16(0);
914+
int16arg2=PG_GETARG_INT16(1);
915+
916+
PG_RETURN_INT16(arg1&arg2);
917+
}
918+
919+
Datum
920+
int2or(PG_FUNCTION_ARGS)
921+
{
922+
int16arg1=PG_GETARG_INT16(0);
923+
int16arg2=PG_GETARG_INT16(1);
924+
925+
PG_RETURN_INT16(arg1 |arg2);
926+
}
927+
928+
Datum
929+
int2xor(PG_FUNCTION_ARGS)
930+
{
931+
int16arg1=PG_GETARG_INT16(0);
932+
int16arg2=PG_GETARG_INT16(1);
933+
934+
PG_RETURN_INT16(arg1 ^arg2);
935+
}
936+
937+
Datum
938+
int2not(PG_FUNCTION_ARGS)
939+
{
940+
int16arg1=PG_GETARG_INT16(0);
941+
942+
PG_RETURN_INT16(~arg1);
943+
}
944+
945+
946+
Datum
947+
int2shl(PG_FUNCTION_ARGS)
948+
{
949+
int16arg1=PG_GETARG_INT16(0);
950+
int32arg2=PG_GETARG_INT32(1);
951+
952+
PG_RETURN_INT16(arg1 <<arg2);
953+
}
954+
955+
Datum
956+
int2shr(PG_FUNCTION_ARGS)
957+
{
958+
int16arg1=PG_GETARG_INT16(0);
959+
int32arg2=PG_GETARG_INT32(1);
960+
961+
PG_RETURN_INT16(arg1 >>arg2);
962+
}
963+

‎src/backend/utils/adt/int8.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.24 2000/07/28 05:07:41 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.25 2000/10/24 20:14:35 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -591,6 +591,68 @@ int48div(PG_FUNCTION_ARGS)
591591
PG_RETURN_INT64(val1 /val2);
592592
}
593593

594+
/* Binary arithmetics
595+
*
596+
*int8and- returns arg1 & arg2
597+
*int8or- returns arg1 | arg2
598+
*int8xor- returns arg1 # arg2
599+
*int8not- returns ~arg1
600+
*int8shl- returns arg1 << arg2
601+
*int8shr- returns arg1 >> arg2
602+
*/
603+
604+
Datum
605+
int8and(PG_FUNCTION_ARGS)
606+
{
607+
int64arg1=PG_GETARG_INT64(0);
608+
int64arg2=PG_GETARG_INT64(1);
609+
610+
PG_RETURN_INT64(arg1&arg2);
611+
}
612+
613+
Datum
614+
int8or(PG_FUNCTION_ARGS)
615+
{
616+
int64arg1=PG_GETARG_INT64(0);
617+
int64arg2=PG_GETARG_INT64(1);
618+
619+
PG_RETURN_INT64(arg1 |arg2);
620+
}
621+
622+
Datum
623+
int8xor(PG_FUNCTION_ARGS)
624+
{
625+
int64arg1=PG_GETARG_INT64(0);
626+
int64arg2=PG_GETARG_INT64(1);
627+
628+
PG_RETURN_INT64(arg1 ^arg2);
629+
}
630+
631+
Datum
632+
int8not(PG_FUNCTION_ARGS)
633+
{
634+
int64arg1=PG_GETARG_INT64(0);
635+
636+
PG_RETURN_INT64(~arg1);
637+
}
638+
639+
Datum
640+
int8shl(PG_FUNCTION_ARGS)
641+
{
642+
int64arg1=PG_GETARG_INT64(0);
643+
int32arg2=PG_GETARG_INT32(1);
644+
645+
PG_RETURN_INT64(arg1 <<arg2);
646+
}
647+
648+
Datum
649+
int8shr(PG_FUNCTION_ARGS)
650+
{
651+
int64arg1=PG_GETARG_INT64(0);
652+
int32arg2=PG_GETARG_INT32(1);
653+
654+
PG_RETURN_INT64(arg1 >>arg2);
655+
}
594656

595657
/*----------------------------------------------------------
596658
*Conversion operators.

‎src/include/catalog/pg_operator.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_operator.h,v 1.82 2000/09/15 18:45:27 tgl Exp $
11+
* $Id: pg_operator.h,v 1.83 2000/10/24 20:15:45 petere Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -727,7 +727,7 @@ DATA(insert OID = 1788 ( "<=" PGUID 0 b t f 1560 156016 1789 17870 0 bitle
727727
DATA(insertOID=1789 (">="PGUID0btf15601560161788178600bitgescalargtselscalargtjoinsel ));
728728
DATA(insertOID=1791 ("&"PGUID0btf1560156015601791000bitand-- ));
729729
DATA(insertOID=1792 ("|"PGUID0btf1560156015601792000bitor-- ));
730-
DATA(insertOID=1793 ("^"PGUID0btf1560156015601793000bitxor-- ));
730+
DATA(insertOID=1793 ("#"PGUID0btf1560156015601793000bitxor-- ));
731731
DATA(insertOID=1794 ("~"PGUID0ltf0156015600000bitnot-- ));
732732
DATA(insertOID=1795 ("<<"PGUID0btf15602315600000bitshiftleft-- ));
733733
DATA(insertOID=1796 (">>"PGUID0btf15602315600000bitshiftright-- ));
@@ -754,6 +754,27 @@ DATA(insert OID = 1871 ( ">" PGUID 0 b t f 20 21 16 1864 1872 0 0 int8
754754
DATA(insertOID=1872 ("<="PGUID0btf2021161867187100int82lescalarltselscalarltjoinsel ));
755755
DATA(insertOID=1873 (">="PGUID0btf2021161866187000int82gescalargtselscalargtjoinsel ));
756756

757+
DATA(insertOID=1874 ("&"PGUID0btf2121211874000int2and-- ));
758+
DATA(insertOID=1875 ("|"PGUID0btf2121211875000int2or-- ));
759+
DATA(insertOID=1876 ("#"PGUID0btf2121211876000int2xor-- ));
760+
DATA(insertOID=1877 ("~"PGUID0ltf021210000int2not-- ));
761+
DATA(insertOID=1878 ("<<"PGUID0btf2123210000int2shl-- ));
762+
DATA(insertOID=1879 (">>"PGUID0btf2123210000int2shr-- ));
763+
764+
DATA(insertOID=1880 ("&"PGUID0btf2323231880000int4and-- ));
765+
DATA(insertOID=1881 ("|"PGUID0btf2323231881000int4or-- ));
766+
DATA(insertOID=1882 ("#"PGUID0btf2323231882000int4xor-- ));
767+
DATA(insertOID=1883 ("~"PGUID0ltf023230000int4not-- ));
768+
DATA(insertOID=1884 ("<<"PGUID0btf2323230000int4shl-- ));
769+
DATA(insertOID=1885 (">>"PGUID0btf2323230000int4shr-- ));
770+
771+
DATA(insertOID=1886 ("&"PGUID0btf2020201886000int8and-- ));
772+
DATA(insertOID=1887 ("|"PGUID0btf2020201887000int8or-- ));
773+
DATA(insertOID=1888 ("#"PGUID0btf2020201888000int8xor-- ));
774+
DATA(insertOID=1889 ("~"PGUID0ltf020200000int8not-- ));
775+
DATA(insertOID=1890 ("<<"PGUID0btf2023200000int8shl-- ));
776+
DATA(insertOID=1891 (">>"PGUID0btf2023200000int8shr-- ));
777+
757778
/*
758779
* function prototypes
759780
*/

‎src/include/catalog/pg_proc.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.169 2000/10/1115:31:13 pjw Exp $
10+
* $Id: pg_proc.h,v 1.170 2000/10/24 20:15:45 petere Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2513,6 +2513,44 @@ DESCR("less-than-or-equal");
25132513
DATA(insertOID=1861 (int82gePGUID12fttt2f16"20 21"10000100int82ge- ));
25142514
DESCR("greater-than-or-equal");
25152515

2516+
DATA(insertOID=1892 (int2andPGUID12fttt2f21"21 21"10000100int2and- ));
2517+
DESCR("binary and");
2518+
DATA(insertOID=1893 (int2orPGUID12fttt2f21"21 21"10000100int2or- ));
2519+
DESCR("binary or");
2520+
DATA(insertOID=1894 (int2xorPGUID12fttt2f21"21 21"10000100int2xor- ));
2521+
DESCR("binary xor");
2522+
DATA(insertOID=1895 (int2notPGUID12fttt1f21"21"10000100int2not- ));
2523+
DESCR("binary not");
2524+
DATA(insertOID=1896 (int2shlPGUID12fttt2f21"21 23"10000100int2shl- ));
2525+
DESCR("binary shift left");
2526+
DATA(insertOID=1897 (int2shrPGUID12fttt2f21"21 23"10000100int2shr- ));
2527+
DESCR("binary shift right");
2528+
2529+
DATA(insertOID=1898 (int4andPGUID12fttt2f23"23 23"10000100int4and- ));
2530+
DESCR("binary and");
2531+
DATA(insertOID=1899 (int4orPGUID12fttt2f23"23 23"10000100int4or- ));
2532+
DESCR("binary or");
2533+
DATA(insertOID=1900 (int4xorPGUID12fttt2f23"23 23"10000100int4xor- ));
2534+
DESCR("binary xor");
2535+
DATA(insertOID=1901 (int4notPGUID12fttt1f23"23"10000100int4not- ));
2536+
DESCR("binary not");
2537+
DATA(insertOID=1902 (int4shlPGUID12fttt2f23"23 23"10000100int4shl- ));
2538+
DESCR("binary shift left");
2539+
DATA(insertOID=1903 (int4shrPGUID12fttt2f23"23 23"10000100int4shr- ));
2540+
DESCR("binary shift right");
2541+
2542+
DATA(insertOID=1904 (int8andPGUID12fttt2f20"20 20"10000100int8and- ));
2543+
DESCR("binary and");
2544+
DATA(insertOID=1905 (int8orPGUID12fttt2f20"20 20"10000100int8or- ));
2545+
DESCR("binary or");
2546+
DATA(insertOID=1906 (int8xorPGUID12fttt2f20"20 20"10000100int8xor- ));
2547+
DESCR("binary xor");
2548+
DATA(insertOID=1907 (int8notPGUID12fttt1f20"20"10000100int8not- ));
2549+
DESCR("binary not");
2550+
DATA(insertOID=1908 (int8shlPGUID12fttt2f20"20 23"10000100int8shl- ));
2551+
DESCR("binary shift left");
2552+
DATA(insertOID=1909 (int8shrPGUID12fttt2f20"20 23"10000100int8shr- ));
2553+
DESCR("binary shift right");
25162554

25172555
/*
25182556
* prototypes for functions pg_proc.c

‎src/include/utils/builtins.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.139 2000/09/2516:36:36 tgl Exp $
10+
* $Id: builtins.h,v 1.140 2000/10/24 20:16:47 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -127,6 +127,19 @@ extern Datum int2smaller(PG_FUNCTION_ARGS);
127127
externDatumint4larger(PG_FUNCTION_ARGS);
128128
externDatumint4smaller(PG_FUNCTION_ARGS);
129129

130+
externDatumint4and(PG_FUNCTION_ARGS);
131+
externDatumint4or(PG_FUNCTION_ARGS);
132+
externDatumint4xor(PG_FUNCTION_ARGS);
133+
externDatumint4not(PG_FUNCTION_ARGS);
134+
externDatumint4shl(PG_FUNCTION_ARGS);
135+
externDatumint4shr(PG_FUNCTION_ARGS);
136+
externDatumint2and(PG_FUNCTION_ARGS);
137+
externDatumint2or(PG_FUNCTION_ARGS);
138+
externDatumint2xor(PG_FUNCTION_ARGS);
139+
externDatumint2not(PG_FUNCTION_ARGS);
140+
externDatumint2shl(PG_FUNCTION_ARGS);
141+
externDatumint2shr(PG_FUNCTION_ARGS);
142+
130143
/* name.c */
131144
externDatumnamein(PG_FUNCTION_ARGS);
132145
externDatumnameout(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp