PostgreSQL Source Code  git master
int8.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <math.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/builtins.h"
#include "utils/int8.h"
Include dependency graph for int8.c:

Go to the source code of this file.

Data Structures

struct  generate_series_fctx
 

Functions

bool scanint8 (const char *str, bool errorOK, int64 *result)
 
Datum int8in (PG_FUNCTION_ARGS)
 
Datum int8out (PG_FUNCTION_ARGS)
 
Datum int8recv (PG_FUNCTION_ARGS)
 
Datum int8send (PG_FUNCTION_ARGS)
 
Datum int8eq (PG_FUNCTION_ARGS)
 
Datum int8ne (PG_FUNCTION_ARGS)
 
Datum int8lt (PG_FUNCTION_ARGS)
 
Datum int8gt (PG_FUNCTION_ARGS)
 
Datum int8le (PG_FUNCTION_ARGS)
 
Datum int8ge (PG_FUNCTION_ARGS)
 
Datum int84eq (PG_FUNCTION_ARGS)
 
Datum int84ne (PG_FUNCTION_ARGS)
 
Datum int84lt (PG_FUNCTION_ARGS)
 
Datum int84gt (PG_FUNCTION_ARGS)
 
Datum int84le (PG_FUNCTION_ARGS)
 
Datum int84ge (PG_FUNCTION_ARGS)
 
Datum int48eq (PG_FUNCTION_ARGS)
 
Datum int48ne (PG_FUNCTION_ARGS)
 
Datum int48lt (PG_FUNCTION_ARGS)
 
Datum int48gt (PG_FUNCTION_ARGS)
 
Datum int48le (PG_FUNCTION_ARGS)
 
Datum int48ge (PG_FUNCTION_ARGS)
 
Datum int82eq (PG_FUNCTION_ARGS)
 
Datum int82ne (PG_FUNCTION_ARGS)
 
Datum int82lt (PG_FUNCTION_ARGS)
 
Datum int82gt (PG_FUNCTION_ARGS)
 
Datum int82le (PG_FUNCTION_ARGS)
 
Datum int82ge (PG_FUNCTION_ARGS)
 
Datum int28eq (PG_FUNCTION_ARGS)
 
Datum int28ne (PG_FUNCTION_ARGS)
 
Datum int28lt (PG_FUNCTION_ARGS)
 
Datum int28gt (PG_FUNCTION_ARGS)
 
Datum int28le (PG_FUNCTION_ARGS)
 
Datum int28ge (PG_FUNCTION_ARGS)
 
Datum in_range_int8_int8 (PG_FUNCTION_ARGS)
 
Datum int8um (PG_FUNCTION_ARGS)
 
Datum int8up (PG_FUNCTION_ARGS)
 
Datum int8pl (PG_FUNCTION_ARGS)
 
Datum int8mi (PG_FUNCTION_ARGS)
 
Datum int8mul (PG_FUNCTION_ARGS)
 
Datum int8div (PG_FUNCTION_ARGS)
 
Datum int8abs (PG_FUNCTION_ARGS)
 
Datum int8mod (PG_FUNCTION_ARGS)
 
static int64 int8gcd_internal (int64 arg1, int64 arg2)
 
Datum int8gcd (PG_FUNCTION_ARGS)
 
Datum int8lcm (PG_FUNCTION_ARGS)
 
Datum int8inc (PG_FUNCTION_ARGS)
 
Datum int8dec (PG_FUNCTION_ARGS)
 
Datum int8inc_any (PG_FUNCTION_ARGS)
 
Datum int8inc_float8_float8 (PG_FUNCTION_ARGS)
 
Datum int8dec_any (PG_FUNCTION_ARGS)
 
Datum int8larger (PG_FUNCTION_ARGS)
 
Datum int8smaller (PG_FUNCTION_ARGS)
 
Datum int84pl (PG_FUNCTION_ARGS)
 
Datum int84mi (PG_FUNCTION_ARGS)
 
Datum int84mul (PG_FUNCTION_ARGS)
 
Datum int84div (PG_FUNCTION_ARGS)
 
Datum int48pl (PG_FUNCTION_ARGS)
 
Datum int48mi (PG_FUNCTION_ARGS)
 
Datum int48mul (PG_FUNCTION_ARGS)
 
Datum int48div (PG_FUNCTION_ARGS)
 
Datum int82pl (PG_FUNCTION_ARGS)
 
Datum int82mi (PG_FUNCTION_ARGS)
 
Datum int82mul (PG_FUNCTION_ARGS)
 
Datum int82div (PG_FUNCTION_ARGS)
 
Datum int28pl (PG_FUNCTION_ARGS)
 
Datum int28mi (PG_FUNCTION_ARGS)
 
Datum int28mul (PG_FUNCTION_ARGS)
 
Datum int28div (PG_FUNCTION_ARGS)
 
Datum int8and (PG_FUNCTION_ARGS)
 
Datum int8or (PG_FUNCTION_ARGS)
 
Datum int8xor (PG_FUNCTION_ARGS)
 
Datum int8not (PG_FUNCTION_ARGS)
 
Datum int8shl (PG_FUNCTION_ARGS)
 
Datum int8shr (PG_FUNCTION_ARGS)
 
Datum int48 (PG_FUNCTION_ARGS)
 
Datum int84 (PG_FUNCTION_ARGS)
 
Datum int28 (PG_FUNCTION_ARGS)
 
Datum int82 (PG_FUNCTION_ARGS)
 
Datum i8tod (PG_FUNCTION_ARGS)
 
Datum dtoi8 (PG_FUNCTION_ARGS)
 
Datum i8tof (PG_FUNCTION_ARGS)
 
Datum ftoi8 (PG_FUNCTION_ARGS)
 
Datum i8tooid (PG_FUNCTION_ARGS)
 
Datum oidtoi8 (PG_FUNCTION_ARGS)
 
Datum generate_series_int8 (PG_FUNCTION_ARGS)
 
Datum generate_series_step_int8 (PG_FUNCTION_ARGS)
 
Datum generate_series_int8_support (PG_FUNCTION_ARGS)
 

Function Documentation

◆ dtoi8()

Datum dtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1333 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, FLOAT8_FITS_IN_INT64, PG_GETARG_FLOAT8, PG_RETURN_INT64, and unlikely.

Referenced by int8_to_char().

1334 {
1335  float8 num = PG_GETARG_FLOAT8(0);
1336 
1337  /*
1338  * Get rid of any fractional part in the input. This is so we don't fail
1339  * on just-out-of-range values that would round into range. Note
1340  * assumption that rint() will pass through a NaN or Inf unchanged.
1341  */
1342  num = rint(num);
1343 
1344  /* Range check */
1345  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT64(num)))
1346  ereport(ERROR,
1347  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1348  errmsg("bigint out of range")));
1349 
1350  PG_RETURN_INT64((int64) num);
1351 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:491
#define FLOAT8_FITS_IN_INT64(num)
Definition: c.h:1070
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ ftoi8()

