PostgreSQL Source Code  git master
int.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include "catalog/pg_type.h"
#include "common/int.h"
#include "funcapi.h"
#include "libpq/pqformat.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for int.c:

Go to the source code of this file.

Data Structures

struct  generate_series_fctx
 

Macros

#define Int2VectorSize(n)   (offsetof(int2vector, values) + (n) * sizeof(int16))
 

Functions

Datum int2in (PG_FUNCTION_ARGS)
 
Datum int2out (PG_FUNCTION_ARGS)
 
Datum int2recv (PG_FUNCTION_ARGS)
 
Datum int2send (PG_FUNCTION_ARGS)
 
int2vectorbuildint2vector (const int16 *int2s, int n)
 
Datum int2vectorin (PG_FUNCTION_ARGS)
 
Datum int2vectorout (PG_FUNCTION_ARGS)
 
Datum int2vectorrecv (PG_FUNCTION_ARGS)
 
Datum int2vectorsend (PG_FUNCTION_ARGS)
 
Datum int4in (PG_FUNCTION_ARGS)
 
Datum int4out (PG_FUNCTION_ARGS)
 
Datum int4recv (PG_FUNCTION_ARGS)
 
Datum int4send (PG_FUNCTION_ARGS)
 
Datum i2toi4 (PG_FUNCTION_ARGS)
 
Datum i4toi2 (PG_FUNCTION_ARGS)
 
Datum int4_bool (PG_FUNCTION_ARGS)
 
Datum bool_int4 (PG_FUNCTION_ARGS)
 
Datum int4eq (PG_FUNCTION_ARGS)
 
Datum int4ne (PG_FUNCTION_ARGS)
 
Datum int4lt (PG_FUNCTION_ARGS)
 
Datum int4le (PG_FUNCTION_ARGS)
 
Datum int4gt (PG_FUNCTION_ARGS)
 
Datum int4ge (PG_FUNCTION_ARGS)
 
Datum int2eq (PG_FUNCTION_ARGS)
 
Datum int2ne (PG_FUNCTION_ARGS)
 
Datum int2lt (PG_FUNCTION_ARGS)
 
Datum int2le (PG_FUNCTION_ARGS)
 
Datum int2gt (PG_FUNCTION_ARGS)
 
Datum int2ge (PG_FUNCTION_ARGS)
 
Datum int24eq (PG_FUNCTION_ARGS)
 
Datum int24ne (PG_FUNCTION_ARGS)
 
Datum int24lt (PG_FUNCTION_ARGS)
 
Datum int24le (PG_FUNCTION_ARGS)
 
Datum int24gt (PG_FUNCTION_ARGS)
 
Datum int24ge (PG_FUNCTION_ARGS)
 
Datum int42eq (PG_FUNCTION_ARGS)
 
Datum int42ne (PG_FUNCTION_ARGS)
 
Datum int42lt (PG_FUNCTION_ARGS)
 
Datum int42le (PG_FUNCTION_ARGS)
 
Datum int42gt (PG_FUNCTION_ARGS)
 
