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 1332 of file int8.c.

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

Referenced by int8_to_char().

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

◆ ftoi8()

Datum ftoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1367 of file int8.c.

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

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

◆ generate_series_int8()

Datum generate_series_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1412 of file int8.c.

References generate_series_step_int8().

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

◆ generate_series_int8_support()

Datum generate_series_int8_support ( PG_FUNCTION_ARGS  )

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

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

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

◆ i8tod()

Datum i8tod ( PG_FUNCTION_ARGS  )

Definition at line 1318 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT8.

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

◆ i8tof()

Datum i8tof ( PG_FUNCTION_ARGS  )

Definition at line 1353 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT4.

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

◆ i8tooid()

Datum i8tooid ( PG_FUNCTION_ARGS  )

Definition at line 1388 of file int8.c.

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

1389 {
1390  int64 arg = PG_GETARG_INT64(0);
1391 
1392  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1393  ereport(ERROR,
1394  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1395  errmsg("OID out of range")));
1396 
1397  PG_RETURN_OID((Oid) arg);
1398 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define PG_UINT32_MAX
Definition: c.h:443
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#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
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
#define PG_RETURN_OID(x)
Definition: fmgr.h:350

◆ 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: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:664

◆ int28()

Datum int28 ( PG_FUNCTION_ARGS  )

Definition at line 1297 of file int8.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT64.