Datum ftoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1368 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, FLOAT4_FITS_IN_INT64, PG_GETARG_FLOAT4, PG_RETURN_INT64, and unlikely.

1369 {
1370  float4 num = PG_GETARG_FLOAT4(0);
1371 
1372  /*
1373  * Get rid of any fractional part in the input. This is so we don't fail
1374  * on just-out-of-range values that would round into range. Note
1375  * assumption that rint() will pass through a NaN or Inf unchanged.
1376  */
1377  num = rint(num);
1378 
1379  /* Range check */
1380  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT64(num)))
1381  ereport(ERROR,
1382  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1383  errmsg("bigint out of range")));
1384 
1385  PG_RETURN_INT64((int64) num);
1386 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:490
#define FLOAT4_FITS_IN_INT64(num)
Definition: c.h:1064
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ generate_series_int8()

Datum generate_series_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1413 of file int8.c.

References generate_series_step_int8().

1414 {
1415  return generate_series_step_int8(fcinfo);
1416 }
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1419

◆ generate_series_int8_support()

Datum generate_series_int8_support ( PG_FUNCTION_ARGS  )

Definition at line 1495 of file int8.c.

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

1496 {
1497  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1498  Node *ret = NULL;
1499 
1500  if (IsA(rawreq, SupportRequestRows))
1501  {
1502  /* Try to estimate the number of rows returned */
1503  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1504 
1505  if (is_funcclause(req->node)) /* be paranoid */
1506  {
1507  List *args = ((FuncExpr *) req->node)->args;
1508  Node *arg1,
1509  *arg2,
1510  *arg3;
1511 
1512  /* We can use estimated argument values here */
1513  arg1 = estimate_expression_value(req->root, linitial(args));
1514  arg2 = estimate_expression_value(req->root, lsecond(args));
1515  if (list_length(args) >= 3)
1516  arg3 = estimate_expression_value(req->root, lthird(args));
1517  else
1518  arg3 = NULL;
1519 
1520  /*
1521  * If any argument is constant NULL, we can safely assume that
1522  * zero rows are returned. Otherwise, if they're all non-NULL
1523  * constants, we can calculate the number of rows that will be
1524  * returned. Use double arithmetic to avoid overflow hazards.
1525  */
1526  if ((IsA(arg1, Const) &&
1527  ((Const *) arg1)->constisnull) ||
1528  (IsA(arg2, Const) &&
1529  ((Const *) arg2)->constisnull) ||
1530  (arg3 != NULL && IsA(arg3, Const) &&
1531  ((Const *) arg3)->constisnull))
1532  {
1533  req->rows = 0;
1534  ret = (Node *) req;
1535  }
1536  else if (IsA(arg1, Const) &&
1537  IsA(arg2, Const) &&
1538  (arg3 == NULL || IsA(arg3, Const)))
1539  {
1540  double start,
1541  finish,
1542  step;
1543 
1544  start = DatumGetInt64(((Const *) arg1)->constvalue);
1545  finish = DatumGetInt64(((Const *) arg2)->constvalue);
1546  step = arg3 ? DatumGetInt64(((Const *) arg3)->constvalue) : 1;
1547 
1548  /* This equation works for either sign of step */
1549  if (step != 0)
1550  {
1551  req->rows = floor((finish - start + step) / step);
1552  ret = (Node *) req;
1553  }
1554  }
1555  }
1556  }
1557 
1558  PG_RETURN_POINTER(ret);
1559 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2288
Definition: nodes.h:529
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#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
#define DatumGetInt64(X)
Definition: postgres.h:607
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_int8()

Datum generate_series_step_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1419 of file int8.c.

References generate_series_fctx::current, ereport, errcode(), errmsg(), ERROR, generate_series_fctx::finish, Int64GetDatum(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, palloc(), pg_add_s64_overflow(), PG_GETARG_INT64, 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_int8().

1420 {
1421  FuncCallContext *funcctx;
1422  generate_series_fctx *fctx;
1423  int64 result;
1424  MemoryContext oldcontext;
1425 
1426  /* stuff done only on the first call of the function */
1427  if (SRF_IS_FIRSTCALL())
1428  {
1429  int64 start = PG_GETARG_INT64(0);
1430  int64 finish = PG_GETARG_INT64(1);
1431  int64 step = 1;
1432 
1433  /* see if we were given an explicit step size */
1434  if (PG_NARGS() == 3)
1435  step = PG_GETARG_INT64(2);
1436  if (step == 0)
1437  ereport(ERROR,
1438  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1439  errmsg("step size cannot equal zero")));
1440 
1441  /* create a function context for cross-call persistence */
1442  funcctx = SRF_FIRSTCALL_INIT();
1443 
1444  /*
1445  * switch to memory context appropriate for multiple function calls
1446  */
1447  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1448 
1449  /* allocate memory for user context */
1450  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1451 
1452  /*
1453  * Use fctx to keep state from call to call. Seed current with the
1454  * original start value
1455  */
1456  fctx->current = start;
1457  fctx->finish = finish;
1458  fctx->step = step;
1459 
1460  funcctx->user_fctx = fctx;
1461  MemoryContextSwitchTo(oldcontext);
1462  }
1463 
1464  /* stuff done on every call of the function */
1465  funcctx = SRF_PERCALL_SETUP();
1466 
1467  /*
1468  * get the saved state and use current as the result for this iteration
1469  */
1470  fctx = funcctx->user_fctx;
1471  result = fctx->current;
1472 
1473  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1474  (fctx->step < 0 && fctx->current >= fctx->finish))
1475  {
1476  /*
1477  * Increment current in preparation for next iteration. If next-value
1478  * computation overflows, this is the final result.
1479  */
1480  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1481  fctx->step = 0;
1482 
1483  /* do when there is more left to send */
1484  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1485  }
1486  else
1487  /* do when there is no more left */
1488  SRF_RETURN_DONE(funcctx);
1489 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:293
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:610
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:297
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:299
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1701
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int32 current
Definition: int.c:49
int32 finish
Definition: int.c:50
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
#define PG_NARGS()
Definition: fmgr.h:203
void * user_fctx
Definition: funcapi.h:82
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:317
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:295

◆ i8tod()

Datum i8tod ( PG_FUNCTION_ARGS  )

Definition at line 1319 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT8.

1320 {
1321  int64 arg = PG_GETARG_INT64(0);
1322  float8 result;
1323 
1324  result = arg;
1325 
1326  PG_RETURN_FLOAT8(result);
1327 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:491
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ i8tof()

Datum i8tof ( PG_FUNCTION_ARGS  )

Definition at line 1354 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT4.

1355 {
1356  int64 arg = PG_GETARG_INT64(0);
1357  float4 result;
1358 
1359  result = arg;
1360 
1361  PG_RETURN_FLOAT4(result);
1362 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
float float4
Definition: c.h:490
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ i8tooid()

Datum i8tooid ( PG_FUNCTION_ARGS  )

Definition at line 1389 of file int8.c.

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_RETURN_OID, PG_UINT32_MAX, and unlikely.

1390 {
1391  int64 arg = PG_GETARG_INT64(0);
1392 
1393  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1394  ereport(ERROR,
1395  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1396  errmsg("OID out of range")));
1397 
1398  PG_RETURN_OID((Oid) arg);
1399 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_UINT32_MAX
Definition: c.h:451
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
void * arg
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ in_range_int8_int8()

Datum in_range_int8_int8 ( PG_FUNCTION_ARGS  )

Definition at line 480 of file int8.c.

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

481 {
482  int64 val = PG_GETARG_INT64(0);
483  int64 base = PG_GETARG_INT64(1);
484  int64 offset = PG_GETARG_INT64(2);
485  bool sub = PG_GETARG_BOOL(3);
486  bool less = PG_GETARG_BOOL(4);
487  int64 sum;
488 
489  if (offset < 0)
490  ereport(ERROR,
491  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
492  errmsg("invalid preceding or following size in window function")));
493 
494  if (sub)
495  offset = -offset; /* cannot overflow */
496 
497  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
498  {
499  /*
500  * If sub is false, the true sum is surely more than val, so correct
501  * answer is the same as "less". If sub is true, the true sum is
502  * surely less than val, so the answer is "!less".
503  */
504  PG_RETURN_BOOL(sub ? !less : less);
505  }
506 
507  if (less)
508  PG_RETURN_BOOL(val <= sum);
509  else
510  PG_RETURN_BOOL(val >= sum);
511 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define ERROR
Definition: elog.h:43
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
long val
Definition: informix.c:664

◆ int28()

Datum int28 ( PG_FUNCTION_ARGS  )

Definition at line 1298 of file int8.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT64.

1299 {
1300  int16 arg = PG_GETARG_INT16(0);
1301 
1302  PG_RETURN_INT64((int64) arg);
1303 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
void * arg

◆ int28div()

Datum int28div ( PG_FUNCTION_ARGS  )

Definition at line 1191 of file int8.c.

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

1192 {
1193  int16 arg1 = PG_GETARG_INT16(0);
1194  int64 arg2 = PG_GETARG_INT64(1);
1195 
1196  if (unlikely(arg2 == 0))
1197  {
1198  ereport(ERROR,
1199  (errcode(ERRCODE_DIVISION_BY_ZERO),
1200  errmsg("division by zero")));
1201  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1202  PG_RETURN_NULL();
1203  }
1204 
1205  /* No overflow is possible */
1206  PG_RETURN_INT64((int64) arg1 / arg2);
1207 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ int28eq()

Datum int28eq ( PG_FUNCTION_ARGS  )

Definition at line 420 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

421 {
422  int16 val1 = PG_GETARG_INT16(0);
423  int64 val2 = PG_GETARG_INT64(1);
424 
425  PG_RETURN_BOOL(val1 == val2);
426 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28ge()

Datum int28ge ( PG_FUNCTION_ARGS  )

Definition at line 465 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

466 {
467  int16 val1 = PG_GETARG_INT16(0);
468  int64 val2 = PG_GETARG_INT64(1);
469 
470  PG_RETURN_BOOL(val1 >= val2);
471 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28gt()

Datum int28gt ( PG_FUNCTION_ARGS  )

Definition at line 447 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

448 {
449  int16 val1 = PG_GETARG_INT16(0);
450  int64 val2 = PG_GETARG_INT64(1);
451 
452  PG_RETURN_BOOL(val1 > val2);
453 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28le()

Datum int28le ( PG_FUNCTION_ARGS  )

Definition at line 456 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

457 {
458  int16 val1 = PG_GETARG_INT16(0);
459  int64 val2 = PG_GETARG_INT64(1);
460 
461  PG_RETURN_BOOL(val1 <= val2);
462 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28lt()

Datum int28lt ( PG_FUNCTION_ARGS  )

Definition at line 438 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

439 {
440  int16 val1 = PG_GETARG_INT16(0);
441  int64 val2 = PG_GETARG_INT64(1);
442 
443  PG_RETURN_BOOL(val1 < val2);
444 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28mi()

Datum int28mi ( PG_FUNCTION_ARGS  )

Definition at line 1163 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

1164 {
1165  int16 arg1 = PG_GETARG_INT16(0);
1166  int64 arg2 = PG_GETARG_INT64(1);
1167  int64 result;
1168 
1169  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1170  ereport(ERROR,
1171  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1172  errmsg("bigint out of range")));
1173  PG_RETURN_INT64(result);
1174 }
signed short int16
Definition: c.h:354
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28mul()

Datum int28mul ( PG_FUNCTION_ARGS  )

Definition at line 1177 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

1178 {
1179  int16 arg1 = PG_GETARG_INT16(0);
1180  int64 arg2 = PG_GETARG_INT64(1);
1181  int64 result;
1182 
1183  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1184  ereport(ERROR,
1185  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1186  errmsg("bigint out of range")));
1187  PG_RETURN_INT64(result);
1188 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28ne()

Datum int28ne ( PG_FUNCTION_ARGS  )

Definition at line 429 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

430 {
431  int16 val1 = PG_GETARG_INT16(0);
432  int64 val2 = PG_GETARG_INT64(1);
433 
434  PG_RETURN_BOOL(val1 != val2);
435 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int28pl()

Datum int28pl ( PG_FUNCTION_ARGS  )

Definition at line 1149 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

1150 {
1151  int16 arg1 = PG_GETARG_INT16(0);
1152  int64 arg2 = PG_GETARG_INT64(1);
1153  int64 result;
1154 
1155  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1156  ereport(ERROR,
1157  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1158  errmsg("bigint out of range")));
1159  PG_RETURN_INT64(result);
1160 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48()

Datum int48 ( PG_FUNCTION_ARGS  )

Definition at line 1277 of file int8.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT64.

1278 {
1279  int32 arg = PG_GETARG_INT32(0);
1280 
1281  PG_RETURN_INT64((int64) arg);
1282 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
signed int int32
Definition: c.h:355
void * arg

◆ int48div()

Datum int48div ( PG_FUNCTION_ARGS  )

Definition at line 1049 of file int8.c.

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

1050 {
1051  int32 arg1 = PG_GETARG_INT32(0);
1052  int64 arg2 = PG_GETARG_INT64(1);
1053 
1054  if (unlikely(arg2 == 0))
1055  {
1056  ereport(ERROR,
1057  (errcode(ERRCODE_DIVISION_BY_ZERO),
1058  errmsg("division by zero")));
1059  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1060  PG_RETURN_NULL();
1061  }
1062 
1063  /* No overflow is possible */
1064  PG_RETURN_INT64((int64) arg1 / arg2);
1065 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ int48eq()

Datum int48eq ( PG_FUNCTION_ARGS  )

Definition at line 306 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

307 {
308  int32 val1 = PG_GETARG_INT32(0);
309  int64 val2 = PG_GETARG_INT64(1);
310 
311  PG_RETURN_BOOL(val1 == val2);
312 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48ge()

Datum int48ge ( PG_FUNCTION_ARGS  )

Definition at line 351 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

352 {
353  int32 val1 = PG_GETARG_INT32(0);
354  int64 val2 = PG_GETARG_INT64(1);
355 
356  PG_RETURN_BOOL(val1 >= val2);
357 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48gt()

Datum int48gt ( PG_FUNCTION_ARGS  )

Definition at line 333 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

334 {
335  int32 val1 = PG_GETARG_INT32(0);
336  int64 val2 = PG_GETARG_INT64(1);
337 
338  PG_RETURN_BOOL(val1 > val2);
339 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48le()

Datum int48le ( PG_FUNCTION_ARGS  )

Definition at line 342 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

343 {
344  int32 val1 = PG_GETARG_INT32(0);
345  int64 val2 = PG_GETARG_INT64(1);
346 
347  PG_RETURN_BOOL(val1 <= val2);
348 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48lt()

Datum int48lt ( PG_FUNCTION_ARGS  )

Definition at line 324 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

325 {
326  int32 val1 = PG_GETARG_INT32(0);
327  int64 val2 = PG_GETARG_INT64(1);
328 
329  PG_RETURN_BOOL(val1 < val2);
330 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48mi()

Datum int48mi ( PG_FUNCTION_ARGS  )

Definition at line 1021 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

1022 {
1023  int32 arg1 = PG_GETARG_INT32(0);
1024  int64 arg2 = PG_GETARG_INT64(1);
1025  int64 result;
1026 
1027  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1028  ereport(ERROR,
1029  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1030  errmsg("bigint out of range")));
1031  PG_RETURN_INT64(result);
1032 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48mul()

Datum int48mul ( PG_FUNCTION_ARGS  )

Definition at line 1035 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

1036 {
1037  int32 arg1 = PG_GETARG_INT32(0);
1038  int64 arg2 = PG_GETARG_INT64(1);
1039  int64 result;
1040 
1041  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1042  ereport(ERROR,
1043  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1044  errmsg("bigint out of range")));
1045  PG_RETURN_INT64(result);
1046 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48ne()

Datum int48ne ( PG_FUNCTION_ARGS  )

Definition at line 315 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

316 {
317  int32 val1 = PG_GETARG_INT32(0);
318  int64 val2 = PG_GETARG_INT64(1);
319 
320  PG_RETURN_BOOL(val1 != val2);
321 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int48pl()

Datum int48pl ( PG_FUNCTION_ARGS  )

Definition at line 1007 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

1008 {
1009  int32 arg1 = PG_GETARG_INT32(0);
1010  int64 arg2 = PG_GETARG_INT64(1);
1011  int64 result;
1012 
1013  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1014  ereport(ERROR,
1015  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1016  errmsg("bigint out of range")));
1017  PG_RETURN_INT64(result);
1018 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82()

Datum int82 ( PG_FUNCTION_ARGS  )

Definition at line 1306 of file int8.c.

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

1307 {
1308  int64 arg = PG_GETARG_INT64(0);
1309 
1310  if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
1311  ereport(ERROR,
1312  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1313  errmsg("smallint out of range")));
1314 
1315  PG_RETURN_INT16((int16) arg);
1316 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT16(x)
Definition: fmgr.h:355
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:446
#define ereport(elevel,...)
Definition: elog.h:144
#define PG_INT16_MAX
Definition: c.h:447
int errmsg(const char *fmt,...)
Definition: elog.c:824
void * arg
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82div()

Datum int82div ( PG_FUNCTION_ARGS  )

Definition at line 1110 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

1111 {
1112  int64 arg1 = PG_GETARG_INT64(0);
1113  int16 arg2 = PG_GETARG_INT16(1);
1114  int64 result;
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  * INT64_MIN / -1 is problematic, since the result can't be represented on
1127  * a two's-complement machine. Some machines produce INT64_MIN, some
1128  * produce zero, some throw an exception. We can dodge the problem by
1129  * recognizing that division by -1 is the same as negation.
1130  */
1131  if (arg2 == -1)
1132  {
1133  if (unlikely(arg1 == PG_INT64_MIN))
1134  ereport(ERROR,
1135  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1136  errmsg("bigint out of range")));
1137  result = -arg1;
1138  PG_RETURN_INT64(result);
1139  }
1140 
1141  /* No overflow is possible */
1142 
1143  result = arg1 / arg2;
1144 
1145  PG_RETURN_INT64(result);
1146 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ int82eq()

Datum int82eq ( PG_FUNCTION_ARGS  )

Definition at line 363 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

364 {
365  int64 val1 = PG_GETARG_INT64(0);
366  int16 val2 = PG_GETARG_INT16(1);
367 
368  PG_RETURN_BOOL(val1 == val2);
369 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82ge()

Datum int82ge ( PG_FUNCTION_ARGS  )

Definition at line 408 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

409 {
410  int64 val1 = PG_GETARG_INT64(0);
411  int16 val2 = PG_GETARG_INT16(1);
412 
413  PG_RETURN_BOOL(val1 >= val2);
414 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82gt()

Datum int82gt ( PG_FUNCTION_ARGS  )

Definition at line 390 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

391 {
392  int64 val1 = PG_GETARG_INT64(0);
393  int16 val2 = PG_GETARG_INT16(1);
394 
395  PG_RETURN_BOOL(val1 > val2);
396 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82le()

Datum int82le ( PG_FUNCTION_ARGS  )

Definition at line 399 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

400 {
401  int64 val1 = PG_GETARG_INT64(0);
402  int16 val2 = PG_GETARG_INT16(1);
403 
404  PG_RETURN_BOOL(val1 <= val2);
405 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82lt()

Datum int82lt ( PG_FUNCTION_ARGS  )

Definition at line 381 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

382 {
383  int64 val1 = PG_GETARG_INT64(0);
384  int16 val2 = PG_GETARG_INT16(1);
385 
386  PG_RETURN_BOOL(val1 < val2);
387 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82mi()

Datum int82mi ( PG_FUNCTION_ARGS  )

Definition at line 1082 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

1083 {
1084  int64 arg1 = PG_GETARG_INT64(0);
1085  int16 arg2 = PG_GETARG_INT16(1);
1086  int64 result;
1087 
1088  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
1089  ereport(ERROR,
1090  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1091  errmsg("bigint out of range")));
1092  PG_RETURN_INT64(result);
1093 }
signed short int16
Definition: c.h:354
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82mul()

Datum int82mul ( PG_FUNCTION_ARGS  )

Definition at line 1096 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

1097 {
1098  int64 arg1 = PG_GETARG_INT64(0);
1099  int16 arg2 = PG_GETARG_INT16(1);
1100  int64 result;
1101 
1102  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
1103  ereport(ERROR,
1104  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1105  errmsg("bigint out of range")));
1106  PG_RETURN_INT64(result);
1107 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82ne()

Datum int82ne ( PG_FUNCTION_ARGS  )

Definition at line 372 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

373 {
374  int64 val1 = PG_GETARG_INT64(0);
375  int16 val2 = PG_GETARG_INT16(1);
376 
377  PG_RETURN_BOOL(val1 != val2);
378 }
signed short int16
Definition: c.h:354
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int82pl()

Datum int82pl ( PG_FUNCTION_ARGS  )

Definition at line 1068 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

1069 {
1070  int64 arg1 = PG_GETARG_INT64(0);
1071  int16 arg2 = PG_GETARG_INT16(1);
1072  int64 result;
1073 
1074  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
1075  ereport(ERROR,
1076  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1077  errmsg("bigint out of range")));
1078  PG_RETURN_INT64(result);
1079 }
signed short int16
Definition: c.h:354
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84()

Datum int84 ( PG_FUNCTION_ARGS  )

Definition at line 1285 of file int8.c.

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

Referenced by int8_to_char().

1286 {
1287  int64 arg = PG_GETARG_INT64(0);
1288 
1289  if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
1290  ereport(ERROR,
1291  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1292  errmsg("integer out of range")));
1293 
1294  PG_RETURN_INT32((int32) arg);
1295 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:449
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define PG_INT32_MAX
Definition: c.h:450
void * arg
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84div()

Datum int84div ( PG_FUNCTION_ARGS  )

Definition at line 968 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

969 {
970  int64 arg1 = PG_GETARG_INT64(0);
971  int32 arg2 = PG_GETARG_INT32(1);
972  int64 result;
973 
974  if (arg2 == 0)
975  {
976  ereport(ERROR,
977  (errcode(ERRCODE_DIVISION_BY_ZERO),
978  errmsg("division by zero")));
979  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
980  PG_RETURN_NULL();
981  }
982 
983  /*
984  * INT64_MIN / -1 is problematic, since the result can't be represented on
985  * a two's-complement machine. Some machines produce INT64_MIN, some
986  * produce zero, some throw an exception. We can dodge the problem by
987  * recognizing that division by -1 is the same as negation.
988  */
989  if (arg2 == -1)
990  {
991  if (unlikely(arg1 == PG_INT64_MIN))
992  ereport(ERROR,
993  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
994  errmsg("bigint out of range")));
995  result = -arg1;
996  PG_RETURN_INT64(result);
997  }
998 
999  /* No overflow is possible */
1000 
1001  result = arg1 / arg2;
1002 
1003  PG_RETURN_INT64(result);
1004 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ int84eq()

Datum int84eq ( PG_FUNCTION_ARGS  )

Definition at line 249 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

250 {
251  int64 val1 = PG_GETARG_INT64(0);
252  int32 val2 = PG_GETARG_INT32(1);
253 
254  PG_RETURN_BOOL(val1 == val2);
255 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84ge()

Datum int84ge ( PG_FUNCTION_ARGS  )

Definition at line 294 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

295 {
296  int64 val1 = PG_GETARG_INT64(0);
297  int32 val2 = PG_GETARG_INT32(1);
298 
299  PG_RETURN_BOOL(val1 >= val2);
300 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84gt()

Datum int84gt ( PG_FUNCTION_ARGS  )

Definition at line 276 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

277 {
278  int64 val1 = PG_GETARG_INT64(0);
279  int32 val2 = PG_GETARG_INT32(1);
280 
281  PG_RETURN_BOOL(val1 > val2);
282 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84le()

Datum int84le ( PG_FUNCTION_ARGS  )

Definition at line 285 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

286 {
287  int64 val1 = PG_GETARG_INT64(0);
288  int32 val2 = PG_GETARG_INT32(1);
289 
290  PG_RETURN_BOOL(val1 <= val2);
291 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84lt()

Datum int84lt ( PG_FUNCTION_ARGS  )

Definition at line 267 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

268 {
269  int64 val1 = PG_GETARG_INT64(0);
270  int32 val2 = PG_GETARG_INT32(1);
271 
272  PG_RETURN_BOOL(val1 < val2);
273 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84mi()

Datum int84mi ( PG_FUNCTION_ARGS  )

Definition at line 940 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

941 {
942  int64 arg1 = PG_GETARG_INT64(0);
943  int32 arg2 = PG_GETARG_INT32(1);
944  int64 result;
945 
946  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
947  ereport(ERROR,
948  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
949  errmsg("bigint out of range")));
950  PG_RETURN_INT64(result);
951 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84mul()

Datum int84mul ( PG_FUNCTION_ARGS  )

Definition at line 954 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

955 {
956  int64 arg1 = PG_GETARG_INT64(0);
957  int32 arg2 = PG_GETARG_INT32(1);
958  int64 result;
959 
960  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
961  ereport(ERROR,
962  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
963  errmsg("bigint out of range")));
964  PG_RETURN_INT64(result);
965 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84ne()

Datum int84ne ( PG_FUNCTION_ARGS  )

Definition at line 258 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

259 {
260  int64 val1 = PG_GETARG_INT64(0);
261  int32 val2 = PG_GETARG_INT32(1);
262 
263  PG_RETURN_BOOL(val1 != val2);
264 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int84pl()

Datum int84pl ( PG_FUNCTION_ARGS  )

Definition at line 926 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

927 {
928  int64 arg1 = PG_GETARG_INT64(0);
929  int32 arg2 = PG_GETARG_INT32(1);
930  int64 result;
931 
932  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
933  ereport(ERROR,
934  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
935  errmsg("bigint out of range")));
936  PG_RETURN_INT64(result);
937 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8abs()

Datum int8abs ( PG_FUNCTION_ARGS  )

Definition at line 625 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, and unlikely.

626 {
627  int64 arg1 = PG_GETARG_INT64(0);
628  int64 result;
629 
630  if (unlikely(arg1 == PG_INT64_MIN))
631  ereport(ERROR,
632  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
633  errmsg("bigint out of range")));
634  result = (arg1 < 0) ? -arg1 : arg1;
635  PG_RETURN_INT64(result);
636 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8and()

Datum int8and ( PG_FUNCTION_ARGS  )

Definition at line 1220 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1221 {
1222  int64 arg1 = PG_GETARG_INT64(0);
1223  int64 arg2 = PG_GETARG_INT64(1);
1224 
1225  PG_RETURN_INT64(arg1 & arg2);
1226 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8dec()

Datum int8dec ( PG_FUNCTION_ARGS  )

Definition at line 836 of file int8.c.

References AggCheckCallContext(), arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_GETARG_POINTER, PG_RETURN_INT64, PG_RETURN_POINTER, pg_sub_s64_overflow(), and unlikely.

Referenced by int8dec_any().

837 {
838  /*
839  * When int8 is pass-by-reference, we provide this special case to avoid
840  * palloc overhead for COUNT(): when called as an aggregate, we know that
841  * the argument is modifiable local storage, so just update it in-place.
842  * (If int8 is pass-by-value, then of course this is useless as well as
843  * incorrect, so just ifdef it out.)
844  */
845 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
846  if (AggCheckCallContext(fcinfo, NULL))
847  {
848  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
849 
850  if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
851  ereport(ERROR,
852  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
853  errmsg("bigint out of range")));
854  PG_RETURN_POINTER(arg);
855  }
856  else
857 #endif
858  {
859  /* Not called as an aggregate, so just do it the dumb way */
860  int64 arg = PG_GETARG_INT64(0);
861  int64 result;
862 
863  if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
864  ereport(ERROR,
865  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
866  errmsg("bigint out of range")));
867 
868  PG_RETURN_INT64(result);
869  }
870 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4684
int errmsg(const char *fmt,...)
Definition: elog.c:824
void * arg
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8dec_any()

Datum int8dec_any ( PG_FUNCTION_ARGS  )

Definition at line 895 of file int8.c.

References int8dec().

896 {
897  return int8dec(fcinfo);
898 }
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:836

◆ int8div()

Datum int8div ( PG_FUNCTION_ARGS  )

Definition at line 583 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

584 {
585  int64 arg1 = PG_GETARG_INT64(0);
586  int64 arg2 = PG_GETARG_INT64(1);
587  int64 result;
588 
589  if (arg2 == 0)
590  {
591  ereport(ERROR,
592  (errcode(ERRCODE_DIVISION_BY_ZERO),
593  errmsg("division by zero")));
594  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
595  PG_RETURN_NULL();
596  }
597 
598  /*
599  * INT64_MIN / -1 is problematic, since the result can't be represented on
600  * a two's-complement machine. Some machines produce INT64_MIN, some
601  * produce zero, some throw an exception. We can dodge the problem by
602  * recognizing that division by -1 is the same as negation.
603  */
604  if (arg2 == -1)
605  {
606  if (unlikely(arg1 == PG_INT64_MIN))
607  ereport(ERROR,
608  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
609  errmsg("bigint out of range")));
610  result = -arg1;
611  PG_RETURN_INT64(result);
612  }
613 
614  /* No overflow is possible */
615 
616  result = arg1 / arg2;
617 
618  PG_RETURN_INT64(result);
619 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ int8eq()

Datum int8eq ( PG_FUNCTION_ARGS  )

Definition at line 192 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

193 {
194  int64 val1 = PG_GETARG_INT64(0);
195  int64 val2 = PG_GETARG_INT64(1);
196 
197  PG_RETURN_BOOL(val1 == val2);
198 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8gcd()

Datum int8gcd ( PG_FUNCTION_ARGS  )

Definition at line 746 of file int8.c.

References int8gcd_internal(), PG_GETARG_INT64, and PG_RETURN_INT64.

747 {
748  int64 arg1 = PG_GETARG_INT64(0);
749  int64 arg2 = PG_GETARG_INT64(1);
750  int64 result;
751 
752  result = int8gcd_internal(arg1, arg2);
753 
754  PG_RETURN_INT64(result);
755 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
static int64 int8gcd_internal(int64 arg1, int64 arg2)
Definition: int8.c:685
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8gcd_internal()

static int64 int8gcd_internal ( int64  arg1,
int64  arg2 
)
static

Definition at line 685 of file int8.c.

References a1, a2, ereport, errcode(), errmsg(), ERROR, PG_INT64_MIN, and swap.

Referenced by int8gcd(), and int8lcm().

686 {
687  int64 swap;
688  int64 a1,
689  a2;
690 
691  /*
692  * Put the greater absolute value in arg1.
693  *
694  * This would happen automatically in the loop below, but avoids an
695  * expensive modulo operation, and simplifies the special-case handling
696  * for INT64_MIN below.
697  *
698  * We do this in negative space in order to handle INT64_MIN.
699  */
700  a1 = (arg1 < 0) ? arg1 : -arg1;
701  a2 = (arg2 < 0) ? arg2 : -arg2;
702  if (a1 > a2)
703  {
704  swap = arg1;
705  arg1 = arg2;
706  arg2 = swap;
707  }
708 
709  /* Special care needs to be taken with INT64_MIN. See comments above. */
710  if (arg1 == PG_INT64_MIN)
711  {
712  if (arg2 == 0 || arg2 == PG_INT64_MIN)
713  ereport(ERROR,
714  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
715  errmsg("bigint out of range")));
716 
717  /*
718  * Some machines throw a floating-point exception for INT64_MIN % -1,
719  * which is a bit silly since the correct answer is perfectly
720  * well-defined, namely zero. Guard against this and just return the
721  * result, gcd(INT64_MIN, -1) = 1.
722  */
723  if (arg2 == -1)
724  return 1;
725  }
726 
727  /* Use the Euclidean algorithm to find the GCD */
728  while (arg2 != 0)
729  {
730  swap = arg2;
731  arg2 = arg1 % arg2;
732  arg1 = swap;
733  }
734 
735  /*
736  * Make sure the result is positive. (We know we don't have INT64_MIN
737  * anymore).
738  */
739  if (arg1 < 0)
740  arg1 = -arg1;
741 
742  return arg1;
743 }
#define swap(a, b)
Definition: qsort.c:94
int errcode(int sqlerrcode)
Definition: elog.c:610
static const FormData_pg_attribute a2
Definition: heap.c:165
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
static const FormData_pg_attribute a1
Definition: heap.c:151

◆ int8ge()

Datum int8ge ( PG_FUNCTION_ARGS  )

Definition at line 237 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

238 {
239  int64 val1 = PG_GETARG_INT64(0);
240  int64 val2 = PG_GETARG_INT64(1);
241 
242  PG_RETURN_BOOL(val1 >= val2);
243 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8gt()

Datum int8gt ( PG_FUNCTION_ARGS  )

Definition at line 219 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

220 {
221  int64 val1 = PG_GETARG_INT64(0);
222  int64 val2 = PG_GETARG_INT64(1);
223 
224  PG_RETURN_BOOL(val1 > val2);
225 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8in()

Datum int8in ( PG_FUNCTION_ARGS  )

Definition at line 134 of file int8.c.

References PG_GETARG_CSTRING, PG_RETURN_INT64, scanint8(), and generate_unaccent_rules::str.

Referenced by defGetInt64().

135 {
136  char *str = PG_GETARG_CSTRING(0);
137  int64 result;
138 
139  (void) scanint8(str, false, &result);
140  PG_RETURN_INT64(result);
141 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
bool scanint8(const char *str, bool errorOK, int64 *result)
Definition: int8.c:55

◆ int8inc()

Datum int8inc ( PG_FUNCTION_ARGS  )

Definition at line 798 of file int8.c.

References AggCheckCallContext(), arg, ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT64, PG_GETARG_POINTER, PG_RETURN_INT64, PG_RETURN_POINTER, and unlikely.

Referenced by int8inc_any(), and int8inc_float8_float8().

799 {
800  /*
801  * When int8 is pass-by-reference, we provide this special case to avoid
802  * palloc overhead for COUNT(): when called as an aggregate, we know that
803  * the argument is modifiable local storage, so just update it in-place.
804  * (If int8 is pass-by-value, then of course this is useless as well as
805  * incorrect, so just ifdef it out.)
806  */
807 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
808  if (AggCheckCallContext(fcinfo, NULL))
809  {
810  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
811 
812  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
813  ereport(ERROR,
814  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
815  errmsg("bigint out of range")));
816 
817  PG_RETURN_POINTER(arg);
818  }
819  else
820 #endif
821  {
822  /* Not called as an aggregate, so just do it the dumb way */
823  int64 arg = PG_GETARG_INT64(0);
824  int64 result;
825 
826  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
827  ereport(ERROR,
828  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
829  errmsg("bigint out of range")));
830 
831  PG_RETURN_INT64(result);
832  }
833 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define ERROR
Definition: elog.h:43
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4684
int errmsg(const char *fmt,...)
Definition: elog.c:824
void * arg
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8inc_any()

Datum int8inc_any ( PG_FUNCTION_ARGS  )

Definition at line 883 of file int8.c.

References int8inc().

884 {
885  return int8inc(fcinfo);
886 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:798

◆ int8inc_float8_float8()

Datum int8inc_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 889 of file int8.c.

References int8inc().

890 {
891  return int8inc(fcinfo);
892 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:798

◆ int8larger()

Datum int8larger ( PG_FUNCTION_ARGS  )

Definition at line 902 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

903 {
904  int64 arg1 = PG_GETARG_INT64(0);
905  int64 arg2 = PG_GETARG_INT64(1);
906  int64 result;
907 
908  result = ((arg1 > arg2) ? arg1 : arg2);
909 
910  PG_RETURN_INT64(result);
911 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8lcm()

Datum int8lcm ( PG_FUNCTION_ARGS  )

Definition at line 761 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, gcd(), int8gcd_internal(), PG_GETARG_INT64, PG_INT64_MIN, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

762 {
763  int64 arg1 = PG_GETARG_INT64(0);
764  int64 arg2 = PG_GETARG_INT64(1);
765  int64 gcd;
766  int64 result;
767 
768  /*
769  * Handle lcm(x, 0) = lcm(0, x) = 0 as a special case. This prevents a
770  * division-by-zero error below when x is zero, and an overflow error from
771  * the GCD computation when x = INT64_MIN.
772  */
773  if (arg1 == 0 || arg2 == 0)
774  PG_RETURN_INT64(0);
775 
776  /* lcm(x, y) = abs(x / gcd(x, y) * y) */
777  gcd = int8gcd_internal(arg1, arg2);
778  arg1 = arg1 / gcd;
779 
780  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
781  ereport(ERROR,
782  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
783  errmsg("bigint out of range")));
784 
785  /* If the result is INT64_MIN, it cannot be represented. */
786  if (unlikely(result == PG_INT64_MIN))
787  ereport(ERROR,
788  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
789  errmsg("bigint out of range")));
790 
791  if (result < 0)
792  result = -result;
793 
794  PG_RETURN_INT64(result);
795 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
static int64 int8gcd_internal(int64 arg1, int64 arg2)
Definition: int8.c:685
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:824
static uint32 gcd(uint32 a, uint32 b)
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8le()

Datum int8le ( PG_FUNCTION_ARGS  )

Definition at line 228 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

229 {
230  int64 val1 = PG_GETARG_INT64(0);
231  int64 val2 = PG_GETARG_INT64(1);
232 
233  PG_RETURN_BOOL(val1 <= val2);
234 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8lt()

Datum int8lt ( PG_FUNCTION_ARGS  )

Definition at line 210 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

211 {
212  int64 val1 = PG_GETARG_INT64(0);
213  int64 val2 = PG_GETARG_INT64(1);
214 
215  PG_RETURN_BOOL(val1 < val2);
216 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8mi()

Datum int8mi ( PG_FUNCTION_ARGS  )

Definition at line 555 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

556 {
557  int64 arg1 = PG_GETARG_INT64(0);
558  int64 arg2 = PG_GETARG_INT64(1);
559  int64 result;
560 
561  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
562  ereport(ERROR,
563  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
564  errmsg("bigint out of range")));
565  PG_RETURN_INT64(result);
566 }
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8mod()

Datum int8mod ( PG_FUNCTION_ARGS  )

Definition at line 642 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

643 {
644  int64 arg1 = PG_GETARG_INT64(0);
645  int64 arg2 = PG_GETARG_INT64(1);
646 
647  if (unlikely(arg2 == 0))
648  {
649  ereport(ERROR,
650  (errcode(ERRCODE_DIVISION_BY_ZERO),
651  errmsg("division by zero")));
652  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
653  PG_RETURN_NULL();
654  }
655 
656  /*
657  * Some machines throw a floating-point exception for INT64_MIN % -1,
658  * which is a bit silly since the correct answer is perfectly
659  * well-defined, namely zero.
660  */
661  if (arg2 == -1)
662  PG_RETURN_INT64(0);
663 
664  /* No overflow is possible */
665 
666  PG_RETURN_INT64(arg1 % arg2);
667 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ int8mul()

Datum int8mul ( PG_FUNCTION_ARGS  )

Definition at line 569 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

Referenced by int4_cash(), int8_cash(), and int8_to_char().

570 {
571  int64 arg1 = PG_GETARG_INT64(0);
572  int64 arg2 = PG_GETARG_INT64(1);
573  int64 result;
574 
575  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
576  ereport(ERROR,
577  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
578  errmsg("bigint out of range")));
579  PG_RETURN_INT64(result);
580 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8ne()

Datum int8ne ( PG_FUNCTION_ARGS  )

Definition at line 201 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

202 {
203  int64 val1 = PG_GETARG_INT64(0);
204  int64 val2 = PG_GETARG_INT64(1);
205 
206  PG_RETURN_BOOL(val1 != val2);
207 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8not()

Datum int8not ( PG_FUNCTION_ARGS  )

Definition at line 1247 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1248 {
1249  int64 arg1 = PG_GETARG_INT64(0);
1250 
1251  PG_RETURN_INT64(~arg1);
1252 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8or()

Datum int8or ( PG_FUNCTION_ARGS  )

Definition at line 1229 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1230 {
1231  int64 arg1 = PG_GETARG_INT64(0);
1232  int64 arg2 = PG_GETARG_INT64(1);
1233 
1234  PG_RETURN_INT64(arg1 | arg2);
1235 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8out()

Datum int8out ( PG_FUNCTION_ARGS  )

Definition at line 147 of file int8.c.

References buf, MAXINT8LEN, PG_GETARG_INT64, pg_lltoa(), PG_RETURN_CSTRING, pstrdup(), and val.

Referenced by int8_to_char().

148 {
149  int64 val = PG_GETARG_INT64(0);
150  char buf[MAXINT8LEN + 1];
151  char *result;
152 
153  pg_lltoa(val, buf);
154  result = pstrdup(buf);
155  PG_RETURN_CSTRING(result);
156 }
#define MAXINT8LEN
Definition: builtins.h:22
char * pstrdup(const char *in)
Definition: mcxt.c:1186
static char * buf
Definition: pg_test_fsync.c:67
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:521
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282
long val
Definition: informix.c:664

◆ int8pl()

Datum int8pl ( PG_FUNCTION_ARGS  )

Definition at line 541 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

Referenced by int8range_canonical().

542 {
543  int64 arg1 = PG_GETARG_INT64(0);
544  int64 arg2 = PG_GETARG_INT64(1);
545  int64 result;
546 
547  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
548  ereport(ERROR,
549  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
550  errmsg("bigint out of range")));
551  PG_RETURN_INT64(result);
552 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8recv()

Datum int8recv ( PG_FUNCTION_ARGS  )

Definition at line 162 of file int8.c.

References buf, PG_GETARG_POINTER, PG_RETURN_INT64, and pq_getmsgint64().

163 {
165 
167 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:67
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

◆ int8send()

Datum int8send ( PG_FUNCTION_ARGS  )

Definition at line 173 of file int8.c.

References buf, PG_GETARG_INT64, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint64().

174 {
175  int64 arg1 = PG_GETARG_INT64(0);
177 
178  pq_begintypsend(&buf);
179  pq_sendint64(&buf, arg1);
181 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:369
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8shl()

Datum int8shl ( PG_FUNCTION_ARGS  )

Definition at line 1255 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1256 {
1257  int64 arg1 = PG_GETARG_INT64(0);
1258  int32 arg2 = PG_GETARG_INT32(1);
1259 
1260  PG_RETURN_INT64(arg1 << arg2);
1261 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
signed int int32
Definition: c.h:355
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8shr()

Datum int8shr ( PG_FUNCTION_ARGS  )

Definition at line 1264 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1265 {
1266  int64 arg1 = PG_GETARG_INT64(0);
1267  int32 arg2 = PG_GETARG_INT32(1);
1268 
1269  PG_RETURN_INT64(arg1 >> arg2);
1270 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
signed int int32
Definition: c.h:355
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8smaller()

Datum int8smaller ( PG_FUNCTION_ARGS  )

Definition at line 914 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

915 {
916  int64 arg1 = PG_GETARG_INT64(0);
917  int64 arg2 = PG_GETARG_INT64(1);
918  int64 result;
919 
920  result = ((arg1 < arg2) ? arg1 : arg2);
921 
922  PG_RETURN_INT64(result);
923 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8um()

Datum int8um ( PG_FUNCTION_ARGS  )

Definition at line 519 of file int8.c.

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, and unlikely.

520 {
521  int64 arg = PG_GETARG_INT64(0);
522  int64 result;
523 
524  if (unlikely(arg == PG_INT64_MIN))
525  ereport(ERROR,
526  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
527  errmsg("bigint out of range")));
528  result = -arg;
529  PG_RETURN_INT64(result);
530 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
void * arg
#define unlikely(x)
Definition: c.h:206
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8up()

Datum int8up ( PG_FUNCTION_ARGS  )

Definition at line 533 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_INT64.

534 {
535  int64 arg = PG_GETARG_INT64(0);
536 
537  PG_RETURN_INT64(arg);
538 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ int8xor()

Datum int8xor ( PG_FUNCTION_ARGS  )

Definition at line 1238 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1239 {
1240  int64 arg1 = PG_GETARG_INT64(0);
1241  int64 arg2 = PG_GETARG_INT64(1);
1242 
1243  PG_RETURN_INT64(arg1 ^ arg2);
1244 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ oidtoi8()

Datum oidtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1402 of file int8.c.

References arg, PG_GETARG_OID, and PG_RETURN_INT64.

1403 {
1404  Oid arg = PG_GETARG_OID(0);
1405 
1406  PG_RETURN_INT64((int64) arg);
1407 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
void * arg

◆ scanint8()

bool scanint8 ( const char *  str,
bool  errorOK,
int64 *  result 
)

Definition at line 55 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, PG_INT64_MIN, pg_mul_s64_overflow(), pg_sub_s64_overflow(), generate_unaccent_rules::str, and unlikely.

Referenced by int8in(), make_const(), and parse_output_parameters().

56 {
57  const char *ptr = str;
58  int64 tmp = 0;
59  bool neg = false;
60 
61  /*
62  * Do our own scan, rather than relying on sscanf which might be broken
63  * for long long.
64  *
65  * As INT64_MIN can't be stored as a positive 64 bit integer, accumulate
66  * value as a negative number.
67  */
68 
69  /* skip leading spaces */
70  while (*ptr && isspace((unsigned char) *ptr))
71  ptr++;
72 
73  /* handle sign */
74  if (*ptr == '-')
75  {
76  ptr++;
77  neg = true;
78  }
79  else if (*ptr == '+')
80  ptr++;
81 
82  /* require at least one digit */
83  if (unlikely(!isdigit((unsigned char) *ptr)))
84  goto invalid_syntax;
85 
86  /* process digits */
87  while (*ptr && isdigit((unsigned char) *ptr))
88  {
89  int8 digit = (*ptr++ - '0');
90 
91  if (unlikely(pg_mul_s64_overflow(tmp, 10, &tmp)) ||
92  unlikely(pg_sub_s64_overflow(tmp, digit, &tmp)))
93  goto out_of_range;
94  }
95 
96  /* allow trailing whitespace, but not other trailing chars */
97  while (*ptr != '\0' && isspace((unsigned char) *ptr))
98  ptr++;
99 
100  if (unlikely(*ptr != '\0'))
101  goto invalid_syntax;
102 
103  if (!neg)
104  {
105  /* could fail if input is most negative number */
106  if (unlikely(tmp == PG_INT64_MIN))
107  goto out_of_range;
108  tmp = -tmp;
109  }
110 
111  *result = tmp;
112  return true;
113 
114 out_of_range:
115  if (!errorOK)
116  ereport(ERROR,
117  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
118  errmsg("value \"%s\" is out of range for type %s",
119  str, "bigint")));
120  return false;
121 
122 invalid_syntax:
123  if (!errorOK)
124  ereport(ERROR,
125  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
126  errmsg("invalid input syntax for type %s: \"%s\"",
127  "bigint", str)));
128  return false;
129 }
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:452
signed char int8
Definition: c.h:353
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206