Datum int42ge (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int4 (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int2 (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int8 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int4 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int2 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int8 (PG_FUNCTION_ARGS)
 
Datum int4um (PG_FUNCTION_ARGS)
 
Datum int4up (PG_FUNCTION_ARGS)
 
Datum int4pl (PG_FUNCTION_ARGS)
 
Datum int4mi (PG_FUNCTION_ARGS)
 
Datum int4mul (PG_FUNCTION_ARGS)
 
Datum int4div (PG_FUNCTION_ARGS)
 
Datum int4inc (PG_FUNCTION_ARGS)
 
Datum int2um (PG_FUNCTION_ARGS)
 
Datum int2up (PG_FUNCTION_ARGS)
 
Datum int2pl (PG_FUNCTION_ARGS)
 
Datum int2mi (PG_FUNCTION_ARGS)
 
Datum int2mul (PG_FUNCTION_ARGS)
 
Datum int2div (PG_FUNCTION_ARGS)
 
Datum int24pl (PG_FUNCTION_ARGS)
 
Datum int24mi (PG_FUNCTION_ARGS)
 
Datum int24mul (PG_FUNCTION_ARGS)
 
Datum int24div (PG_FUNCTION_ARGS)
 
Datum int42pl (PG_FUNCTION_ARGS)
 
Datum int42mi (PG_FUNCTION_ARGS)
 
Datum int42mul (PG_FUNCTION_ARGS)
 
Datum int42div (PG_FUNCTION_ARGS)
 
Datum int4mod (PG_FUNCTION_ARGS)
 
Datum int2mod (PG_FUNCTION_ARGS)
 
Datum int4abs (PG_FUNCTION_ARGS)
 
Datum int2abs (PG_FUNCTION_ARGS)
 
Datum int2larger (PG_FUNCTION_ARGS)
 
Datum int2smaller (PG_FUNCTION_ARGS)
 
Datum int4larger (PG_FUNCTION_ARGS)
 
Datum int4smaller (PG_FUNCTION_ARGS)
 
Datum int4and (PG_FUNCTION_ARGS)
 
Datum int4or (PG_FUNCTION_ARGS)
 
Datum int4xor (PG_FUNCTION_ARGS)
 
Datum int4shl (PG_FUNCTION_ARGS)
 
Datum int4shr (PG_FUNCTION_ARGS)
 
Datum int4not (PG_FUNCTION_ARGS)
 
Datum int2and (PG_FUNCTION_ARGS)
 
Datum int2or (PG_FUNCTION_ARGS)
 
Datum int2xor (PG_FUNCTION_ARGS)
 
Datum int2not (PG_FUNCTION_ARGS)
 
Datum int2shl (PG_FUNCTION_ARGS)
 
Datum int2shr (PG_FUNCTION_ARGS)
 
Datum generate_series_int4 (PG_FUNCTION_ARGS)
 
Datum generate_series_step_int4 (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ Int2VectorSize

#define Int2VectorSize (   n)    (offsetof(int2vector, values) + (n) * sizeof(int16))

Definition at line 41 of file int.c.

Referenced by buildint2vector(), and int2vectorin().

Function Documentation

◆ bool_int4()

Datum bool_int4 ( PG_FUNCTION_ARGS  )

Definition at line 349 of file int.c.

References PG_GETARG_BOOL, and PG_RETURN_INT32.

350 {
351  if (PG_GETARG_BOOL(0) == false)
352  PG_RETURN_INT32(0);
353  else
354  PG_RETURN_INT32(1);
355 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:244

◆ buildint2vector()

int2vector* buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 110 of file int.c.

References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), SET_VARSIZE, and int2vector::values.

Referenced by CreateStatistics(), CreateTrigger(), StorePartitionKey(), and UpdateIndexRelation().

111 {
112  int2vector *result;
113 
114  result = (int2vector *) palloc0(Int2VectorSize(n));
115 
116  if (n > 0 && int2s)
117  memcpy(result->values, int2s, n * sizeof(int16));
118 
119  /*
120  * Attach standard array header. For historical reasons, we set the index
121  * lower bound to 0 not 1.
122  */
123  SET_VARSIZE(result, Int2VectorSize(n));
124  result->ndim = 1;
125  result->dataoffset = 0; /* never any nulls */
126  result->elemtype = INT2OID;
127  result->dim1 = n;
128  result->lbound1 = 0;
129 
130  return result;
131 }
signed short int16
Definition: c.h:312
int lbound1
Definition: c.h:551
Oid elemtype
Definition: c.h:549
int32 dataoffset
Definition: c.h:548
int ndim
Definition: c.h:547
Definition: c.h:544
void * palloc0(Size size)
Definition: mcxt.c:955
int dim1
Definition: c.h:550
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:552
#define Int2VectorSize(n)
Definition: int.c:41
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:327

◆ generate_series_int4()

Datum generate_series_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1353 of file int.c.

References generate_series_step_int4().

1354 {
1355  return generate_series_step_int4(fcinfo);
1356 }
Datum generate_series_step_int4(PG_FUNCTION_ARGS)
Definition: int.c:1359

◆ generate_series_step_int4()

Datum generate_series_step_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1359 of file int.c.

References generate_series_fctx::current, ereport, errcode(), errmsg(), ERROR, generate_series_fctx::finish, Int32GetDatum, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, palloc(), pg_add_s32_overflow(), PG_GETARG_INT32, PG_NARGS, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, generate_series_fctx::step, and FuncCallContext::user_fctx.

Referenced by generate_series_int4().

1360 {
1361  FuncCallContext *funcctx;
1362  generate_series_fctx *fctx;
1363  int32 result;
1364  MemoryContext oldcontext;
1365 
1366  /* stuff done only on the first call of the function */
1367  if (SRF_IS_FIRSTCALL())
1368  {
1369  int32 start = PG_GETARG_INT32(0);
1370  int32 finish = PG_GETARG_INT32(1);
1371  int32 step = 1;
1372 
1373  /* see if we were given an explicit step size */
1374  if (PG_NARGS() == 3)
1375  step = PG_GETARG_INT32(2);
1376  if (step == 0)
1377  ereport(ERROR,
1378  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1379  errmsg("step size cannot equal zero")));
1380 
1381  /* create a function context for cross-call persistence */
1382  funcctx = SRF_FIRSTCALL_INIT();
1383 
1384  /*
1385  * switch to memory context appropriate for multiple function calls
1386  */
1387  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1388 
1389  /* allocate memory for user context */
1390  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1391 
1392  /*
1393  * Use fctx to keep state from call to call. Seed current with the
1394  * original start value
1395  */
1396  fctx->current = start;
1397  fctx->finish = finish;
1398  fctx->step = step;
1399 
1400  funcctx->user_fctx = fctx;
1401  MemoryContextSwitchTo(oldcontext);
1402  }
1403 
1404  /* stuff done on every call of the function */
1405  funcctx = SRF_PERCALL_SETUP();
1406 
1407  /*
1408  * get the saved state and use current as the result for this iteration
1409  */
1410  fctx = funcctx->user_fctx;
1411  result = fctx->current;
1412 
1413  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1414  (fctx->step < 0 && fctx->current >= fctx->finish))
1415  {
1416  /*
1417  * Increment current in preparation for next iteration. If next-value
1418  * computation overflows, this is the final result.
1419  */
1420  if (pg_add_s32_overflow(fctx->current, fctx->step, &fctx->current))
1421  fctx->step = 0;
1422 
1423  /* do when there is more left to send */
1424  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
1425  }
1426  else
1427  /* do when there is no more left */
1428  SRF_RETURN_DONE(funcctx);
1429 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:294
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:298
signed int int32
Definition: c.h:313
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:300
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int32 current
Definition: int.c:45
int32 finish
Definition: int.c:46
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:98
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:110
#define PG_NARGS()
Definition: fmgr.h:173
#define Int32GetDatum(X)
Definition: postgres.h:462
void * user_fctx
Definition: funcapi.h:91
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:318
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:296

◆ i2toi4()

Datum i2toi4 ( PG_FUNCTION_ARGS  )

Definition at line 317 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT32.

318 {
319  int16 arg1 = PG_GETARG_INT16(0);
320 
321  PG_RETURN_INT32((int32) arg1);
322 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ i4toi2()

Datum i4toi2 ( PG_FUNCTION_ARGS  )

Definition at line 325 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT16, and unlikely.

326 {
327  int32 arg1 = PG_GETARG_INT32(0);
328 
329  if (unlikely(arg1 < SHRT_MIN) || unlikely(arg1 > SHRT_MAX))
330  ereport(ERROR,
331  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
332  errmsg("smallint out of range")));
333 
334  PG_RETURN_INT16((int16) arg1);
335 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ in_range_int2_int2()

Datum in_range_int2_int2 ( PG_FUNCTION_ARGS  )

Definition at line 716 of file int.c.

References DirectFunctionCall5, in_range_int2_int4(), Int32GetDatum, PG_GETARG_DATUM, and PG_GETARG_INT16.

717 {
718  /* Doesn't seem worth duplicating code for, so just invoke int2_int4 */
720  PG_GETARG_DATUM(0),
721  PG_GETARG_DATUM(1),
723  PG_GETARG_DATUM(3),
724  PG_GETARG_DATUM(4));
725 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:238
signed int int32
Definition: c.h:313
Datum in_range_int2_int4(PG_FUNCTION_ARGS)
Definition: int.c:681
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:598
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define Int32GetDatum(X)
Definition: postgres.h:462

◆ in_range_int2_int4()

Datum in_range_int2_int4 ( PG_FUNCTION_ARGS  )

Definition at line 681 of file int.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_BOOL, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int2_int2().

682 {
683  /* We must do all the math in int32 */
685  int32 base = (int32) PG_GETARG_INT16(1);
686  int32 offset = PG_GETARG_INT32(2);
687  bool sub = PG_GETARG_BOOL(3);
688  bool less = PG_GETARG_BOOL(4);
689  int32 sum;
690 
691  if (offset < 0)
692  ereport(ERROR,
693  (errcode(ERRCODE_INVALID_PRECEDING_FOLLOWING_SIZE),
694  errmsg("invalid preceding or following size in window function")));
695 
696  if (sub)
697  offset = -offset; /* cannot overflow */
698 
699  if (unlikely(pg_add_s32_overflow(base, offset, &sum)))
700  {
701  /*
702  * If sub is false, the true sum is surely more than val, so correct
703  * answer is the same as "less". If sub is true, the true sum is
704  * surely less than val, so the answer is "!less".
705  */
706  PG_RETURN_BOOL(sub ? !less : less);
707  }
708 
709  if (less)
710  PG_RETURN_BOOL(val <= sum);
711  else
712  PG_RETURN_BOOL(val >= sum);
713 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:244
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:98
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
long val
Definition: informix.c:689

◆ in_range_int2_int8()

Datum in_range_int2_int8 ( PG_FUNCTION_ARGS  )

Definition at line 728 of file int.c.

References DirectFunctionCall5, in_range_int4_int8(), Int32GetDatum, PG_GETARG_DATUM, and PG_GETARG_INT16.

729 {
730  /* Doesn't seem worth duplicating code for, so just invoke int4_int8 */
734  PG_GETARG_DATUM(2),
735  PG_GETARG_DATUM(3),
736  PG_GETARG_DATUM(4));
737 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:238
Datum in_range_int4_int8(PG_FUNCTION_ARGS)
Definition: int.c:646
signed int int32
Definition: c.h:313
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:598
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define Int32GetDatum(X)
Definition: postgres.h:462

◆ in_range_int4_int2()

Datum in_range_int4_int2 ( PG_FUNCTION_ARGS  )

Definition at line 634 of file int.c.

References DirectFunctionCall5, in_range_int4_int4(), Int32GetDatum, PG_GETARG_DATUM, and PG_GETARG_INT16.

635 {
636  /* Doesn't seem worth duplicating code for, so just invoke int4_int4 */
638  PG_GETARG_DATUM(0),
639  PG_GETARG_DATUM(1),
641  PG_GETARG_DATUM(3),
642  PG_GETARG_DATUM(4));
643 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:238
signed int int32
Definition: c.h:313
Datum in_range_int4_int4(PG_FUNCTION_ARGS)
Definition: int.c:600
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:598
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define Int32GetDatum(X)
Definition: postgres.h:462

◆ in_range_int4_int4()

Datum in_range_int4_int4 ( PG_FUNCTION_ARGS  )

Definition at line 600 of file int.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_BOOL, PG_GETARG_INT32, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int4_int2().

601 {
603  int32 base = PG_GETARG_INT32(1);
604  int32 offset = PG_GETARG_INT32(2);
605  bool sub = PG_GETARG_BOOL(3);
606  bool less = PG_GETARG_BOOL(4);
607  int32 sum;
608 
609  if (offset < 0)
610  ereport(ERROR,
611  (errcode(ERRCODE_INVALID_PRECEDING_FOLLOWING_SIZE),
612  errmsg("invalid preceding or following size in window function")));
613 
614  if (sub)
615  offset = -offset; /* cannot overflow */
616 
617  if (unlikely(pg_add_s32_overflow(base, offset, &sum)))
618  {
619  /*
620  * If sub is false, the true sum is surely more than val, so correct
621  * answer is the same as "less". If sub is true, the true sum is
622  * surely less than val, so the answer is "!less".
623  */
624  PG_RETURN_BOOL(sub ? !less : less);
625  }
626 
627  if (less)
628  PG_RETURN_BOOL(val <= sum);
629  else
630  PG_RETURN_BOOL(val >= sum);
631 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:244
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:98
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
long val
Definition: informix.c:689

◆ in_range_int4_int8()

Datum in_range_int4_int8 ( PG_FUNCTION_ARGS  )

Definition at line 646 of file int.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_BOOL, PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int2_int8().

647 {
648  /* We must do all the math in int64 */
649  int64 val = (int64) PG_GETARG_INT32(0);
650  int64 base = (int64) PG_GETARG_INT32(1);
651  int64 offset = PG_GETARG_INT64(2);
652  bool sub = PG_GETARG_BOOL(3);
653  bool less = PG_GETARG_BOOL(4);
654  int64 sum;
655 
656  if (offset < 0)
657  ereport(ERROR,
658  (errcode(ERRCODE_INVALID_PRECEDING_FOLLOWING_SIZE),
659  errmsg("invalid preceding or following size in window function")));
660 
661  if (sub)
662  offset = -offset; /* cannot overflow */
663 
664  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
665  {
666  /*
667  * If sub is false, the true sum is surely more than val, so correct
668  * answer is the same as "less". If sub is true, the true sum is
669  * surely less than val, so the answer is "!less".
670  */
671  PG_RETURN_BOOL(sub ? !less : less);
672  }
673 
674  if (less)
675  PG_RETURN_BOOL(val <= sum);
676  else
677  PG_RETURN_BOOL(val >= sum);
678 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:244
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:167
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
long val
Definition: informix.c:689

◆ int24div()

Datum int24div ( PG_FUNCTION_ARGS  )

Definition at line 1007 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

1008 {
1009  int16 arg1 = PG_GETARG_INT16(0);
1010  int32 arg2 = PG_GETARG_INT32(1);
1011 
1012  if (unlikely(arg2 == 0))
1013  {
1014  ereport(ERROR,
1015  (errcode(ERRCODE_DIVISION_BY_ZERO),
1016  errmsg("division by zero")));
1017  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1018  PG_RETURN_NULL();
1019  }
1020 
1021  /* No overflow is possible */
1022  PG_RETURN_INT32((int32) arg1 / arg2);
1023 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int24eq()

Datum int24eq ( PG_FUNCTION_ARGS  )

Definition at line 481 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

482 {
483  int16 arg1 = PG_GETARG_INT16(0);
484  int32 arg2 = PG_GETARG_INT32(1);
485 
486  PG_RETURN_BOOL(arg1 == arg2);
487 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int24ge()

Datum int24ge ( PG_FUNCTION_ARGS  )

Definition at line 526 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

527 {
528  int16 arg1 = PG_GETARG_INT16(0);
529  int32 arg2 = PG_GETARG_INT32(1);
530 
531  PG_RETURN_BOOL(arg1 >= arg2);
532 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int24gt()

Datum int24gt ( PG_FUNCTION_ARGS  )

Definition at line 517 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

518 {
519  int16 arg1 = PG_GETARG_INT16(0);
520  int32 arg2 = PG_GETARG_INT32(1);
521 
522  PG_RETURN_BOOL(arg1 > arg2);
523 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int24le()

Datum int24le ( PG_FUNCTION_ARGS  )

Definition at line 508 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

509 {
510  int16 arg1 = PG_GETARG_INT16(0);
511  int32 arg2 = PG_GETARG_INT32(1);
512 
513  PG_RETURN_BOOL(arg1 <= arg2);
514 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int24lt()

Datum int24lt ( PG_FUNCTION_ARGS  )

Definition at line 499 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

500 {
501  int16 arg1 = PG_GETARG_INT16(0);
502  int32 arg2 = PG_GETARG_INT32(1);
503 
504  PG_RETURN_BOOL(arg1 < arg2);
505 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int24mi()

Datum int24mi ( PG_FUNCTION_ARGS  )

Definition at line 979 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

980 {
981  int16 arg1 = PG_GETARG_INT16(0);
982  int32 arg2 = PG_GETARG_INT32(1);
983  int32 result;
984 
985  if (unlikely(pg_sub_s32_overflow((int32) arg1, arg2, &result)))
986  ereport(ERROR,
987  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
988  errmsg("integer out of range")));
989  PG_RETURN_INT32(result);
990 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:121
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int24mul()

Datum int24mul ( PG_FUNCTION_ARGS  )

Definition at line 993 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

994 {
995  int16 arg1 = PG_GETARG_INT16(0);
996  int32 arg2 = PG_GETARG_INT32(1);
997  int32 result;
998 
999  if (unlikely(pg_mul_s32_overflow((int32) arg1, arg2, &result)))
1000  ereport(ERROR,
1001  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1002  errmsg("integer out of range")));
1003  PG_RETURN_INT32(result);
1004 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:144
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int24ne()

Datum int24ne ( PG_FUNCTION_ARGS  )

Definition at line 490 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

491 {
492  int16 arg1 = PG_GETARG_INT16(0);
493  int32 arg2 = PG_GETARG_INT32(1);
494 
495  PG_RETURN_BOOL(arg1 != arg2);
496 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int24pl()

Datum int24pl ( PG_FUNCTION_ARGS  )

Definition at line 965 of file int.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

966 {
967  int16 arg1 = PG_GETARG_INT16(0);
968  int32 arg2 = PG_GETARG_INT32(1);
969  int32 result;
970 
971  if (unlikely(pg_add_s32_overflow((int32) arg1, arg2, &result)))
972  ereport(ERROR,
973  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
974  errmsg("integer out of range")));
975  PG_RETURN_INT32(result);
976 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:98
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int2abs()

Datum int2abs ( PG_FUNCTION_ARGS  )

Definition at line 1182 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, and unlikely.

1183 {
1184  int16 arg1 = PG_GETARG_INT16(0);
1185  int16 result;
1186 
1187  if (unlikely(arg1 == PG_INT16_MIN))
1188  ereport(ERROR,
1189  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1190  errmsg("smallint out of range")));
1191  result = (arg1 < 0) ? -arg1 : arg1;
1192  PG_RETURN_INT16(result);
1193 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:404
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int2and()

Datum int2and ( PG_FUNCTION_ARGS  )

Definition at line 1296 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1297 {
1298  int16 arg1 = PG_GETARG_INT16(0);
1299  int16 arg2 = PG_GETARG_INT16(1);
1300 
1301  PG_RETURN_INT16(arg1 & arg2);
1302 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2div()

Datum int2div ( PG_FUNCTION_ARGS  )

Definition at line 926 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, PG_RETURN_NULL, and unlikely.

927 {
928  int16 arg1 = PG_GETARG_INT16(0);
929  int16 arg2 = PG_GETARG_INT16(1);
930  int16 result;
931 
932  if (arg2 == 0)
933  {
934  ereport(ERROR,
935  (errcode(ERRCODE_DIVISION_BY_ZERO),
936  errmsg("division by zero")));
937  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
938  PG_RETURN_NULL();
939  }
940 
941  /*
942  * SHRT_MIN / -1 is problematic, since the result can't be represented on
943  * a two's-complement machine. Some machines produce SHRT_MIN, some
944  * produce zero, some throw an exception. We can dodge the problem by
945  * recognizing that division by -1 is the same as negation.
946  */
947  if (arg2 == -1)
948  {
949  if (unlikely(arg1 == PG_INT16_MIN))
950  ereport(ERROR,
951  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
952  errmsg("smallint out of range")));
953  result = -arg1;
954  PG_RETURN_INT16(result);
955  }
956 
957  /* No overflow is possible */
958 
959  result = arg1 / arg2;
960 
961  PG_RETURN_INT16(result);
962 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:404
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int2eq()

Datum int2eq ( PG_FUNCTION_ARGS  )

Definition at line 427 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

428 {
429  int16 arg1 = PG_GETARG_INT16(0);
430  int16 arg2 = PG_GETARG_INT16(1);
431 
432  PG_RETURN_BOOL(arg1 == arg2);
433 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2ge()

Datum int2ge ( PG_FUNCTION_ARGS  )

Definition at line 472 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

473 {
474  int16 arg1 = PG_GETARG_INT16(0);
475  int16 arg2 = PG_GETARG_INT16(1);
476 
477  PG_RETURN_BOOL(arg1 >= arg2);
478 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2gt()

Datum int2gt ( PG_FUNCTION_ARGS  )

Definition at line 463 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

464 {
465  int16 arg1 = PG_GETARG_INT16(0);
466  int16 arg2 = PG_GETARG_INT16(1);
467 
468  PG_RETURN_BOOL(arg1 > arg2);
469 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2in()

Datum int2in ( PG_FUNCTION_ARGS  )

Definition at line 59 of file int.c.

References pg_atoi(), PG_GETARG_CSTRING, and PG_RETURN_INT16.

60 {
61  char *num = PG_GETARG_CSTRING(0);
62 
63  PG_RETURN_INT16(pg_atoi(num, sizeof(int16), '\0'));
64 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247
int32 pg_atoi(const char *s, int size, int c)
Definition: numutils.c:37

◆ int2larger()

Datum int2larger ( PG_FUNCTION_ARGS  )

Definition at line 1196 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1197 {
1198  int16 arg1 = PG_GETARG_INT16(0);
1199  int16 arg2 = PG_GETARG_INT16(1);
1200 
1201  PG_RETURN_INT16((arg1 > arg2) ? arg1 : arg2);
1202 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2le()

Datum int2le ( PG_FUNCTION_ARGS  )

Definition at line 454 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

455 {
456  int16 arg1 = PG_GETARG_INT16(0);
457  int16 arg2 = PG_GETARG_INT16(1);
458 
459  PG_RETURN_BOOL(arg1 <= arg2);
460 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2lt()

Datum int2lt ( PG_FUNCTION_ARGS  )

Definition at line 445 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

446 {
447  int16 arg1 = PG_GETARG_INT16(0);
448  int16 arg2 = PG_GETARG_INT16(1);
449 
450  PG_RETURN_BOOL(arg1 < arg2);
451 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2mi()

Datum int2mi ( PG_FUNCTION_ARGS  )

Definition at line 897 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, pg_sub_s16_overflow(), and unlikely.

898 {
899  int16 arg1 = PG_GETARG_INT16(0);
900  int16 arg2 = PG_GETARG_INT16(1);
901  int16 result;
902 
903  if (unlikely(pg_sub_s16_overflow(arg1, arg2, &result)))
904  ereport(ERROR,
905  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
906  errmsg("smallint out of range")));
907  PG_RETURN_INT16(result);
908 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_sub_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:52
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int2mod()

Datum int2mod ( PG_FUNCTION_ARGS  )

Definition at line 1135 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, PG_RETURN_NULL, and unlikely.

1136 {
1137  int16 arg1 = PG_GETARG_INT16(0);
1138  int16 arg2 = PG_GETARG_INT16(1);
1139 
1140  if (unlikely(arg2 == 0))
1141  {
1142  ereport(ERROR,
1143  (errcode(ERRCODE_DIVISION_BY_ZERO),
1144  errmsg("division by zero")));
1145  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1146  PG_RETURN_NULL();
1147  }
1148 
1149  /*
1150  * Some machines throw a floating-point exception for INT_MIN % -1, which
1151  * is a bit silly since the correct answer is perfectly well-defined,
1152  * namely zero. (It's not clear this ever happens when dealing with
1153  * int16, but we might as well have the test for safety.)
1154  */
1155  if (arg2 == -1)
1156  PG_RETURN_INT16(0);
1157 
1158  /* No overflow is possible */
1159 
1160  PG_RETURN_INT16(arg1 % arg2);
1161 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int2mul()

Datum int2mul ( PG_FUNCTION_ARGS  )

Definition at line 911 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, pg_mul_s16_overflow(), PG_RETURN_INT16, and unlikely.

912 {
913  int16 arg1 = PG_GETARG_INT16(0);
914  int16 arg2 = PG_GETARG_INT16(1);
915  int16 result;
916 
917  if (unlikely(pg_mul_s16_overflow(arg1, arg2, &result)))
918  ereport(ERROR,
919  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
920  errmsg("smallint out of range")));
921 
922  PG_RETURN_INT16(result);
923 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
static bool pg_mul_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:75
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int2ne()

Datum int2ne ( PG_FUNCTION_ARGS  )

Definition at line 436 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

437 {
438  int16 arg1 = PG_GETARG_INT16(0);
439  int16 arg2 = PG_GETARG_INT16(1);
440 
441  PG_RETURN_BOOL(arg1 != arg2);
442 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2not()

Datum int2not ( PG_FUNCTION_ARGS  )

Definition at line 1323 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1324 {
1325  int16 arg1 = PG_GETARG_INT16(0);
1326 
1327  PG_RETURN_INT16(~arg1);
1328 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2or()

Datum int2or ( PG_FUNCTION_ARGS  )

Definition at line 1305 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1306 {
1307  int16 arg1 = PG_GETARG_INT16(0);
1308  int16 arg2 = PG_GETARG_INT16(1);
1309 
1310  PG_RETURN_INT16(arg1 | arg2);
1311 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2out()

Datum int2out ( PG_FUNCTION_ARGS  )

Definition at line 70 of file int.c.

References palloc(), PG_GETARG_INT16, pg_itoa(), and PG_RETURN_CSTRING.

71 {
72  int16 arg1 = PG_GETARG_INT16(0);
73  char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */
74 
75  pg_itoa(arg1, result);
76  PG_RETURN_CSTRING(result);
77 }
signed short int16
Definition: c.h:312
void pg_itoa(int16 i, char *a)
Definition: numutils.c:120
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
void * palloc(Size size)
Definition: mcxt.c:924

◆ int2pl()

Datum int2pl ( PG_FUNCTION_ARGS  )

Definition at line 883 of file int.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s16_overflow(), PG_GETARG_INT16, PG_RETURN_INT16, and unlikely.

884 {
885  int16 arg1 = PG_GETARG_INT16(0);
886  int16 arg2 = PG_GETARG_INT16(1);
887  int16 result;
888 
889  if (unlikely(pg_add_s16_overflow(arg1, arg2, &result)))
890  ereport(ERROR,
891  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
892  errmsg("smallint out of range")));
893  PG_RETURN_INT16(result);
894 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
static bool pg_add_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:29
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int2recv()

Datum int2recv ( PG_FUNCTION_ARGS  )

Definition at line 83 of file int.c.

References buf, PG_GETARG_POINTER, PG_RETURN_INT16, and pq_getmsgint().

84 {
86 
87  PG_RETURN_INT16((int16) pq_getmsgint(buf, sizeof(int16)));
88 }
signed short int16
Definition: c.h:312
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
static char * buf
Definition: pg_test_fsync.c:67
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ int2send()

Datum int2send ( PG_FUNCTION_ARGS  )

Definition at line 94 of file int.c.

References buf, PG_GETARG_INT16, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint16().

95 {
96  int16 arg1 = PG_GETARG_INT16(0);
98 
99  pq_begintypsend(&buf);
100  pq_sendint16(&buf, arg1);
102 }
signed short int16
Definition: c.h:312
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:335
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static void pq_sendint16(StringInfo buf, int16 i)
Definition: pqformat.h:140

◆ int2shl()

Datum int2shl ( PG_FUNCTION_ARGS  )

Definition at line 1332 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

1333 {
1334  int16 arg1 = PG_GETARG_INT16(0);
1335  int32 arg2 = PG_GETARG_INT32(1);
1336 
1337  PG_RETURN_INT16(arg1 << arg2);
1338 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
signed int int32
Definition: c.h:313
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2shr()

Datum int2shr ( PG_FUNCTION_ARGS  )

Definition at line 1341 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

1342 {
1343  int16 arg1 = PG_GETARG_INT16(0);
1344  int32 arg2 = PG_GETARG_INT32(1);
1345 
1346  PG_RETURN_INT16(arg1 >> arg2);
1347 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
signed int int32
Definition: c.h:313
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2smaller()

Datum int2smaller ( PG_FUNCTION_ARGS  )

Definition at line 1205 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1206 {
1207  int16 arg1 = PG_GETARG_INT16(0);
1208  int16 arg2 = PG_GETARG_INT16(1);
1209 
1210  PG_RETURN_INT16((arg1 < arg2) ? arg1 : arg2);
1211 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int2um()

Datum int2um ( PG_FUNCTION_ARGS  )

Definition at line 863 of file int.c.

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, and unlikely.

864 {
866 
867  if (unlikely(arg == PG_INT16_MIN))
868  ereport(ERROR,
869  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
870  errmsg("smallint out of range")));
871  PG_RETURN_INT16(-arg);
872 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:404
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208

◆ int2up()

Datum int2up ( PG_FUNCTION_ARGS  )

Definition at line 875 of file int.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT16.

876 {
878 
879  PG_RETURN_INT16(arg);
880 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
void * arg

◆ int2vectorin()

Datum int2vectorin ( PG_FUNCTION_ARGS  )

Definition at line 137 of file int.c.

References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, ereport, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), pg_atoi(), PG_GETARG_CSTRING, PG_RETURN_POINTER, SET_VARSIZE, and int2vector::values.

138 {
139  char *intString = PG_GETARG_CSTRING(0);
140  int2vector *result;
141  int n;
142 
144 
145  for (n = 0; *intString && n < FUNC_MAX_ARGS; n++)
146  {
147  while (*intString && isspace((unsigned char) *intString))
148  intString++;
149  if (*intString == '\0')
150  break;
151  result->values[n] = pg_atoi(intString, sizeof(int16), ' ');
152  while (*intString && !isspace((unsigned char) *intString))
153  intString++;
154  }
155  while (*intString && isspace((unsigned char) *intString))
156  intString++;
157  if (*intString)
158  ereport(ERROR,
159  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
160  errmsg("int2vector has too many elements")));
161 
162  SET_VARSIZE(result, Int2VectorSize(n));
163  result->ndim = 1;
164  result->dataoffset = 0; /* never any nulls */
165  result->elemtype = INT2OID;
166  result->dim1 = n;
167  result->lbound1 = 0;
168 
169  PG_RETURN_POINTER(result);
170 }
signed short int16
Definition: c.h:312
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
int lbound1
Definition: c.h:551
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid elemtype
Definition: c.h:549
#define FUNC_MAX_ARGS
int32 dataoffset
Definition: c.h:548
#define ERROR
Definition: elog.h:43
int ndim
Definition: c.h:547
#define ereport(elevel, rest)
Definition: elog.h:122
Definition: c.h:544
void * palloc0(Size size)
Definition: mcxt.c:955
int dim1
Definition: c.h:550
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:552
#define Int2VectorSize(n)
Definition: int.c:41
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:327
int32 pg_atoi(const char *s, int size, int c)
Definition: numutils.c:37

◆ int2vectorout()

Datum int2vectorout ( PG_FUNCTION_ARGS  )

Definition at line 176 of file int.c.

References int2vector::dim1, palloc(), PG_GETARG_POINTER, pg_itoa(), PG_RETURN_CSTRING, and int2vector::values.

177 {
178  int2vector *int2Array = (int2vector *) PG_GETARG_POINTER(0);
179  int num,
180  nnums = int2Array->dim1;
181  char *rp;
182  char *result;
183 
184  /* assumes sign, 5 digits, ' ' */
185  rp = result = (char *) palloc(nnums * 7 + 1);
186  for (num = 0; num < nnums; num++)
187  {
188  if (num != 0)
189  *rp++ = ' ';
190  pg_itoa(int2Array->values[num], rp);
191  while (*++rp != '\0')
192  ;
193  }
194  *rp = '\0';
195  PG_RETURN_CSTRING(result);
196 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
void pg_itoa(int16 i, char *a)
Definition: numutils.c:120
Definition: c.h:544
int dim1
Definition: c.h:550
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:552
void * palloc(Size size)
Definition: mcxt.c:924

◆ int2vectorrecv()

Datum int2vectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 202 of file int.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, array_recv(), Assert, buf, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoData::flinfo, FUNC_MAX_ARGS, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, ObjectIdGetDatum, PG_GETARG_POINTER, PG_RETURN_POINTER, and PointerGetDatum.

203 {
205  FunctionCallInfoData locfcinfo;
206  int2vector *result;
207 
208  /*
209  * Normally one would call array_recv() using DirectFunctionCall3, but
210  * that does not work since array_recv wants to cache some data using
211  * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
212  * parameter.
213  */
214  InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 3,
215  InvalidOid, NULL, NULL);
216 
217  locfcinfo.arg[0] = PointerGetDatum(buf);
218  locfcinfo.arg[1] = ObjectIdGetDatum(INT2OID);
219  locfcinfo.arg[2] = Int32GetDatum(-1);
220  locfcinfo.argnull[0] = false;
221  locfcinfo.argnull[1] = false;
222  locfcinfo.argnull[2] = false;
223 
224  result = (int2vector *) DatumGetPointer(array_recv(&locfcinfo));
225 
226  Assert(!locfcinfo.isnull);
227 
228  /* sanity checks: int2vector must be 1-D, 0-based, no nulls */
229  if (ARR_NDIM(result) != 1 ||
230  ARR_HASNULL(result) ||
231  ARR_ELEMTYPE(result) != INT2OID ||
232  ARR_LBOUND(result)[0] != 0)
233  ereport(ERROR,
234  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
235  errmsg("invalid int2vector data")));
236 
237  /* check length for consistency with int2vectorin() */
238  if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS)
239  ereport(ERROR,
240  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
241  errmsg("oidvector has too many elements")));
242 
243  PG_RETURN_POINTER(result);
244 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
#define PointerGetDatum(X)
Definition: postgres.h:539
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
Datum array_recv(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1255
#define ARR_LBOUND(a)
Definition: array.h:281
#define FUNC_MAX_ARGS
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:279
static char * buf
Definition: pg_test_fsync.c:67
#define ARR_HASNULL(a)
Definition: array.h:276
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
#define ereport(elevel, rest)
Definition: elog.h:122
Definition: c.h:544
#define InvalidOid
Definition: postgres_ext.h:36
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define Assert(condition)
Definition: c.h:699
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define ARR_NDIM(a)
Definition: array.h:275
#define DatumGetPointer(X)
Definition: postgres.h:532
#define Int32GetDatum(X)
Definition: postgres.h:462
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ARR_ELEMTYPE(a)
Definition: array.h:277

◆ int2vectorsend()

Datum int2vectorsend ( PG_FUNCTION_ARGS  )

Definition at line 250 of file int.c.

References array_send().

251 {
252  return array_send(fcinfo);
253 }
Datum array_send(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1535

◆ int2xor()

Datum int2xor ( PG_FUNCTION_ARGS  )

Definition at line 1314 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1315 {
1316  int16 arg1 = PG_GETARG_INT16(0);
1317  int16 arg2 = PG_GETARG_INT16(1);
1318 
1319  PG_RETURN_INT16(arg1 ^ arg2);
1320 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int42div()

Datum int42div ( PG_FUNCTION_ARGS  )

Definition at line 1068 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

1069 {
1070  int32 arg1 = PG_GETARG_INT32(0);
1071  int16 arg2 = PG_GETARG_INT16(1);
1072  int32 result;
1073 
1074  if (unlikely(arg2 == 0))
1075  {
1076  ereport(ERROR,
1077  (errcode(ERRCODE_DIVISION_BY_ZERO),
1078  errmsg("division by zero")));
1079  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1080  PG_RETURN_NULL();
1081  }
1082 
1083  /*
1084  * INT_MIN / -1 is problematic, since the result can't be represented on a
1085  * two's-complement machine. Some machines produce INT_MIN, some produce
1086  * zero, some throw an exception. We can dodge the problem by recognizing
1087  * that division by -1 is the same as negation.
1088  */
1089  if (arg2 == -1)
1090  {
1091  if (unlikely(arg1 == PG_INT32_MIN))
1092  ereport(ERROR,
1093  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1094  errmsg("integer out of range")));
1095  result = -arg1;
1096  PG_RETURN_INT32(result);
1097  }
1098 
1099  /* No overflow is possible */
1100 
1101  result = arg1 / arg2;
1102 
1103  PG_RETURN_INT32(result);
1104 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:407
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int42eq()

Datum int42eq ( PG_FUNCTION_ARGS  )

Definition at line 535 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

536 {
537  int32 arg1 = PG_GETARG_INT32(0);
538  int16 arg2 = PG_GETARG_INT16(1);
539 
540  PG_RETURN_BOOL(arg1 == arg2);
541 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int42ge()

Datum int42ge ( PG_FUNCTION_ARGS  )

Definition at line 580 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

581 {
582  int32 arg1 = PG_GETARG_INT32(0);
583  int16 arg2 = PG_GETARG_INT16(1);
584 
585  PG_RETURN_BOOL(arg1 >= arg2);
586 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int42gt()

Datum int42gt ( PG_FUNCTION_ARGS  )

Definition at line 571 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

572 {
573  int32 arg1 = PG_GETARG_INT32(0);
574  int16 arg2 = PG_GETARG_INT16(1);
575 
576  PG_RETURN_BOOL(arg1 > arg2);
577 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int42le()

Datum int42le ( PG_FUNCTION_ARGS  )

Definition at line 562 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

563 {
564  int32 arg1 = PG_GETARG_INT32(0);
565  int16 arg2 = PG_GETARG_INT16(1);
566 
567  PG_RETURN_BOOL(arg1 <= arg2);
568 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int42lt()

Datum int42lt ( PG_FUNCTION_ARGS  )

Definition at line 553 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

554 {
555  int32 arg1 = PG_GETARG_INT32(0);
556  int16 arg2 = PG_GETARG_INT16(1);
557 
558  PG_RETURN_BOOL(arg1 < arg2);
559 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int42mi()

Datum int42mi ( PG_FUNCTION_ARGS  )

Definition at line 1040 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

1041 {
1042  int32 arg1 = PG_GETARG_INT32(0);
1043  int16 arg2 = PG_GETARG_INT16(1);
1044  int32 result;
1045 
1046  if (unlikely(pg_sub_s32_overflow(arg1, (int32) arg2, &result)))
1047  ereport(ERROR,
1048  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1049  errmsg("integer out of range")));
1050  PG_RETURN_INT32(result);
1051 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:121
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int42mul()

Datum int42mul ( PG_FUNCTION_ARGS  )

Definition at line 1054 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

1055 {
1056  int32 arg1 = PG_GETARG_INT32(0);
1057  int16 arg2 = PG_GETARG_INT16(1);
1058  int32 result;
1059 
1060  if (unlikely(pg_mul_s32_overflow(arg1, (int32) arg2, &result)))
1061  ereport(ERROR,
1062  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1063  errmsg("integer out of range")));
1064  PG_RETURN_INT32(result);
1065 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:144
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int42ne()

Datum int42ne ( PG_FUNCTION_ARGS  )

Definition at line 544 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

545 {
546  int32 arg1 = PG_GETARG_INT32(0);
547  int16 arg2 = PG_GETARG_INT16(1);
548 
549  PG_RETURN_BOOL(arg1 != arg2);
550 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241

◆ int42pl()

Datum int42pl ( PG_FUNCTION_ARGS  )

Definition at line 1026 of file int.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

1027 {
1028  int32 arg1 = PG_GETARG_INT32(0);
1029  int16 arg2 = PG_GETARG_INT16(1);
1030  int32 result;
1031 
1032  if (unlikely(pg_add_s32_overflow(arg1, (int32) arg2, &result)))
1033  ereport(ERROR,
1034  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1035  errmsg("integer out of range")));
1036  PG_RETURN_INT32(result);
1037 }
signed short int16
Definition: c.h:312
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:98
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int4_bool()

Datum int4_bool ( PG_FUNCTION_ARGS  )

Definition at line 339 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

340 {
341  if (PG_GETARG_INT32(0) == 0)
342  PG_RETURN_BOOL(false);
343  else
344  PG_RETURN_BOOL(true);
345 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ int4abs()

Datum int4abs ( PG_FUNCTION_ARGS  )

Definition at line 1168 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, and unlikely.

1169 {
1170  int32 arg1 = PG_GETARG_INT32(0);
1171  int32 result;
1172 
1173  if (unlikely(arg1 == PG_INT32_MIN))
1174  ereport(ERROR,
1175  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1176  errmsg("integer out of range")));
1177  result = (arg1 < 0) ? -arg1 : arg1;
1178  PG_RETURN_INT32(result);
1179 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:407
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int4and()

Datum int4and ( PG_FUNCTION_ARGS  )

Definition at line 1243 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1244 {
1245  int32 arg1 = PG_GETARG_INT32(0);
1246  int32 arg2 = PG_GETARG_INT32(1);
1247 
1248  PG_RETURN_INT32(arg1 & arg2);
1249 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313

◆ int4div()

Datum int4div ( PG_FUNCTION_ARGS  )

Definition at line 810 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

811 {
812  int32 arg1 = PG_GETARG_INT32(0);
813  int32 arg2 = PG_GETARG_INT32(1);
814  int32 result;
815 
816  if (arg2 == 0)
817  {
818  ereport(ERROR,
819  (errcode(ERRCODE_DIVISION_BY_ZERO),
820  errmsg("division by zero")));
821  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
822  PG_RETURN_NULL();
823  }
824 
825  /*
826  * INT_MIN / -1 is problematic, since the result can't be represented on a
827  * two's-complement machine. Some machines produce INT_MIN, some produce
828  * zero, some throw an exception. We can dodge the problem by recognizing
829  * that division by -1 is the same as negation.
830  */
831  if (arg2 == -1)
832  {
833  if (unlikely(arg1 == PG_INT32_MIN))
834  ereport(ERROR,
835  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
836  errmsg("integer out of range")));
837  result = -arg1;
838  PG_RETURN_INT32(result);
839  }
840 
841  /* No overflow is possible */
842 
843  result = arg1 / arg2;
844 
845  PG_RETURN_INT32(result);
846 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:407
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int4eq()

Datum int4eq ( PG_FUNCTION_ARGS  )

Definition at line 373 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

374 {
375  int32 arg1 = PG_GETARG_INT32(0);
376  int32 arg2 = PG_GETARG_INT32(1);
377 
378  PG_RETURN_BOOL(arg1 == arg2);
379 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ int4ge()

Datum int4ge ( PG_FUNCTION_ARGS  )

Definition at line 418 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

419 {
420  int32 arg1 = PG_GETARG_INT32(0);
421  int32 arg2 = PG_GETARG_INT32(1);
422 
423  PG_RETURN_BOOL(arg1 >= arg2);
424 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ int4gt()

Datum int4gt ( PG_FUNCTION_ARGS  )

Definition at line 409 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

410 {
411  int32 arg1 = PG_GETARG_INT32(0);
412  int32 arg2 = PG_GETARG_INT32(1);
413 
414  PG_RETURN_BOOL(arg1 > arg2);
415 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ int4in()

Datum int4in ( PG_FUNCTION_ARGS  )

Definition at line 264 of file int.c.

References pg_atoi(), PG_GETARG_CSTRING, and PG_RETURN_INT32.

Referenced by inet_client_port(), inet_server_port(), and pg_stat_get_backend_client_port().

265 {
266  char *num = PG_GETARG_CSTRING(0);
267 
268  PG_RETURN_INT32(pg_atoi(num, sizeof(int32), '\0'));
269 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247
int32 pg_atoi(const char *s, int size, int c)
Definition: numutils.c:37

◆ int4inc()

Datum int4inc ( PG_FUNCTION_ARGS  )

Definition at line 849 of file int.c.

References arg, ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

850 {
852  int32 result;
853 
854  if (unlikely(pg_add_s32_overflow(arg, 1, &result)))
855  ereport(ERROR,
856  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
857  errmsg("integer out of range")));
858 
859  PG_RETURN_INT32(result);
860 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:98
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208

◆ int4larger()

Datum int4larger ( PG_FUNCTION_ARGS  )

Definition at line 1214 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1215 {
1216  int32 arg1 = PG_GETARG_INT32(0);
1217  int32 arg2 = PG_GETARG_INT32(1);
1218 
1219  PG_RETURN_INT32((arg1 > arg2) ? arg1 : arg2);
1220 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313

◆ int4le()

Datum int4le ( PG_FUNCTION_ARGS  )

Definition at line 400 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

401 {
402  int32 arg1 = PG_GETARG_INT32(0);
403  int32 arg2 = PG_GETARG_INT32(1);
404 
405  PG_RETURN_BOOL(arg1 <= arg2);
406 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ int4lt()

Datum int4lt ( PG_FUNCTION_ARGS  )

Definition at line 391 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

392 {
393  int32 arg1 = PG_GETARG_INT32(0);
394  int32 arg2 = PG_GETARG_INT32(1);
395 
396  PG_RETURN_BOOL(arg1 < arg2);
397 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ int4mi()

Datum int4mi ( PG_FUNCTION_ARGS  )

Definition at line 782 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

783 {
784  int32 arg1 = PG_GETARG_INT32(0);
785  int32 arg2 = PG_GETARG_INT32(1);
786  int32 result;
787 
788  if (unlikely(pg_sub_s32_overflow(arg1, arg2, &result)))
789  ereport(ERROR,
790  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
791  errmsg("integer out of range")));
792  PG_RETURN_INT32(result);
793 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:121
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int4mod()

Datum int4mod ( PG_FUNCTION_ARGS  )

Definition at line 1107 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

1108 {
1109  int32 arg1 = PG_GETARG_INT32(0);
1110  int32 arg2 = PG_GETARG_INT32(1);
1111 
1112  if (unlikely(arg2 == 0))
1113  {
1114  ereport(ERROR,
1115  (errcode(ERRCODE_DIVISION_BY_ZERO),
1116  errmsg("division by zero")));
1117  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1118  PG_RETURN_NULL();
1119  }
1120 
1121  /*
1122  * Some machines throw a floating-point exception for INT_MIN % -1, which
1123  * is a bit silly since the correct answer is perfectly well-defined,
1124  * namely zero.
1125  */
1126  if (arg2 == -1)
1127  PG_RETURN_INT32(0);
1128 
1129  /* No overflow is possible */
1130 
1131  PG_RETURN_INT32(arg1 % arg2);
1132 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int4mul()

Datum int4mul ( PG_FUNCTION_ARGS  )

Definition at line 796 of file int.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

797 {
798  int32 arg1 = PG_GETARG_INT32(0);
799  int32 arg2 = PG_GETARG_INT32(1);
800  int32 result;
801 
802  if (unlikely(pg_mul_s32_overflow(arg1, arg2, &result)))
803  ereport(ERROR,
804  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
805  errmsg("integer out of range")));
806  PG_RETURN_INT32(result);
807 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:144
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int4ne()

Datum int4ne ( PG_FUNCTION_ARGS  )

Definition at line 382 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

383 {
384  int32 arg1 = PG_GETARG_INT32(0);
385  int32 arg2 = PG_GETARG_INT32(1);
386 
387  PG_RETURN_BOOL(arg1 != arg2);
388 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ int4not()

Datum int4not ( PG_FUNCTION_ARGS  )

Definition at line 1288 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1289 {
1290  int32 arg1 = PG_GETARG_INT32(0);
1291 
1292  PG_RETURN_INT32(~arg1);
1293 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313

◆ int4or()

Datum int4or ( PG_FUNCTION_ARGS  )

Definition at line 1252 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1253 {
1254  int32 arg1 = PG_GETARG_INT32(0);
1255  int32 arg2 = PG_GETARG_INT32(1);
1256 
1257  PG_RETURN_INT32(arg1 | arg2);
1258 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313

◆ int4out()

Datum int4out ( PG_FUNCTION_ARGS  )

Definition at line 275 of file int.c.

References palloc(), PG_GETARG_INT32, pg_ltoa(), and PG_RETURN_CSTRING.

Referenced by int4_to_char().

276 {
277  int32 arg1 = PG_GETARG_INT32(0);
278  char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */
279 
280  pg_ltoa(arg1, result);
281  PG_RETURN_CSTRING(result);
282 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
void * palloc(Size size)
Definition: mcxt.c:924
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:132

◆ int4pl()

Datum int4pl ( PG_FUNCTION_ARGS  )

Definition at line 768 of file int.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

Referenced by int4range_canonical().

769 {
770  int32 arg1 = PG_GETARG_INT32(0);
771  int32 arg2 = PG_GETARG_INT32(1);
772  int32 result;
773 
774  if (unlikely(pg_add_s32_overflow(arg1, arg2, &result)))
775  ereport(ERROR,
776  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
777  errmsg("integer out of range")));
778  PG_RETURN_INT32(result);
779 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:98
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208

◆ int4recv()

Datum int4recv ( PG_FUNCTION_ARGS  )

Definition at line 288 of file int.c.

References buf, PG_GETARG_POINTER, PG_RETURN_INT32, and pq_getmsgint().

289 {
291 
292  PG_RETURN_INT32((int32) pq_getmsgint(buf, sizeof(int32)));
293 }
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
signed int int32
Definition: c.h:313
static char * buf
Definition: pg_test_fsync.c:67
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ int4send()

Datum int4send ( PG_FUNCTION_ARGS  )

Definition at line 299 of file int.c.

References buf, PG_GETARG_INT32, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

300 {
301  int32 arg1 = PG_GETARG_INT32(0);
303 
304  pq_begintypsend(&buf);
305  pq_sendint32(&buf, arg1);
307 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:335
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
signed int int32
Definition: c.h:313
static char * buf
Definition: pg_test_fsync.c:67

◆ int4shl()

Datum int4shl ( PG_FUNCTION_ARGS  )

Definition at line 1270 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1271 {
1272  int32 arg1 = PG_GETARG_INT32(0);
1273  int32 arg2 = PG_GETARG_INT32(1);
1274 
1275  PG_RETURN_INT32(arg1 << arg2);
1276 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313

◆ int4shr()

Datum int4shr ( PG_FUNCTION_ARGS  )

Definition at line 1279 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1280 {
1281  int32 arg1 = PG_GETARG_INT32(0);
1282  int32 arg2 = PG_GETARG_INT32(1);
1283 
1284  PG_RETURN_INT32(arg1 >> arg2);
1285 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313

◆ int4smaller()

Datum int4smaller ( PG_FUNCTION_ARGS  )

Definition at line 1223 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1224 {
1225  int32 arg1 = PG_GETARG_INT32(0);
1226  int32 arg2 = PG_GETARG_INT32(1);
1227 
1228  PG_RETURN_INT32((arg1 < arg2) ? arg1 : arg2);
1229 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313

◆ int4um()

Datum int4um ( PG_FUNCTION_ARGS  )

Definition at line 748 of file int.c.

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, and unlikely.

749 {
751 
752  if (unlikely(arg == PG_INT32_MIN))
753  ereport(ERROR,
754  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
755  errmsg("integer out of range")));
756  PG_RETURN_INT32(-arg);
757 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:407
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208

◆ int4up()

Datum int4up ( PG_FUNCTION_ARGS  )

Definition at line 760 of file int.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT32.

761 {
763 
764  PG_RETURN_INT32(arg);
765 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313
void * arg

◆ int4xor()

Datum int4xor ( PG_FUNCTION_ARGS  )

Definition at line 1261 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1262 {
1263  int32 arg1 = PG_GETARG_INT32(0);
1264  int32 arg2 = PG_GETARG_INT32(1);
1265 
1266  PG_RETURN_INT32(arg1 ^ arg2);
1267 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
signed int int32
Definition: c.h:313