1298 {
1299  int16 arg = PG_GETARG_INT16(0);
1300 
1301  PG_RETURN_INT64((int64) arg);
1302 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
void * arg

◆ int28div()

Datum int28div ( PG_FUNCTION_ARGS  )

Definition at line 1190 of file int8.c.

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

1191 {
1192  int16 arg1 = PG_GETARG_INT16(0);
1193  int64 arg2 = PG_GETARG_INT64(1);
1194 
1195  if (unlikely(arg2 == 0))
1196  {
1197  ereport(ERROR,
1198  (errcode(ERRCODE_DIVISION_BY_ZERO),
1199  errmsg("division by zero")));
1200  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1201  PG_RETURN_NULL();
1202  }
1203 
1204  /* No overflow is possible */
1205  PG_RETURN_INT64((int64) arg1 / arg2);
1206 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_GETARG_INT64(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int28mi()

Datum int28mi ( PG_FUNCTION_ARGS  )

Definition at line 1162 of file int8.c.

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

1163 {
1164  int16 arg1 = PG_GETARG_INT16(0);
1165  int64 arg2 = PG_GETARG_INT64(1);
1166  int64 result;
1167 
1168  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1169  ereport(ERROR,
1170  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1171  errmsg("bigint out of range")));
1172  PG_RETURN_INT64(result);
1173 }
signed short int16
Definition: c.h:346
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int28mul()

Datum int28mul ( PG_FUNCTION_ARGS  )

Definition at line 1176 of file int8.c.

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

1177 {
1178  int16 arg1 = PG_GETARG_INT16(0);
1179  int64 arg2 = PG_GETARG_INT64(1);
1180  int64 result;
1181 
1182  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1183  ereport(ERROR,
1184  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1185  errmsg("bigint out of range")));
1186  PG_RETURN_INT64(result);
1187 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
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

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int28pl()

Datum int28pl ( PG_FUNCTION_ARGS  )

Definition at line 1148 of file int8.c.

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

1149 {
1150  int16 arg1 = PG_GETARG_INT16(0);
1151  int64 arg2 = PG_GETARG_INT64(1);
1152  int64 result;
1153 
1154  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1155  ereport(ERROR,
1156  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1157  errmsg("bigint out of range")));
1158  PG_RETURN_INT64(result);
1159 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_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

◆ int48()

Datum int48 ( PG_FUNCTION_ARGS  )

Definition at line 1276 of file int8.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT64.

1277 {
1278  int32 arg = PG_GETARG_INT32(0);
1279 
1280  PG_RETURN_INT64((int64) arg);
1281 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
signed int int32
Definition: c.h:347
void * arg

◆ int48div()

Datum int48div ( PG_FUNCTION_ARGS  )

Definition at line 1048 of file int8.c.

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

1049 {
1050  int32 arg1 = PG_GETARG_INT32(0);
1051  int64 arg2 = PG_GETARG_INT64(1);
1052 
1053  if (unlikely(arg2 == 0))
1054  {
1055  ereport(ERROR,
1056  (errcode(ERRCODE_DIVISION_BY_ZERO),
1057  errmsg("division by zero")));
1058  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1059  PG_RETURN_NULL();
1060  }
1061 
1062  /* No overflow is possible */
1063  PG_RETURN_INT64((int64) arg1 / arg2);
1064 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_GETARG_INT64(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int48mi()

Datum int48mi ( PG_FUNCTION_ARGS  )

Definition at line 1020 of file int8.c.

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

1021 {
1022  int32 arg1 = PG_GETARG_INT32(0);
1023  int64 arg2 = PG_GETARG_INT64(1);
1024  int64 result;
1025 
1026  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1027  ereport(ERROR,
1028  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1029  errmsg("bigint out of range")));
1030  PG_RETURN_INT64(result);
1031 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int48mul()

Datum int48mul ( PG_FUNCTION_ARGS  )

Definition at line 1034 of file int8.c.

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

1035 {
1036  int32 arg1 = PG_GETARG_INT32(0);
1037  int64 arg2 = PG_GETARG_INT64(1);
1038  int64 result;
1039 
1040  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1041  ereport(ERROR,
1042  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1043  errmsg("bigint out of range")));
1044  PG_RETURN_INT64(result);
1045 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
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

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int48pl()

Datum int48pl ( PG_FUNCTION_ARGS  )

Definition at line 1006 of file int8.c.

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

1007 {
1008  int32 arg1 = PG_GETARG_INT32(0);
1009  int64 arg2 = PG_GETARG_INT64(1);
1010  int64 result;
1011 
1012  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1013  ereport(ERROR,
1014  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1015  errmsg("bigint out of range")));
1016  PG_RETURN_INT64(result);
1017 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_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

◆ int82()

Datum int82 ( PG_FUNCTION_ARGS  )

Definition at line 1305 of file int8.c.

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

1306 {
1307  int64 arg = PG_GETARG_INT64(0);
1308 
1309  if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
1310  ereport(ERROR,
1311  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1312  errmsg("smallint out of range")));
1313 
1314  PG_RETURN_INT16((int16) arg);
1315 }
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_INT16_MAX
Definition: c.h:439
int errmsg(const char *fmt,...)
Definition: elog.c:822
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int82div()

Datum int82div ( PG_FUNCTION_ARGS  )

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

1110 {
1111  int64 arg1 = PG_GETARG_INT64(0);
1112  int16 arg2 = PG_GETARG_INT16(1);
1113  int64 result;
1114 
1115  if (unlikely(arg2 == 0))
1116  {
1117  ereport(ERROR,
1118  (errcode(ERRCODE_DIVISION_BY_ZERO),
1119  errmsg("division by zero")));
1120  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1121  PG_RETURN_NULL();
1122  }
1123 
1124  /*
1125  * INT64_MIN / -1 is problematic, since the result can't be represented on
1126  * a two's-complement machine. Some machines produce INT64_MIN, some
1127  * produce zero, some throw an exception. We can dodge the problem by
1128  * recognizing that division by -1 is the same as negation.
1129  */
1130  if (arg2 == -1)
1131  {
1132  if (unlikely(arg1 == PG_INT64_MIN))
1133  ereport(ERROR,
1134  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1135  errmsg("bigint out of range")));
1136  result = -arg1;
1137  PG_RETURN_INT64(result);
1138  }
1139 
1140  /* No overflow is possible */
1141 
1142  result = arg1 / arg2;
1143 
1144  PG_RETURN_INT64(result);
1145 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:444
#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_GETARG_INT64(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int82mi()

Datum int82mi ( PG_FUNCTION_ARGS  )

Definition at line 1081 of file int8.c.

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

1082 {
1083  int64 arg1 = PG_GETARG_INT64(0);
1084  int16 arg2 = PG_GETARG_INT16(1);
1085  int64 result;
1086 
1087  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
1088  ereport(ERROR,
1089  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1090  errmsg("bigint out of range")));
1091  PG_RETURN_INT64(result);
1092 }
signed short int16
Definition: c.h:346
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int82mul()

Datum int82mul ( PG_FUNCTION_ARGS  )

Definition at line 1095 of file int8.c.

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

1096 {
1097  int64 arg1 = PG_GETARG_INT64(0);
1098  int16 arg2 = PG_GETARG_INT16(1);
1099  int64 result;
1100 
1101  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
1102  ereport(ERROR,
1103  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1104  errmsg("bigint out of range")));
1105  PG_RETURN_INT64(result);
1106 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
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

◆ 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:346
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int82pl()

Datum int82pl ( PG_FUNCTION_ARGS  )

Definition at line 1067 of file int8.c.

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

1068 {
1069  int64 arg1 = PG_GETARG_INT64(0);
1070  int16 arg2 = PG_GETARG_INT16(1);
1071  int64 result;
1072 
1073  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
1074  ereport(ERROR,
1075  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1076  errmsg("bigint out of range")));
1077  PG_RETURN_INT64(result);
1078 }
signed short int16
Definition: c.h:346
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_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

◆ int84()

Datum int84 ( PG_FUNCTION_ARGS  )

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

1285 {
1286  int64 arg = PG_GETARG_INT64(0);
1287 
1288  if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
1289  ereport(ERROR,
1290  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1291  errmsg("integer out of range")));
1292 
1293  PG_RETURN_INT32((int32) arg);
1294 }
#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 PG_INT32_MAX
Definition: c.h:442
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int84div()

Datum int84div ( PG_FUNCTION_ARGS  )

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

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

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int84mi()

Datum int84mi ( PG_FUNCTION_ARGS  )

Definition at line 939 of file int8.c.

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

940 {
941  int64 arg1 = PG_GETARG_INT64(0);
942  int32 arg2 = PG_GETARG_INT32(1);
943  int64 result;
944 
945  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
946  ereport(ERROR,
947  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
948  errmsg("bigint out of range")));
949  PG_RETURN_INT64(result);
950 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int84mul()

Datum int84mul ( PG_FUNCTION_ARGS  )

Definition at line 953 of file int8.c.

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

954 {
955  int64 arg1 = PG_GETARG_INT64(0);
956  int32 arg2 = PG_GETARG_INT32(1);
957  int64 result;
958 
959  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
960  ereport(ERROR,
961  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
962  errmsg("bigint out of range")));
963  PG_RETURN_INT64(result);
964 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
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

◆ 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:264
signed int int32
Definition: c.h:347
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int84pl()

Datum int84pl ( PG_FUNCTION_ARGS  )

Definition at line 925 of file int8.c.

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

926 {
927  int64 arg1 = PG_GETARG_INT64(0);
928  int32 arg2 = PG_GETARG_INT32(1);
929  int64 result;
930 
931  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
932  ereport(ERROR,
933  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
934  errmsg("bigint out of range")));
935  PG_RETURN_INT64(result);
936 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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_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

◆ 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:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:444
#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_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8and()

Datum int8and ( PG_FUNCTION_ARGS  )

Definition at line 1219 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

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

◆ int8dec()

Datum int8dec ( PG_FUNCTION_ARGS  )

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

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

◆ int8dec_any()

Datum int8dec_any ( PG_FUNCTION_ARGS  )

Definition at line 894 of file int8.c.

References int8dec().

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

◆ 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:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:444
#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_GETARG_INT64(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ 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:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8gcd()

Datum int8gcd ( PG_FUNCTION_ARGS  )

Definition at line 745 of file int8.c.

References int8gcd_internal(), PG_GETARG_INT64, and PG_RETURN_INT64.

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

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

◆ 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:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:357
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
bool scanint8(const char *str, bool errorOK, int64 *result)
Definition: int8.c:55

◆ int8inc()

Datum int8inc ( PG_FUNCTION_ARGS  )

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

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

◆ int8inc_any()

Datum int8inc_any ( PG_FUNCTION_ARGS  )

Definition at line 882 of file int8.c.

References int8inc().

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

◆ int8inc_float8_float8()

Datum int8inc_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 888 of file int8.c.

References int8inc().

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

◆ int8larger()

Datum int8larger ( PG_FUNCTION_ARGS  )

Definition at line 901 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

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

◆ int8lcm()

Datum int8lcm ( PG_FUNCTION_ARGS  )

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

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

◆ 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:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#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_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#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_GETARG_INT64(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ 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:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
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

◆ 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:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8not()

Datum int8not ( PG_FUNCTION_ARGS  )

Definition at line 1246 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

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

◆ int8or()

Datum int8or ( PG_FUNCTION_ARGS  )

Definition at line 1228 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

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

◆ 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:352
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:519
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
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:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
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

◆ 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:357
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
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:360
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:277

◆ int8shl()

Datum int8shl ( PG_FUNCTION_ARGS  )

Definition at line 1254 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1255 {
1256  int64 arg1 = PG_GETARG_INT64(0);
1257  int32 arg2 = PG_GETARG_INT32(1);
1258 
1259  PG_RETURN_INT64(arg1 << arg2);
1260 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
signed int int32
Definition: c.h:347
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8shr()

Datum int8shr ( PG_FUNCTION_ARGS  )

Definition at line 1263 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1264 {
1265  int64 arg1 = PG_GETARG_INT64(0);
1266  int32 arg2 = PG_GETARG_INT32(1);
1267 
1268  PG_RETURN_INT64(arg1 >> arg2);
1269 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
signed int int32
Definition: c.h:347
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8smaller()

Datum int8smaller ( PG_FUNCTION_ARGS  )

Definition at line 913 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

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

◆ 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:357
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:444
#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
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ 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:357
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8xor()

Datum int8xor ( PG_FUNCTION_ARGS  )

Definition at line 1237 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

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

◆ oidtoi8()

Datum oidtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1401 of file int8.c.

References arg, PG_GETARG_OID, and PG_RETURN_INT64.

1402 {
1403  Oid arg = PG_GETARG_OID(0);
1404 
1405  PG_RETURN_INT64((int64) arg);
1406 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
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:608
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:444
#define ereport(elevel, rest)
Definition: elog.h:141
signed char int8
Definition: c.h:345
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208