PostgreSQL Source Code  git master
int.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include "catalog/pg_type.h"
#include "common/int.h"
#include "funcapi.h"
#include "libpq/pqformat.h"
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "optimizer/optimizer.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)
 
Datum generate_series_int4_support (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ Int2VectorSize

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

Definition at line 45 of file int.c.

Referenced by buildint2vector(), and int2vectorin().

Function Documentation

◆ bool_int4()

Datum bool_int4 ( PG_FUNCTION_ARGS  )

Definition at line 353 of file int.c.

References PG_GETARG_BOOL, and PG_RETURN_INT32.

354 {
355  if (PG_GETARG_BOOL(0) == false)
356  PG_RETURN_INT32(0);
357  else
358  PG_RETURN_INT32(1);
359 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269

◆ buildint2vector()

int2vector* buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 114 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().

115 {
116  int2vector *result;
117 
118  result = (int2vector *) palloc0(Int2VectorSize(n));
119 
120  if (n > 0 && int2s)
121  memcpy(result->values, int2s, n * sizeof(int16));
122 
123  /*
124  * Attach standard array header. For historical reasons, we set the index
125  * lower bound to 0 not 1.
126  */
127  SET_VARSIZE(result, Int2VectorSize(n));
128  result->ndim = 1;
129  result->dataoffset = 0; /* never any nulls */
130  result->elemtype = INT2OID;
131  result->dim1 = n;
132  result->lbound1 = 0;
133 
134  return result;
135 }
signed short int16
Definition: c.h:346
int lbound1
Definition: c.h:585
Oid elemtype
Definition: c.h:583
int32 dataoffset
Definition: c.h:582
int ndim
Definition: c.h:581
Definition: c.h:578
void * palloc0(Size size)
Definition: mcxt.c:980
int dim1
Definition: c.h:584
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:586
#define Int2VectorSize(n)
Definition: int.c:45
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329

◆ generate_series_int4()

Datum generate_series_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1357 of file int.c.

References generate_series_step_int4().

1358 {
1359  return generate_series_step_int4(fcinfo);
1360 }
Datum generate_series_step_int4(PG_FUNCTION_ARGS)
Definition: int.c:1363

◆ generate_series_int4_support()

Datum generate_series_int4_support ( PG_FUNCTION_ARGS  )

Definition at line 1439 of file int.c.

References generate_unaccent_rules::args, DatumGetInt32, estimate_expression_value(), is_funcclause(), IsA, linitial, list_length(), lsecond, lthird, SupportRequestRows::node, PG_GETARG_POINTER, PG_RETURN_POINTER, SupportRequestRows::root, and SupportRequestRows::rows.

1440 {
1441  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1442  Node *ret = NULL;
1443 
1444  if (IsA(rawreq, SupportRequestRows))
1445  {
1446  /* Try to estimate the number of rows returned */
1447  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1448 
1449  if (is_funcclause(req->node)) /* be paranoid */
1450  {
1451  List *args = ((FuncExpr *) req->node)->args;
1452  Node *arg1,
1453  *arg2,
1454  *arg3;
1455 
1456  /* We can use estimated argument values here */
1457  arg1 = estimate_expression_value(req->root, linitial(args));
1458  arg2 = estimate_expression_value(req->root, lsecond(args));
1459  if (list_length(args) >= 3)
1460  arg3 = estimate_expression_value(req->root, lthird(args));
1461  else
1462  arg3 = NULL;
1463 
1464  /*
1465  * If any argument is constant NULL, we can safely assume that
1466  * zero rows are returned. Otherwise, if they're all non-NULL
1467  * constants, we can calculate the number of rows that will be
1468  * returned. Use double arithmetic to avoid overflow hazards.
1469  */
1470  if ((IsA(arg1, Const) &&
1471  ((Const *) arg1)->constisnull) ||
1472  (IsA(arg2, Const) &&
1473  ((Const *) arg2)->constisnull) ||
1474  (arg3 != NULL && IsA(arg3, Const) &&
1475  ((Const *) arg3)->constisnull))
1476  {
1477  req->rows = 0;
1478  ret = (Node *) req;
1479  }
1480  else if (IsA(arg1, Const) &&
1481  IsA(arg2, Const) &&
1482  (arg3 == NULL || IsA(arg3, Const)))
1483  {
1484  double start,
1485  finish,
1486  step;
1487 
1488  start = DatumGetInt32(((Const *) arg1)->constvalue);
1489  finish = DatumGetInt32(((Const *) arg2)->constvalue);
1490  step = arg3 ? DatumGetInt32(((Const *) arg3)->constvalue) : 1;
1491 
1492  /* This equation works for either sign of step */
1493  if (step != 0)
1494  {
1495  req->rows = floor((finish - start + step) / step);
1496  ret = (Node *) req;
1497  }
1498  }
1499  }
1500  }
1501 
1502  PG_RETURN_POINTER(ret);
1503 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#define DatumGetInt32(X)
Definition: postgres.h:472
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2286
Definition: nodes.h:525
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define lsecond(l)
Definition: pg_list.h:200
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:56
struct PlannerInfo * root
Definition: supportnodes.h:163
#define linitial(l)
Definition: pg_list.h:195
static int list_length(const List *l)
Definition: pg_list.h:169
#define lthird(l)
Definition: pg_list.h:205
Definition: pg_list.h:50

◆ generate_series_step_int4()

Datum generate_series_step_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1363 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().

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

◆ i2toi4()

Datum i2toi4 ( PG_FUNCTION_ARGS  )

Definition at line 321 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT32.

322 {
323  int16 arg1 = PG_GETARG_INT16(0);
324 
325  PG_RETURN_INT32((int32) arg1);
326 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ i4toi2()

Datum i4toi2 ( PG_FUNCTION_ARGS  )

Definition at line 329 of file int.c.

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

330 {
331  int32 arg1 = PG_GETARG_INT32(0);
332 
333  if (unlikely(arg1 < SHRT_MIN) || unlikely(arg1 > SHRT_MAX))
334  ereport(ERROR,
335  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
336  errmsg("smallint out of range")));
337 
338  PG_RETURN_INT16((int16) arg1);
339 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ in_range_int2_int2()

Datum in_range_int2_int2 ( PG_FUNCTION_ARGS  )

Definition at line 720 of file int.c.

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

721 {
722  /* Doesn't seem worth duplicating code for, so just invoke int2_int4 */
724  PG_GETARG_DATUM(0),
725  PG_GETARG_DATUM(1),
727  PG_GETARG_DATUM(3),
728  PG_GETARG_DATUM(4));
729 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
signed int int32
Definition: c.h:347
Datum in_range_int2_int4(PG_FUNCTION_ARGS)
Definition: int.c:685
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:625
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define Int32GetDatum(X)
Definition: postgres.h:479

◆ in_range_int2_int4()

Datum in_range_int2_int4 ( PG_FUNCTION_ARGS  )

Definition at line 685 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().

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

◆ in_range_int2_int8()

Datum in_range_int2_int8 ( PG_FUNCTION_ARGS  )

Definition at line 732 of file int.c.

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

733 {
734  /* Doesn't seem worth duplicating code for, so just invoke int4_int8 */
738  PG_GETARG_DATUM(2),
739  PG_GETARG_DATUM(3),
740  PG_GETARG_DATUM(4));
741 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum in_range_int4_int8(PG_FUNCTION_ARGS)
Definition: int.c:650
signed int int32
Definition: c.h:347
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:625
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define Int32GetDatum(X)
Definition: postgres.h:479

◆ in_range_int4_int2()

Datum in_range_int4_int2 ( PG_FUNCTION_ARGS  )

Definition at line 638 of file int.c.

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

639 {
640  /* Doesn't seem worth duplicating code for, so just invoke int4_int4 */
642  PG_GETARG_DATUM(0),
643  PG_GETARG_DATUM(1),
645  PG_GETARG_DATUM(3),
646  PG_GETARG_DATUM(4));
647 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
signed int int32
Definition: c.h:347
Datum in_range_int4_int4(PG_FUNCTION_ARGS)
Definition: int.c:604
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:625
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define Int32GetDatum(X)
Definition: postgres.h:479

◆ in_range_int4_int4()

Datum in_range_int4_int4 ( PG_FUNCTION_ARGS  )

Definition at line 604 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().

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

◆ in_range_int4_int8()

Datum in_range_int4_int8 ( PG_FUNCTION_ARGS  )

Definition at line 650 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().

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

◆ int24div()

Datum int24div ( PG_FUNCTION_ARGS  )

Definition at line 1011 of file int.c.

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

1012 {
1013  int16 arg1 = PG_GETARG_INT16(0);
1014  int32 arg2 = PG_GETARG_INT32(1);
1015 
1016  if (unlikely(arg2 == 0))
1017  {
1018  ereport(ERROR,
1019  (errcode(ERRCODE_DIVISION_BY_ZERO),
1020  errmsg("division by zero")));
1021  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1022  PG_RETURN_NULL();
1023  }
1024 
1025  /* No overflow is possible */
1026  PG_RETURN_INT32((int32) arg1 / arg2);
1027 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ int24eq()

Datum int24eq ( PG_FUNCTION_ARGS  )

Definition at line 485 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

486 {
487  int16 arg1 = PG_GETARG_INT16(0);
488  int32 arg2 = PG_GETARG_INT32(1);
489 
490  PG_RETURN_BOOL(arg1 == arg2);
491 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int24ge()

Datum int24ge ( PG_FUNCTION_ARGS  )

Definition at line 530 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

531 {
532  int16 arg1 = PG_GETARG_INT16(0);
533  int32 arg2 = PG_GETARG_INT32(1);
534 
535  PG_RETURN_BOOL(arg1 >= arg2);
536 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int24gt()

Datum int24gt ( PG_FUNCTION_ARGS  )

Definition at line 521 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

522 {
523  int16 arg1 = PG_GETARG_INT16(0);
524  int32 arg2 = PG_GETARG_INT32(1);
525 
526  PG_RETURN_BOOL(arg1 > arg2);
527 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int24le()

Datum int24le ( PG_FUNCTION_ARGS  )

Definition at line 512 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

513 {
514  int16 arg1 = PG_GETARG_INT16(0);
515  int32 arg2 = PG_GETARG_INT32(1);
516 
517  PG_RETURN_BOOL(arg1 <= arg2);
518 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int24lt()

Datum int24lt ( PG_FUNCTION_ARGS  )

Definition at line 503 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

504 {
505  int16 arg1 = PG_GETARG_INT16(0);
506  int32 arg2 = PG_GETARG_INT32(1);
507 
508  PG_RETURN_BOOL(arg1 < arg2);
509 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int24mi()

Datum int24mi ( PG_FUNCTION_ARGS  )

Definition at line 983 of file int.c.

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

984 {
985  int16 arg1 = PG_GETARG_INT16(0);
986  int32 arg2 = PG_GETARG_INT32(1);
987  int32 result;
988 
989  if (unlikely(pg_sub_s32_overflow((int32) arg1, arg2, &result)))
990  ereport(ERROR,
991  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
992  errmsg("integer out of range")));
993  PG_RETURN_INT32(result);
994 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:122
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int24mul()

Datum int24mul ( PG_FUNCTION_ARGS  )

Definition at line 997 of file int.c.

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

998 {
999  int16 arg1 = PG_GETARG_INT16(0);
1000  int32 arg2 = PG_GETARG_INT32(1);
1001  int32 result;
1002 
1003  if (unlikely(pg_mul_s32_overflow((int32) arg1, arg2, &result)))
1004  ereport(ERROR,
1005  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1006  errmsg("integer out of range")));
1007  PG_RETURN_INT32(result);
1008 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:140
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int24ne()

Datum int24ne ( PG_FUNCTION_ARGS  )

Definition at line 494 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

495 {
496  int16 arg1 = PG_GETARG_INT16(0);
497  int32 arg2 = PG_GETARG_INT32(1);
498 
499  PG_RETURN_BOOL(arg1 != arg2);
500 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int24pl()

Datum int24pl ( PG_FUNCTION_ARGS  )

Definition at line 969 of file int.c.

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

970 {
971  int16 arg1 = PG_GETARG_INT16(0);
972  int32 arg2 = PG_GETARG_INT32(1);
973  int32 result;
974 
975  if (unlikely(pg_add_s32_overflow((int32) arg1, arg2, &result)))
976  ereport(ERROR,
977  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
978  errmsg("integer out of range")));
979  PG_RETURN_INT32(result);
980 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:104
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int2abs()

Datum int2abs ( PG_FUNCTION_ARGS  )

Definition at line 1186 of file int.c.

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

1187 {
1188  int16 arg1 = PG_GETARG_INT16(0);
1189  int16 result;
1190 
1191  if (unlikely(arg1 == PG_INT16_MIN))
1192  ereport(ERROR,
1193  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1194  errmsg("smallint out of range")));
1195  result = (arg1 < 0) ? -arg1 : arg1;
1196  PG_RETURN_INT16(result);
1197 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:438
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int2and()

Datum int2and ( PG_FUNCTION_ARGS  )

Definition at line 1300 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1301 {
1302  int16 arg1 = PG_GETARG_INT16(0);
1303  int16 arg2 = PG_GETARG_INT16(1);
1304 
1305  PG_RETURN_INT16(arg1 & arg2);
1306 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2div()

Datum int2div ( PG_FUNCTION_ARGS  )

Definition at line 930 of file int.c.

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

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

◆ int2eq()

Datum int2eq ( PG_FUNCTION_ARGS  )

Definition at line 431 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

432 {
433  int16 arg1 = PG_GETARG_INT16(0);
434  int16 arg2 = PG_GETARG_INT16(1);
435 
436  PG_RETURN_BOOL(arg1 == arg2);
437 }
signed short int16
Definition: c.h:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2ge()

Datum int2ge ( PG_FUNCTION_ARGS  )

Definition at line 476 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

477 {
478  int16 arg1 = PG_GETARG_INT16(0);
479  int16 arg2 = PG_GETARG_INT16(1);
480 
481  PG_RETURN_BOOL(arg1 >= arg2);
482 }
signed short int16
Definition: c.h:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2gt()

Datum int2gt ( PG_FUNCTION_ARGS  )

Definition at line 467 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

468 {
469  int16 arg1 = PG_GETARG_INT16(0);
470  int16 arg2 = PG_GETARG_INT16(1);
471 
472  PG_RETURN_BOOL(arg1 > arg2);
473 }
signed short int16
Definition: c.h:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2in()

Datum int2in ( PG_FUNCTION_ARGS  )

Definition at line 63 of file int.c.

References PG_GETARG_CSTRING, PG_RETURN_INT16, and pg_strtoint16().

64 {
65  char *num = PG_GETARG_CSTRING(0);
66 
68 }
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int16 pg_strtoint16(const char *s)
Definition: numutils.c:123
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272

◆ int2larger()

Datum int2larger ( PG_FUNCTION_ARGS  )

Definition at line 1200 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1201 {
1202  int16 arg1 = PG_GETARG_INT16(0);
1203  int16 arg2 = PG_GETARG_INT16(1);
1204 
1205  PG_RETURN_INT16((arg1 > arg2) ? arg1 : arg2);
1206 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2le()

Datum int2le ( PG_FUNCTION_ARGS  )

Definition at line 458 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

459 {
460  int16 arg1 = PG_GETARG_INT16(0);
461  int16 arg2 = PG_GETARG_INT16(1);
462 
463  PG_RETURN_BOOL(arg1 <= arg2);
464 }
signed short int16
Definition: c.h:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2lt()

Datum int2lt ( PG_FUNCTION_ARGS  )

Definition at line 449 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

450 {
451  int16 arg1 = PG_GETARG_INT16(0);
452  int16 arg2 = PG_GETARG_INT16(1);
453 
454  PG_RETURN_BOOL(arg1 < arg2);
455 }
signed short int16
Definition: c.h:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2mi()

Datum int2mi ( PG_FUNCTION_ARGS  )

Definition at line 901 of file int.c.

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

902 {
903  int16 arg1 = PG_GETARG_INT16(0);
904  int16 arg2 = PG_GETARG_INT16(1);
905  int16 result;
906 
907  if (unlikely(pg_sub_s16_overflow(arg1, arg2, &result)))
908  ereport(ERROR,
909  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
910  errmsg("smallint out of range")));
911  PG_RETURN_INT16(result);
912 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static bool pg_sub_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:65
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int2mod()

Datum int2mod ( PG_FUNCTION_ARGS  )

Definition at line 1139 of file int.c.

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

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

◆ int2mul()

Datum int2mul ( PG_FUNCTION_ARGS  )

Definition at line 915 of file int.c.

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

916 {
917  int16 arg1 = PG_GETARG_INT16(0);
918  int16 arg2 = PG_GETARG_INT16(1);
919  int16 result;
920 
921  if (unlikely(pg_mul_s16_overflow(arg1, arg2, &result)))
922  ereport(ERROR,
923  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
924  errmsg("smallint out of range")));
925 
926  PG_RETURN_INT16(result);
927 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:608
static bool pg_mul_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:83
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int2ne()

Datum int2ne ( PG_FUNCTION_ARGS  )

Definition at line 440 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_BOOL.

441 {
442  int16 arg1 = PG_GETARG_INT16(0);
443  int16 arg2 = PG_GETARG_INT16(1);
444 
445  PG_RETURN_BOOL(arg1 != arg2);
446 }
signed short int16
Definition: c.h:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2not()

Datum int2not ( PG_FUNCTION_ARGS  )

Definition at line 1327 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1328 {
1329  int16 arg1 = PG_GETARG_INT16(0);
1330 
1331  PG_RETURN_INT16(~arg1);
1332 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2or()

Datum int2or ( PG_FUNCTION_ARGS  )

Definition at line 1309 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1310 {
1311  int16 arg1 = PG_GETARG_INT16(0);
1312  int16 arg2 = PG_GETARG_INT16(1);
1313 
1314  PG_RETURN_INT16(arg1 | arg2);
1315 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2out()

Datum int2out ( PG_FUNCTION_ARGS  )

Definition at line 74 of file int.c.

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

75 {
76  int16 arg1 = PG_GETARG_INT16(0);
77  char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */
78 
79  pg_itoa(arg1, result);
80  PG_RETURN_CSTRING(result);
81 }
signed short int16
Definition: c.h:346
void pg_itoa(int16 i, char *a)
Definition: numutils.c:273
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
void * palloc(Size size)
Definition: mcxt.c:949

◆ int2pl()

Datum int2pl ( PG_FUNCTION_ARGS  )

Definition at line 887 of file int.c.

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

888 {
889  int16 arg1 = PG_GETARG_INT16(0);
890  int16 arg2 = PG_GETARG_INT16(1);
891  int16 result;
892 
893  if (unlikely(pg_add_s16_overflow(arg1, arg2, &result)))
894  ereport(ERROR,
895  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
896  errmsg("smallint out of range")));
897  PG_RETURN_INT16(result);
898 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:608
static bool pg_add_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:47
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int2recv()

Datum int2recv ( PG_FUNCTION_ARGS  )

Definition at line 87 of file int.c.

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

88 {
90 
91  PG_RETURN_INT16((int16) pq_getmsgint(buf, sizeof(int16)));
92 }
signed short int16
Definition: c.h:346
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
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 98 of file int.c.

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

99 {
100  int16 arg1 = PG_GETARG_INT16(0);
102 
103  pq_begintypsend(&buf);
104  pq_sendint16(&buf, arg1);
106 }
signed short int16
Definition: c.h:346
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:360
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:266

◆ int2shl()

Datum int2shl ( PG_FUNCTION_ARGS  )

Definition at line 1336 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

1337 {
1338  int16 arg1 = PG_GETARG_INT16(0);
1339  int32 arg2 = PG_GETARG_INT32(1);
1340 
1341  PG_RETURN_INT16(arg1 << arg2);
1342 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
signed int int32
Definition: c.h:347
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2shr()

Datum int2shr ( PG_FUNCTION_ARGS  )

Definition at line 1345 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

1346 {
1347  int16 arg1 = PG_GETARG_INT16(0);
1348  int32 arg2 = PG_GETARG_INT32(1);
1349 
1350  PG_RETURN_INT16(arg1 >> arg2);
1351 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
signed int int32
Definition: c.h:347
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2smaller()

Datum int2smaller ( PG_FUNCTION_ARGS  )

Definition at line 1209 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1210 {
1211  int16 arg1 = PG_GETARG_INT16(0);
1212  int16 arg2 = PG_GETARG_INT16(1);
1213 
1214  PG_RETURN_INT16((arg1 < arg2) ? arg1 : arg2);
1215 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int2um()

Datum int2um ( PG_FUNCTION_ARGS  )

Definition at line 867 of file int.c.

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

868 {
870 
871  if (unlikely(arg == PG_INT16_MIN))
872  ereport(ERROR,
873  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
874  errmsg("smallint out of range")));
875  PG_RETURN_INT16(-arg);
876 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:438
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
void * arg
#define unlikely(x)
Definition: c.h:208

◆ int2up()

Datum int2up ( PG_FUNCTION_ARGS  )

Definition at line 879 of file int.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT16.

880 {
882 
883  PG_RETURN_INT16(arg);
884 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
void * arg

◆ int2vectorin()

Datum int2vectorin ( PG_FUNCTION_ARGS  )

Definition at line 141 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.

142 {
143  char *intString = PG_GETARG_CSTRING(0);
144  int2vector *result;
145  int n;
146 
148 
149  for (n = 0; *intString && n < FUNC_MAX_ARGS; n++)
150  {
151  while (*intString && isspace((unsigned char) *intString))
152  intString++;
153  if (*intString == '\0')
154  break;
155  result->values[n] = pg_atoi(intString, sizeof(int16), ' ');
156  while (*intString && !isspace((unsigned char) *intString))
157  intString++;
158  }
159  while (*intString && isspace((unsigned char) *intString))
160  intString++;
161  if (*intString)
162  ereport(ERROR,
163  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
164  errmsg("int2vector has too many elements")));
165 
166  SET_VARSIZE(result, Int2VectorSize(n));
167  result->ndim = 1;
168  result->dataoffset = 0; /* never any nulls */
169  result->elemtype = INT2OID;
170  result->dim1 = n;
171  result->lbound1 = 0;
172 
173  PG_RETURN_POINTER(result);
174 }
signed short int16
Definition: c.h:346
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
int lbound1
Definition: c.h:585
int errcode(int sqlerrcode)
Definition: elog.c:608
Oid elemtype
Definition: c.h:583
#define FUNC_MAX_ARGS
int32 dataoffset
Definition: c.h:582
#define ERROR
Definition: elog.h:43
int ndim
Definition: c.h:581
#define ereport(elevel, rest)
Definition: elog.h:141
Definition: c.h:578
void * palloc0(Size size)
Definition: mcxt.c:980
int dim1
Definition: c.h:584
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:586
#define Int2VectorSize(n)
Definition: int.c:45
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
int32 pg_atoi(const char *s, int size, int c)
Definition: numutils.c:38

◆ int2vectorout()

Datum int2vectorout ( PG_FUNCTION_ARGS  )

Definition at line 180 of file int.c.

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

181 {
182  int2vector *int2Array = (int2vector *) PG_GETARG_POINTER(0);
183  int num,
184  nnums = int2Array->dim1;
185  char *rp;
186  char *result;
187 
188  /* assumes sign, 5 digits, ' ' */
189  rp = result = (char *) palloc(nnums * 7 + 1);
190  for (num = 0; num < nnums; num++)
191  {
192  if (num != 0)
193  *rp++ = ' ';
194  pg_itoa(int2Array->values[num], rp);
195  while (*++rp != '\0')
196  ;
197  }
198  *rp = '\0';
199  PG_RETURN_CSTRING(result);
200 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
void pg_itoa(int16 i, char *a)
Definition: numutils.c:273
Definition: c.h:578
int dim1
Definition: c.h:584
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:586
void * palloc(Size size)
Definition: mcxt.c:949

◆ int2vectorrecv()

Datum int2vectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 206 of file int.c.

References ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, array_recv(), Assert, buf, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum, PG_GETARG_POINTER, PG_RETURN_POINTER, and PointerGetDatum.

207 {
208  LOCAL_FCINFO(locfcinfo, 3);
210  int2vector *result;
211 
212  /*
213  * Normally one would call array_recv() using DirectFunctionCall3, but
214  * that does not work since array_recv wants to cache some data using
215  * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
216  * parameter.
217  */
218  InitFunctionCallInfoData(*locfcinfo, fcinfo->flinfo, 3,
219  InvalidOid, NULL, NULL);
220 
221  locfcinfo->args[0].value = PointerGetDatum(buf);
222  locfcinfo->args[0].isnull = false;
223  locfcinfo->args[1].value = ObjectIdGetDatum(INT2OID);
224  locfcinfo->args[1].isnull = false;
225  locfcinfo->args[2].value = Int32GetDatum(-1);
226  locfcinfo->args[2].isnull = false;
227 
228  result = (int2vector *) DatumGetPointer(array_recv(locfcinfo));
229 
230  Assert(!locfcinfo->isnull);
231 
232  /* sanity checks: int2vector must be 1-D, 0-based, no nulls */
233  if (ARR_NDIM(result) != 1 ||
234  ARR_HASNULL(result) ||
235  ARR_ELEMTYPE(result) != INT2OID ||
236  ARR_LBOUND(result)[0] != 0)
237  ereport(ERROR,
238  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
239  errmsg("invalid int2vector data")));
240 
241  /* check length for consistency with int2vectorin() */
242  if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS)
243  ereport(ERROR,
244  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
245  errmsg("oidvector has too many elements")));
246 
247  PG_RETURN_POINTER(result);
248 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PointerGetDatum(X)
Definition: postgres.h:556
StringInfoData * StringInfo
Definition: stringinfo.h:44
int errcode(int sqlerrcode)
Definition: elog.c:608
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
Datum array_recv(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1267
#define ARR_LBOUND(a)
Definition: array.h:284
#define FUNC_MAX_ARGS
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:282
static char * buf
Definition: pg_test_fsync.c:67
#define ARR_HASNULL(a)
Definition: array.h:279
#define ereport(elevel, rest)
Definition: elog.h:141
Definition: c.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define Assert(condition)
Definition: c.h:733
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define ARR_NDIM(a)
Definition: array.h:278
#define DatumGetPointer(X)
Definition: postgres.h:549
#define Int32GetDatum(X)
Definition: postgres.h:479
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ int2vectorsend()

Datum int2vectorsend ( PG_FUNCTION_ARGS  )

Definition at line 254 of file int.c.

References array_send().

255 {
256  return array_send(fcinfo);
257 }
Datum array_send(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1547

◆ int2xor()

Datum int2xor ( PG_FUNCTION_ARGS  )

Definition at line 1318 of file int.c.

References PG_GETARG_INT16, and PG_RETURN_INT16.

1319 {
1320  int16 arg1 = PG_GETARG_INT16(0);
1321  int16 arg2 = PG_GETARG_INT16(1);
1322 
1323  PG_RETURN_INT16(arg1 ^ arg2);
1324 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int42div()

Datum int42div ( PG_FUNCTION_ARGS  )

Definition at line 1072 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.

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

◆ int42eq()

Datum int42eq ( PG_FUNCTION_ARGS  )

Definition at line 539 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

540 {
541  int32 arg1 = PG_GETARG_INT32(0);
542  int16 arg2 = PG_GETARG_INT16(1);
543 
544  PG_RETURN_BOOL(arg1 == arg2);
545 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int42ge()

Datum int42ge ( PG_FUNCTION_ARGS  )

Definition at line 584 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

585 {
586  int32 arg1 = PG_GETARG_INT32(0);
587  int16 arg2 = PG_GETARG_INT16(1);
588 
589  PG_RETURN_BOOL(arg1 >= arg2);
590 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int42gt()

Datum int42gt ( PG_FUNCTION_ARGS  )

Definition at line 575 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

576 {
577  int32 arg1 = PG_GETARG_INT32(0);
578  int16 arg2 = PG_GETARG_INT16(1);
579 
580  PG_RETURN_BOOL(arg1 > arg2);
581 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int42le()

Datum int42le ( PG_FUNCTION_ARGS  )

Definition at line 566 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

567 {
568  int32 arg1 = PG_GETARG_INT32(0);
569  int16 arg2 = PG_GETARG_INT16(1);
570 
571  PG_RETURN_BOOL(arg1 <= arg2);
572 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int42lt()

Datum int42lt ( PG_FUNCTION_ARGS  )

Definition at line 557 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

558 {
559  int32 arg1 = PG_GETARG_INT32(0);
560  int16 arg2 = PG_GETARG_INT16(1);
561 
562  PG_RETURN_BOOL(arg1 < arg2);
563 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int42mi()

Datum int42mi ( PG_FUNCTION_ARGS  )

Definition at line 1044 of file int.c.

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

1045 {
1046  int32 arg1 = PG_GETARG_INT32(0);
1047  int16 arg2 = PG_GETARG_INT16(1);
1048  int32 result;
1049 
1050  if (unlikely(pg_sub_s32_overflow(arg1, (int32) arg2, &result)))
1051  ereport(ERROR,
1052  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1053  errmsg("integer out of range")));
1054  PG_RETURN_INT32(result);
1055 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:122
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int42mul()

Datum int42mul ( PG_FUNCTION_ARGS  )

Definition at line 1058 of file int.c.

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

1059 {
1060  int32 arg1 = PG_GETARG_INT32(0);
1061  int16 arg2 = PG_GETARG_INT16(1);
1062  int32 result;
1063 
1064  if (unlikely(pg_mul_s32_overflow(arg1, (int32) arg2, &result)))
1065  ereport(ERROR,
1066  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1067  errmsg("integer out of range")));
1068  PG_RETURN_INT32(result);
1069 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:140
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int42ne()

Datum int42ne ( PG_FUNCTION_ARGS  )

Definition at line 548 of file int.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

549 {
550  int32 arg1 = PG_GETARG_INT32(0);
551  int16 arg2 = PG_GETARG_INT16(1);
552 
553  PG_RETURN_BOOL(arg1 != arg2);
554 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ int42pl()

Datum int42pl ( PG_FUNCTION_ARGS  )

Definition at line 1030 of file int.c.

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

1031 {
1032  int32 arg1 = PG_GETARG_INT32(0);
1033  int16 arg2 = PG_GETARG_INT16(1);
1034  int32 result;
1035 
1036  if (unlikely(pg_add_s32_overflow(arg1, (int32) arg2, &result)))
1037  ereport(ERROR,
1038  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1039  errmsg("integer out of range")));
1040  PG_RETURN_INT32(result);
1041 }
signed short int16
Definition: c.h:346
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:104
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int4_bool()

Datum int4_bool ( PG_FUNCTION_ARGS  )

Definition at line 343 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

344 {
345  if (PG_GETARG_INT32(0) == 0)
346  PG_RETURN_BOOL(false);
347  else
348  PG_RETURN_BOOL(true);
349 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ int4abs()

Datum int4abs ( PG_FUNCTION_ARGS  )

Definition at line 1172 of file int.c.

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

1173 {
1174  int32 arg1 = PG_GETARG_INT32(0);
1175  int32 result;
1176 
1177  if (unlikely(arg1 == PG_INT32_MIN))
1178  ereport(ERROR,
1179  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1180  errmsg("integer out of range")));
1181  result = (arg1 < 0) ? -arg1 : arg1;
1182  PG_RETURN_INT32(result);
1183 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:441
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int4and()

Datum int4and ( PG_FUNCTION_ARGS  )

Definition at line 1247 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1248 {
1249  int32 arg1 = PG_GETARG_INT32(0);
1250  int32 arg2 = PG_GETARG_INT32(1);
1251 
1252  PG_RETURN_INT32(arg1 & arg2);
1253 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347

◆ int4div()

Datum int4div ( PG_FUNCTION_ARGS  )

Definition at line 814 of file int.c.

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

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

◆ int4eq()

Datum int4eq ( PG_FUNCTION_ARGS  )

Definition at line 377 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

378 {
379  int32 arg1 = PG_GETARG_INT32(0);
380  int32 arg2 = PG_GETARG_INT32(1);
381 
382  PG_RETURN_BOOL(arg1 == arg2);
383 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ int4ge()

Datum int4ge ( PG_FUNCTION_ARGS  )

Definition at line 422 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

423 {
424  int32 arg1 = PG_GETARG_INT32(0);
425  int32 arg2 = PG_GETARG_INT32(1);
426 
427  PG_RETURN_BOOL(arg1 >= arg2);
428 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ int4gt()

Datum int4gt ( PG_FUNCTION_ARGS  )

Definition at line 413 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

414 {
415  int32 arg1 = PG_GETARG_INT32(0);
416  int32 arg2 = PG_GETARG_INT32(1);
417 
418  PG_RETURN_BOOL(arg1 > arg2);
419 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ int4in()

Datum int4in ( PG_FUNCTION_ARGS  )

Definition at line 268 of file int.c.

References PG_GETARG_CSTRING, PG_RETURN_INT32, and pg_strtoint32().

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

269 {
270  char *num = PG_GETARG_CSTRING(0);
271 
273 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int32 pg_strtoint32(const char *s)
Definition: numutils.c:199
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272

◆ int4inc()

Datum int4inc ( PG_FUNCTION_ARGS  )

Definition at line 853 of file int.c.

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

854 {
856  int32 result;
857 
858  if (unlikely(pg_add_s32_overflow(arg, 1, &result)))
859  ereport(ERROR,
860  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
861  errmsg("integer out of range")));
862 
863  PG_RETURN_INT32(result);
864 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:104
int errmsg(const char *fmt,...)
Definition: elog.c:822
void * arg
#define unlikely(x)
Definition: c.h:208

◆ int4larger()

Datum int4larger ( PG_FUNCTION_ARGS  )

Definition at line 1218 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1219 {
1220  int32 arg1 = PG_GETARG_INT32(0);
1221  int32 arg2 = PG_GETARG_INT32(1);
1222 
1223  PG_RETURN_INT32((arg1 > arg2) ? arg1 : arg2);
1224 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347

◆ int4le()

Datum int4le ( PG_FUNCTION_ARGS  )

Definition at line 404 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

405 {
406  int32 arg1 = PG_GETARG_INT32(0);
407  int32 arg2 = PG_GETARG_INT32(1);
408 
409  PG_RETURN_BOOL(arg1 <= arg2);
410 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ int4lt()

Datum int4lt ( PG_FUNCTION_ARGS  )

Definition at line 395 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

396 {
397  int32 arg1 = PG_GETARG_INT32(0);
398  int32 arg2 = PG_GETARG_INT32(1);
399 
400  PG_RETURN_BOOL(arg1 < arg2);
401 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ int4mi()

Datum int4mi ( PG_FUNCTION_ARGS  )

Definition at line 786 of file int.c.

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

787 {
788  int32 arg1 = PG_GETARG_INT32(0);
789  int32 arg2 = PG_GETARG_INT32(1);
790  int32 result;
791 
792  if (unlikely(pg_sub_s32_overflow(arg1, arg2, &result)))
793  ereport(ERROR,
794  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
795  errmsg("integer out of range")));
796  PG_RETURN_INT32(result);
797 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:122
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int4mod()

Datum int4mod ( PG_FUNCTION_ARGS  )

Definition at line 1111 of file int.c.

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

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

◆ int4mul()

Datum int4mul ( PG_FUNCTION_ARGS  )

Definition at line 800 of file int.c.

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

801 {
802  int32 arg1 = PG_GETARG_INT32(0);
803  int32 arg2 = PG_GETARG_INT32(1);
804  int32 result;
805 
806  if (unlikely(pg_mul_s32_overflow(arg1, arg2, &result)))
807  ereport(ERROR,
808  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
809  errmsg("integer out of range")));
810  PG_RETURN_INT32(result);
811 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:140
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int4ne()

Datum int4ne ( PG_FUNCTION_ARGS  )

Definition at line 386 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_BOOL.

387 {
388  int32 arg1 = PG_GETARG_INT32(0);
389  int32 arg2 = PG_GETARG_INT32(1);
390 
391  PG_RETURN_BOOL(arg1 != arg2);
392 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ int4not()

Datum int4not ( PG_FUNCTION_ARGS  )

Definition at line 1292 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1293 {
1294  int32 arg1 = PG_GETARG_INT32(0);
1295 
1296  PG_RETURN_INT32(~arg1);
1297 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347

◆ int4or()

Datum int4or ( PG_FUNCTION_ARGS  )

Definition at line 1256 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1257 {
1258  int32 arg1 = PG_GETARG_INT32(0);
1259  int32 arg2 = PG_GETARG_INT32(1);
1260 
1261  PG_RETURN_INT32(arg1 | arg2);
1262 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347

◆ int4out()

Datum int4out ( PG_FUNCTION_ARGS  )

Definition at line 279 of file int.c.

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

Referenced by int4_to_char().

280 {
281  int32 arg1 = PG_GETARG_INT32(0);
282  char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */
283 
284  pg_ltoa(arg1, result);
285  PG_RETURN_CSTRING(result);
286 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:347
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
void * palloc(Size size)
Definition: mcxt.c:949
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:285

◆ int4pl()

Datum int4pl ( PG_FUNCTION_ARGS  )

Definition at line 772 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().

773 {
774  int32 arg1 = PG_GETARG_INT32(0);
775  int32 arg2 = PG_GETARG_INT32(1);
776  int32 result;
777 
778  if (unlikely(pg_add_s32_overflow(arg1, arg2, &result)))
779  ereport(ERROR,
780  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
781  errmsg("integer out of range")));
782  PG_RETURN_INT32(result);
783 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:104
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208

◆ int4recv()

Datum int4recv ( PG_FUNCTION_ARGS  )

Definition at line 292 of file int.c.

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

293 {
295 
296  PG_RETURN_INT32((int32) pq_getmsgint(buf, sizeof(int32)));
297 }
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
signed int int32
Definition: c.h:347
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 303 of file int.c.

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

304 {
305  int32 arg1 = PG_GETARG_INT32(0);
307 
308  pq_begintypsend(&buf);
309  pq_sendint32(&buf, arg1);
311 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:360
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
signed int int32
Definition: c.h:347
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static char * buf
Definition: pg_test_fsync.c:67

◆ int4shl()

Datum int4shl ( PG_FUNCTION_ARGS  )

Definition at line 1274 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1275 {
1276  int32 arg1 = PG_GETARG_INT32(0);
1277  int32 arg2 = PG_GETARG_INT32(1);
1278 
1279  PG_RETURN_INT32(arg1 << arg2);
1280 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347

◆ int4shr()

Datum int4shr ( PG_FUNCTION_ARGS  )

Definition at line 1283 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1284 {
1285  int32 arg1 = PG_GETARG_INT32(0);
1286  int32 arg2 = PG_GETARG_INT32(1);
1287 
1288  PG_RETURN_INT32(arg1 >> arg2);
1289 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347

◆ int4smaller()

Datum int4smaller ( PG_FUNCTION_ARGS  )

Definition at line 1227 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1228 {
1229  int32 arg1 = PG_GETARG_INT32(0);
1230  int32 arg2 = PG_GETARG_INT32(1);
1231 
1232  PG_RETURN_INT32((arg1 < arg2) ? arg1 : arg2);
1233 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347

◆ int4um()

Datum int4um ( PG_FUNCTION_ARGS  )

Definition at line 752 of file int.c.

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

753 {
755 
756  if (unlikely(arg == PG_INT32_MIN))
757  ereport(ERROR,
758  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
759  errmsg("integer out of range")));
760  PG_RETURN_INT32(-arg);
761 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:441
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
void * arg
#define unlikely(x)
Definition: c.h:208

◆ int4up()

Datum int4up ( PG_FUNCTION_ARGS  )

Definition at line 764 of file int.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT32.

765 {
767 
768  PG_RETURN_INT32(arg);
769 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347
void * arg

◆ int4xor()

Datum int4xor ( PG_FUNCTION_ARGS  )

Definition at line 1265 of file int.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

1266 {
1267  int32 arg1 = PG_GETARG_INT32(0);
1268  int32 arg2 = PG_GETARG_INT32(1);
1269 
1270  PG_RETURN_INT32(arg1 ^ arg2);
1271 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347