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/int8.h"
#include "utils/builtins.h"
Include dependency graph for int8.c:

Go to the source code of this file.

Data Structures

struct  generate_series_fctx
 

Macros

#define MAXINT8LEN   25
 

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)
 
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)
 

Macro Definition Documentation

◆ MAXINT8LEN

#define MAXINT8LEN   25

Definition at line 30 of file int8.c.

Referenced by int8out().

Function Documentation

◆ dtoi8()

Datum dtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1208 of file int8.c.

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

Referenced by int8_to_char().

1209 {
1210  float8 num = PG_GETARG_FLOAT8(0);
1211 
1212  /*
1213  * Get rid of any fractional part in the input. This is so we don't fail
1214  * on just-out-of-range values that would round into range. Note
1215  * assumption that rint() will pass through a NaN or Inf unchanged.
1216  */
1217  num = rint(num);
1218 
1219  /*
1220  * Range check. We must be careful here that the boundary values are
1221  * expressed exactly in the float domain. We expect PG_INT64_MIN to be an
1222  * exact power of 2, so it will be represented exactly; but PG_INT64_MAX
1223  * isn't, and might get rounded off, so avoid using it.
1224  */
1225  if (unlikely(num < (float8) PG_INT64_MIN ||
1226  num >= -((float8) PG_INT64_MIN) ||
1227  isnan(num)))
1228  ereport(ERROR,
1229  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1230  errmsg("bigint out of range")));
1231 
1232  PG_RETURN_INT64((int64) num);
1233 }
#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:570
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:491
#define PG_INT64_MIN
Definition: c.h:443
double rint(double x)
Definition: rint.c:21
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define unlikely(x)
Definition: c.h:208

◆ ftoi8()

Datum ftoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1250 of file int8.c.

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

1251 {
1252  float4 num = PG_GETARG_FLOAT4(0);
1253 
1254  /*
1255  * Get rid of any fractional part in the input. This is so we don't fail
1256  * on just-out-of-range values that would round into range. Note
1257  * assumption that rint() will pass through a NaN or Inf unchanged.
1258  */
1259  num = rint(num);
1260 
1261  /*
1262  * Range check. We must be careful here that the boundary values are
1263  * expressed exactly in the float domain. We expect PG_INT64_MIN to be an
1264  * exact power of 2, so it will be represented exactly; but PG_INT64_MAX
1265  * isn't, and might get rounded off, so avoid using it.
1266  */
1267  if (unlikely(num < (float4) PG_INT64_MIN ||
1268  num >= -((float4) PG_INT64_MIN) ||
1269  isnan(num)))
1270  ereport(ERROR,
1271  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1272  errmsg("bigint out of range")));
1273 
1274  PG_RETURN_INT64((int64) num);
1275 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:443
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:490
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define unlikely(x)
Definition: c.h:208

◆ generate_series_int8()

Datum generate_series_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1302 of file int8.c.

References generate_series_step_int8().

1303 {
1304  return generate_series_step_int8(fcinfo);
1305 }
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1308

◆ generate_series_int8_support()

Datum generate_series_int8_support ( PG_FUNCTION_ARGS  )

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

1385 {
1386  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1387  Node *ret = NULL;
1388 
1389  if (IsA(rawreq, SupportRequestRows))
1390  {
1391  /* Try to estimate the number of rows returned */
1392  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1393 
1394  if (is_funcclause(req->node)) /* be paranoid */
1395  {
1396  List *args = ((FuncExpr *) req->node)->args;
1397  Node *arg1,
1398  *arg2,
1399  *arg3;
1400 
1401  /* We can use estimated argument values here */
1402  arg1 = estimate_expression_value(req->root, linitial(args));
1403  arg2 = estimate_expression_value(req->root, lsecond(args));
1404  if (list_length(args) >= 3)
1405  arg3 = estimate_expression_value(req->root, lthird(args));
1406  else
1407  arg3 = NULL;
1408 
1409  /*
1410  * If any argument is constant NULL, we can safely assume that
1411  * zero rows are returned. Otherwise, if they're all non-NULL
1412  * constants, we can calculate the number of rows that will be
1413  * returned. Use double arithmetic to avoid overflow hazards.
1414  */
1415  if ((IsA(arg1, Const) &&
1416  ((Const *) arg1)->constisnull) ||
1417  (IsA(arg2, Const) &&
1418  ((Const *) arg2)->constisnull) ||
1419  (arg3 != NULL && IsA(arg3, Const) &&
1420  ((Const *) arg3)->constisnull))
1421  {
1422  req->rows = 0;
1423  ret = (Node *) req;
1424  }
1425  else if (IsA(arg1, Const) &&
1426  IsA(arg2, Const) &&
1427  (arg3 == NULL || IsA(arg3, Const)))
1428  {
1429  double start,
1430  finish,
1431  step;
1432 
1433  start = DatumGetInt64(((Const *) arg1)->constvalue);
1434  finish = DatumGetInt64(((Const *) arg2)->constvalue);
1435  step = arg3 ? DatumGetInt64(((Const *) arg3)->constvalue) : 1;
1436 
1437  /* This equation works for either sign of step */
1438  if (step != 0)
1439  {
1440  req->rows = floor((finish - start + step) / step);
1441  ret = (Node *) req;
1442  }
1443  }
1444  }
1445  }
1446 
1447  PG_RETURN_POINTER(ret);
1448 }
#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:2286
Definition: nodes.h:525
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define lsecond(l)
Definition: pg_list.h:200
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:56
struct PlannerInfo * root
Definition: supportnodes.h:163
#define linitial(l)
Definition: pg_list.h:195
#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 1308 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().

1309 {
1310  FuncCallContext *funcctx;
1311  generate_series_fctx *fctx;
1312  int64 result;
1313  MemoryContext oldcontext;
1314 
1315  /* stuff done only on the first call of the function */
1316  if (SRF_IS_FIRSTCALL())
1317  {
1318  int64 start = PG_GETARG_INT64(0);
1319  int64 finish = PG_GETARG_INT64(1);
1320  int64 step = 1;
1321 
1322  /* see if we were given an explicit step size */
1323  if (PG_NARGS() == 3)
1324  step = PG_GETARG_INT64(2);
1325  if (step == 0)
1326  ereport(ERROR,
1327  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1328  errmsg("step size cannot equal zero")));
1329 
1330  /* create a function context for cross-call persistence */
1331  funcctx = SRF_FIRSTCALL_INIT();
1332 
1333  /*
1334  * switch to memory context appropriate for multiple function calls
1335  */
1336  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1337 
1338  /* allocate memory for user context */
1339  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1340 
1341  /*
1342  * Use fctx to keep state from call to call. Seed current with the
1343  * original start value
1344  */
1345  fctx->current = start;
1346  fctx->finish = finish;
1347  fctx->step = step;
1348 
1349  funcctx->user_fctx = fctx;
1350  MemoryContextSwitchTo(oldcontext);
1351  }
1352 
1353  /* stuff done on every call of the function */
1354  funcctx = SRF_PERCALL_SETUP();
1355 
1356  /*
1357  * get the saved state and use current as the result for this iteration
1358  */
1359  fctx = funcctx->user_fctx;
1360  result = fctx->current;
1361 
1362  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1363  (fctx->step < 0 && fctx->current >= fctx->finish))
1364  {
1365  /*
1366  * Increment current in preparation for next iteration. If next-value
1367  * computation overflows, this is the final result.
1368  */
1369  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1370  fctx->step = 0;
1371 
1372  /* do when there is more left to send */
1373  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1374  }
1375  else
1376  /* do when there is no more left */
1377  SRF_RETURN_DONE(funcctx);
1378 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:283
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:570
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:287
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:289
#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:102
#define PG_NARGS()
Definition: fmgr.h:198
void * user_fctx
Definition: funcapi.h:83
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:307
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:285

◆ i8tod()

Datum i8tod ( PG_FUNCTION_ARGS  )

Definition at line 1194 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT8.

1195 {
1196  int64 arg = PG_GETARG_INT64(0);
1197  float8 result;
1198 
1199  result = arg;
1200 
1201  PG_RETURN_FLOAT8(result);
1202 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
double float8
Definition: c.h:491
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ i8tof()

Datum i8tof ( PG_FUNCTION_ARGS  )

Definition at line 1236 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT4.

1237 {
1238  int64 arg = PG_GETARG_INT64(0);
1239  float4 result;
1240 
1241  result = arg;
1242 
1243  PG_RETURN_FLOAT4(result);
1244 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:355
float float4
Definition: c.h:490
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ i8tooid()

Datum i8tooid ( PG_FUNCTION_ARGS  )

Definition at line 1278 of file int8.c.

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

1279 {
1280  int64 arg = PG_GETARG_INT64(0);
1281 
1282  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1283  ereport(ERROR,
1284  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1285  errmsg("OID out of range")));
1286 
1287  PG_RETURN_OID((Oid) arg);
1288 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_UINT32_MAX
Definition: c.h:442
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:784
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 482 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.

483 {
484  int64 val = PG_GETARG_INT64(0);
485  int64 base = PG_GETARG_INT64(1);
486  int64 offset = PG_GETARG_INT64(2);
487  bool sub = PG_GETARG_BOOL(3);
488  bool less = PG_GETARG_BOOL(4);
489  int64 sum;
490 
491  if (offset < 0)
492  ereport(ERROR,
493  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
494  errmsg("invalid preceding or following size in window function")));
495 
496  if (sub)
497  offset = -offset; /* cannot overflow */
498 
499  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
500  {
501  /*
502  * If sub is false, the true sum is surely more than val, so correct
503  * answer is the same as "less". If sub is true, the true sum is
504  * surely less than val, so the answer is "!less".
505  */
506  PG_RETURN_BOOL(sub ? !less : less);
507  }
508 
509  if (less)
510  PG_RETURN_BOOL(val <= sum);
511  else
512  PG_RETURN_BOOL(val >= sum);
513 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
long val
Definition: informix.c:684

◆ int28()

Datum int28 ( PG_FUNCTION_ARGS  )

Definition at line 1173 of file int8.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT64.

1174 {
1175  int16 arg = PG_GETARG_INT16(0);
1176 
1177  PG_RETURN_INT64((int64) arg);
1178 }
signed short int16
Definition: c.h:345
#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 1066 of file int8.c.

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

1067 {
1068  int16 arg1 = PG_GETARG_INT16(0);
1069  int64 arg2 = PG_GETARG_INT64(1);
1070 
1071  if (unlikely(arg2 == 0))
1072  {
1073  ereport(ERROR,
1074  (errcode(ERRCODE_DIVISION_BY_ZERO),
1075  errmsg("division by zero")));
1076  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1077  PG_RETURN_NULL();
1078  }
1079 
1080  /* No overflow is possible */
1081  PG_RETURN_INT64((int64) arg1 / arg2);
1082 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#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 422 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

423 {
424  int16 val1 = PG_GETARG_INT16(0);
425  int64 val2 = PG_GETARG_INT64(1);
426 
427  PG_RETURN_BOOL(val1 == val2);
428 }
signed short int16
Definition: c.h:345
#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 467 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

468 {
469  int16 val1 = PG_GETARG_INT16(0);
470  int64 val2 = PG_GETARG_INT64(1);
471 
472  PG_RETURN_BOOL(val1 >= val2);
473 }
signed short int16
Definition: c.h:345
#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 449 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

450 {
451  int16 val1 = PG_GETARG_INT16(0);
452  int64 val2 = PG_GETARG_INT64(1);
453 
454  PG_RETURN_BOOL(val1 > val2);
455 }
signed short int16
Definition: c.h:345
#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 458 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

459 {
460  int16 val1 = PG_GETARG_INT16(0);
461  int64 val2 = PG_GETARG_INT64(1);
462 
463  PG_RETURN_BOOL(val1 <= val2);
464 }
signed short int16
Definition: c.h:345
#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 440 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

441 {
442  int16 val1 = PG_GETARG_INT16(0);
443  int64 val2 = PG_GETARG_INT64(1);
444 
445  PG_RETURN_BOOL(val1 < val2);
446 }
signed short int16
Definition: c.h:345
#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 1038 of file int8.c.

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

1039 {
1040  int16 arg1 = PG_GETARG_INT16(0);
1041  int64 arg2 = PG_GETARG_INT64(1);
1042  int64 result;
1043 
1044  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1045  ereport(ERROR,
1046  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1047  errmsg("bigint out of range")));
1048  PG_RETURN_INT64(result);
1049 }
signed short int16
Definition: c.h:345
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:570
#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:784
#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 1052 of file int8.c.

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

1053 {
1054  int16 arg1 = PG_GETARG_INT16(0);
1055  int64 arg2 = PG_GETARG_INT64(1);
1056  int64 result;
1057 
1058  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1059  ereport(ERROR,
1060  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1061  errmsg("bigint out of range")));
1062  PG_RETURN_INT64(result);
1063 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#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 431 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

432 {
433  int16 val1 = PG_GETARG_INT16(0);
434  int64 val2 = PG_GETARG_INT64(1);
435 
436  PG_RETURN_BOOL(val1 != val2);
437 }
signed short int16
Definition: c.h:345
#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 1024 of file int8.c.

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

1025 {
1026  int16 arg1 = PG_GETARG_INT16(0);
1027  int64 arg2 = PG_GETARG_INT64(1);
1028  int64 result;
1029 
1030  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1031  ereport(ERROR,
1032  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1033  errmsg("bigint out of range")));
1034  PG_RETURN_INT64(result);
1035 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#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 1152 of file int8.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT64.

1153 {
1154  int32 arg = PG_GETARG_INT32(0);
1155 
1156  PG_RETURN_INT64((int64) arg);
1157 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
signed int int32
Definition: c.h:346
void * arg

◆ int48div()

Datum int48div ( PG_FUNCTION_ARGS  )

Definition at line 924 of file int8.c.

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

925 {
926  int32 arg1 = PG_GETARG_INT32(0);
927  int64 arg2 = PG_GETARG_INT64(1);
928 
929  if (unlikely(arg2 == 0))
930  {
931  ereport(ERROR,
932  (errcode(ERRCODE_DIVISION_BY_ZERO),
933  errmsg("division by zero")));
934  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
935  PG_RETURN_NULL();
936  }
937 
938  /* No overflow is possible */
939  PG_RETURN_INT64((int64) arg1 / arg2);
940 }
#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:570
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 308 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

309 {
310  int32 val1 = PG_GETARG_INT32(0);
311  int64 val2 = PG_GETARG_INT64(1);
312 
313  PG_RETURN_BOOL(val1 == val2);
314 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 353 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

354 {
355  int32 val1 = PG_GETARG_INT32(0);
356  int64 val2 = PG_GETARG_INT64(1);
357 
358  PG_RETURN_BOOL(val1 >= val2);
359 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 335 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

336 {
337  int32 val1 = PG_GETARG_INT32(0);
338  int64 val2 = PG_GETARG_INT64(1);
339 
340  PG_RETURN_BOOL(val1 > val2);
341 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 344 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

345 {
346  int32 val1 = PG_GETARG_INT32(0);
347  int64 val2 = PG_GETARG_INT64(1);
348 
349  PG_RETURN_BOOL(val1 <= val2);
350 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 326 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

327 {
328  int32 val1 = PG_GETARG_INT32(0);
329  int64 val2 = PG_GETARG_INT64(1);
330 
331  PG_RETURN_BOOL(val1 < val2);
332 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 896 of file int8.c.

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

897 {
898  int32 arg1 = PG_GETARG_INT32(0);
899  int64 arg2 = PG_GETARG_INT64(1);
900  int64 result;
901 
902  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
903  ereport(ERROR,
904  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
905  errmsg("bigint out of range")));
906  PG_RETURN_INT64(result);
907 }
#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:570
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 910 of file int8.c.

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

911 {
912  int32 arg1 = PG_GETARG_INT32(0);
913  int64 arg2 = PG_GETARG_INT64(1);
914  int64 result;
915 
916  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
917  ereport(ERROR,
918  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
919  errmsg("bigint out of range")));
920  PG_RETURN_INT64(result);
921 }
#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:570
signed int int32
Definition: c.h:346
#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:784
#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 317 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

318 {
319  int32 val1 = PG_GETARG_INT32(0);
320  int64 val2 = PG_GETARG_INT64(1);
321 
322  PG_RETURN_BOOL(val1 != val2);
323 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 882 of file int8.c.

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

883 {
884  int32 arg1 = PG_GETARG_INT32(0);
885  int64 arg2 = PG_GETARG_INT64(1);
886  int64 result;
887 
888  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
889  ereport(ERROR,
890  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
891  errmsg("bigint out of range")));
892  PG_RETURN_INT64(result);
893 }
#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:570
signed int int32
Definition: c.h:346
#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:784
#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 1181 of file int8.c.

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

1182 {
1183  int64 arg = PG_GETARG_INT64(0);
1184 
1185  if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
1186  ereport(ERROR,
1187  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1188  errmsg("smallint out of range")));
1189 
1190  PG_RETURN_INT16((int16) arg);
1191 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:437
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_INT16_MAX
Definition: c.h:438
int errmsg(const char *fmt,...)
Definition: elog.c:784
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 985 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.

986 {
987  int64 arg1 = PG_GETARG_INT64(0);
988  int16 arg2 = PG_GETARG_INT16(1);
989  int64 result;
990 
991  if (unlikely(arg2 == 0))
992  {
993  ereport(ERROR,
994  (errcode(ERRCODE_DIVISION_BY_ZERO),
995  errmsg("division by zero")));
996  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
997  PG_RETURN_NULL();
998  }
999 
1000  /*
1001  * INT64_MIN / -1 is problematic, since the result can't be represented on
1002  * a two's-complement machine. Some machines produce INT64_MIN, some
1003  * produce zero, some throw an exception. We can dodge the problem by
1004  * recognizing that division by -1 is the same as negation.
1005  */
1006  if (arg2 == -1)
1007  {
1008  if (unlikely(arg1 == PG_INT64_MIN))
1009  ereport(ERROR,
1010  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1011  errmsg("bigint out of range")));
1012  result = -arg1;
1013  PG_RETURN_INT64(result);
1014  }
1015 
1016  /* No overflow is possible */
1017 
1018  result = arg1 / arg2;
1019 
1020  PG_RETURN_INT64(result);
1021 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:443
#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:784
#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 365 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

366 {
367  int64 val1 = PG_GETARG_INT64(0);
368  int16 val2 = PG_GETARG_INT16(1);
369 
370  PG_RETURN_BOOL(val1 == val2);
371 }
signed short int16
Definition: c.h:345
#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 410 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

411 {
412  int64 val1 = PG_GETARG_INT64(0);
413  int16 val2 = PG_GETARG_INT16(1);
414 
415  PG_RETURN_BOOL(val1 >= val2);
416 }
signed short int16
Definition: c.h:345
#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 392 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

393 {
394  int64 val1 = PG_GETARG_INT64(0);
395  int16 val2 = PG_GETARG_INT16(1);
396 
397  PG_RETURN_BOOL(val1 > val2);
398 }
signed short int16
Definition: c.h:345
#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 401 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

402 {
403  int64 val1 = PG_GETARG_INT64(0);
404  int16 val2 = PG_GETARG_INT16(1);
405 
406  PG_RETURN_BOOL(val1 <= val2);
407 }
signed short int16
Definition: c.h:345
#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 383 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

384 {
385  int64 val1 = PG_GETARG_INT64(0);
386  int16 val2 = PG_GETARG_INT16(1);
387 
388  PG_RETURN_BOOL(val1 < val2);
389 }
signed short int16
Definition: c.h:345
#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 957 of file int8.c.

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

958 {
959  int64 arg1 = PG_GETARG_INT64(0);
960  int16 arg2 = PG_GETARG_INT16(1);
961  int64 result;
962 
963  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
964  ereport(ERROR,
965  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
966  errmsg("bigint out of range")));
967  PG_RETURN_INT64(result);
968 }
signed short int16
Definition: c.h:345
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:570
#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:784
#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 971 of file int8.c.

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

972 {
973  int64 arg1 = PG_GETARG_INT64(0);
974  int16 arg2 = PG_GETARG_INT16(1);
975  int64 result;
976 
977  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
978  ereport(ERROR,
979  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
980  errmsg("bigint out of range")));
981  PG_RETURN_INT64(result);
982 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#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 374 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

375 {
376  int64 val1 = PG_GETARG_INT64(0);
377  int16 val2 = PG_GETARG_INT16(1);
378 
379  PG_RETURN_BOOL(val1 != val2);
380 }
signed short int16
Definition: c.h:345
#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 943 of file int8.c.

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

944 {
945  int64 arg1 = PG_GETARG_INT64(0);
946  int16 arg2 = PG_GETARG_INT16(1);
947  int64 result;
948 
949  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
950  ereport(ERROR,
951  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
952  errmsg("bigint out of range")));
953  PG_RETURN_INT64(result);
954 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#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 1160 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().

1161 {
1162  int64 arg = PG_GETARG_INT64(0);
1163 
1164  if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
1165  ereport(ERROR,
1166  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1167  errmsg("integer out of range")));
1168 
1169  PG_RETURN_INT32((int32) arg);
1170 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
int errcode(int sqlerrcode)
Definition: elog.c:570
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:440
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_INT32_MAX
Definition: c.h:441
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 843 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.

844 {
845  int64 arg1 = PG_GETARG_INT64(0);
846  int32 arg2 = PG_GETARG_INT32(1);
847  int64 result;
848 
849  if (arg2 == 0)
850  {
851  ereport(ERROR,
852  (errcode(ERRCODE_DIVISION_BY_ZERO),
853  errmsg("division by zero")));
854  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
855  PG_RETURN_NULL();
856  }
857 
858  /*
859  * INT64_MIN / -1 is problematic, since the result can't be represented on
860  * a two's-complement machine. Some machines produce INT64_MIN, some
861  * produce zero, some throw an exception. We can dodge the problem by
862  * recognizing that division by -1 is the same as negation.
863  */
864  if (arg2 == -1)
865  {
866  if (unlikely(arg1 == PG_INT64_MIN))
867  ereport(ERROR,
868  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
869  errmsg("bigint out of range")));
870  result = -arg1;
871  PG_RETURN_INT64(result);
872  }
873 
874  /* No overflow is possible */
875 
876  result = arg1 / arg2;
877 
878  PG_RETURN_INT64(result);
879 }
#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:570
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:443
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 251 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

252 {
253  int64 val1 = PG_GETARG_INT64(0);
254  int32 val2 = PG_GETARG_INT32(1);
255 
256  PG_RETURN_BOOL(val1 == val2);
257 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 296 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

297 {
298  int64 val1 = PG_GETARG_INT64(0);
299  int32 val2 = PG_GETARG_INT32(1);
300 
301  PG_RETURN_BOOL(val1 >= val2);
302 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 278 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

279 {
280  int64 val1 = PG_GETARG_INT64(0);
281  int32 val2 = PG_GETARG_INT32(1);
282 
283  PG_RETURN_BOOL(val1 > val2);
284 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 287 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

288 {
289  int64 val1 = PG_GETARG_INT64(0);
290  int32 val2 = PG_GETARG_INT32(1);
291 
292  PG_RETURN_BOOL(val1 <= val2);
293 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 269 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

270 {
271  int64 val1 = PG_GETARG_INT64(0);
272  int32 val2 = PG_GETARG_INT32(1);
273 
274  PG_RETURN_BOOL(val1 < val2);
275 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 815 of file int8.c.

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

816 {
817  int64 arg1 = PG_GETARG_INT64(0);
818  int32 arg2 = PG_GETARG_INT32(1);
819  int64 result;
820 
821  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
822  ereport(ERROR,
823  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
824  errmsg("bigint out of range")));
825  PG_RETURN_INT64(result);
826 }
#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:570
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 829 of file int8.c.

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

830 {
831  int64 arg1 = PG_GETARG_INT64(0);
832  int32 arg2 = PG_GETARG_INT32(1);
833  int64 result;
834 
835  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
836  ereport(ERROR,
837  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
838  errmsg("bigint out of range")));
839  PG_RETURN_INT64(result);
840 }
#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:570
signed int int32
Definition: c.h:346
#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:784
#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 260 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

261 {
262  int64 val1 = PG_GETARG_INT64(0);
263  int32 val2 = PG_GETARG_INT32(1);
264 
265  PG_RETURN_BOOL(val1 != val2);
266 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
#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 801 of file int8.c.

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

802 {
803  int64 arg1 = PG_GETARG_INT64(0);
804  int32 arg2 = PG_GETARG_INT32(1);
805  int64 result;
806 
807  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
808  ereport(ERROR,
809  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
810  errmsg("bigint out of range")));
811  PG_RETURN_INT64(result);
812 }
#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:570
signed int int32
Definition: c.h:346
#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:784
#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 627 of file int8.c.

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

628 {
629  int64 arg1 = PG_GETARG_INT64(0);
630  int64 result;
631 
632  if (unlikely(arg1 == PG_INT64_MIN))
633  ereport(ERROR,
634  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
635  errmsg("bigint out of range")));
636  result = (arg1 < 0) ? -arg1 : arg1;
637  PG_RETURN_INT64(result);
638 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:443
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 1095 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1096 {
1097  int64 arg1 = PG_GETARG_INT64(0);
1098  int64 arg2 = PG_GETARG_INT64(1);
1099 
1100  PG_RETURN_INT64(arg1 & arg2);
1101 }
#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 711 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().

712 {
713  /*
714  * When int8 is pass-by-reference, we provide this special case to avoid
715  * palloc overhead for COUNT(): when called as an aggregate, we know that
716  * the argument is modifiable local storage, so just update it in-place.
717  * (If int8 is pass-by-value, then of course this is useless as well as
718  * incorrect, so just ifdef it out.)
719  */
720 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
721  if (AggCheckCallContext(fcinfo, NULL))
722  {
723  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
724 
725  if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
726  ereport(ERROR,
727  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
728  errmsg("bigint out of range")));
729  PG_RETURN_POINTER(arg);
730  }
731  else
732 #endif
733  {
734  /* Not called as an aggregate, so just do it the dumb way */
735  int64 arg = PG_GETARG_INT64(0);
736  int64 result;
737 
738  if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
739  ereport(ERROR,
740  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
741  errmsg("bigint out of range")));
742 
743  PG_RETURN_INT64(result);
744  }
745 }
#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:570
#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:3572
int errmsg(const char *fmt,...)
Definition: elog.c:784
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 770 of file int8.c.

References int8dec().

771 {
772  return int8dec(fcinfo);
773 }
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:711

◆ int8div()

Datum int8div ( PG_FUNCTION_ARGS  )

Definition at line 585 of file int8.c.

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

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

References PG_GETARG_INT64, and PG_RETURN_BOOL.

195 {
196  int64 val1 = PG_GETARG_INT64(0);
197  int64 val2 = PG_GETARG_INT64(1);
198 
199  PG_RETURN_BOOL(val1 == val2);
200 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8ge()

Datum int8ge ( PG_FUNCTION_ARGS  )

Definition at line 239 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

240 {
241  int64 val1 = PG_GETARG_INT64(0);
242  int64 val2 = PG_GETARG_INT64(1);
243 
244  PG_RETURN_BOOL(val1 >= val2);
245 }
#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 221 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

222 {
223  int64 val1 = PG_GETARG_INT64(0);
224  int64 val2 = PG_GETARG_INT64(1);
225 
226  PG_RETURN_BOOL(val1 > val2);
227 }
#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 136 of file int8.c.

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

Referenced by defGetInt64().

137 {
138  char *str = PG_GETARG_CSTRING(0);
139  int64 result;
140 
141  (void) scanint8(str, false, &result);
142  PG_RETURN_INT64(result);
143 }
#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:57

◆ int8inc()

Datum int8inc ( PG_FUNCTION_ARGS  )

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

674 {
675  /*
676  * When int8 is pass-by-reference, we provide this special case to avoid
677  * palloc overhead for COUNT(): when called as an aggregate, we know that
678  * the argument is modifiable local storage, so just update it in-place.
679  * (If int8 is pass-by-value, then of course this is useless as well as
680  * incorrect, so just ifdef it out.)
681  */
682 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
683  if (AggCheckCallContext(fcinfo, NULL))
684  {
685  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
686 
687  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
688  ereport(ERROR,
689  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
690  errmsg("bigint out of range")));
691 
692  PG_RETURN_POINTER(arg);
693  }
694  else
695 #endif
696  {
697  /* Not called as an aggregate, so just do it the dumb way */
698  int64 arg = PG_GETARG_INT64(0);
699  int64 result;
700 
701  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
702  ereport(ERROR,
703  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
704  errmsg("bigint out of range")));
705 
706  PG_RETURN_INT64(result);
707  }
708 }
#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:570
#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:3572
int errmsg(const char *fmt,...)
Definition: elog.c:784
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 758 of file int8.c.

References int8inc().

759 {
760  return int8inc(fcinfo);
761 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:673

◆ int8inc_float8_float8()

Datum int8inc_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 764 of file int8.c.

References int8inc().

765 {
766  return int8inc(fcinfo);
767 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:673

◆ int8larger()

Datum int8larger ( PG_FUNCTION_ARGS  )

Definition at line 777 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

778 {
779  int64 arg1 = PG_GETARG_INT64(0);
780  int64 arg2 = PG_GETARG_INT64(1);
781  int64 result;
782 
783  result = ((arg1 > arg2) ? arg1 : arg2);
784 
785  PG_RETURN_INT64(result);
786 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8le()

Datum int8le ( PG_FUNCTION_ARGS  )

Definition at line 230 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

231 {
232  int64 val1 = PG_GETARG_INT64(0);
233  int64 val2 = PG_GETARG_INT64(1);
234 
235  PG_RETURN_BOOL(val1 <= val2);
236 }
#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 212 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

213 {
214  int64 val1 = PG_GETARG_INT64(0);
215  int64 val2 = PG_GETARG_INT64(1);
216 
217  PG_RETURN_BOOL(val1 < val2);
218 }
#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 557 of file int8.c.

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

558 {
559  int64 arg1 = PG_GETARG_INT64(0);
560  int64 arg2 = PG_GETARG_INT64(1);
561  int64 result;
562 
563  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
564  ereport(ERROR,
565  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
566  errmsg("bigint out of range")));
567  PG_RETURN_INT64(result);
568 }
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:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 644 of file int8.c.

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

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

572 {
573  int64 arg1 = PG_GETARG_INT64(0);
574  int64 arg2 = PG_GETARG_INT64(1);
575  int64 result;
576 
577  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
578  ereport(ERROR,
579  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
580  errmsg("bigint out of range")));
581  PG_RETURN_INT64(result);
582 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#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 203 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

204 {
205  int64 val1 = PG_GETARG_INT64(0);
206  int64 val2 = PG_GETARG_INT64(1);
207 
208  PG_RETURN_BOOL(val1 != val2);
209 }
#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 1122 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1123 {
1124  int64 arg1 = PG_GETARG_INT64(0);
1125 
1126  PG_RETURN_INT64(~arg1);
1127 }
#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 1104 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1105 {
1106  int64 arg1 = PG_GETARG_INT64(0);
1107  int64 arg2 = PG_GETARG_INT64(1);
1108 
1109  PG_RETURN_INT64(arg1 | arg2);
1110 }
#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 149 of file int8.c.

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

Referenced by int8_to_char().

150 {
151  int64 val = PG_GETARG_INT64(0);
152  char buf[MAXINT8LEN + 1];
153  char *result;
154 
155  pg_lltoa(val, buf);
156  result = pstrdup(buf);
157  PG_RETURN_CSTRING(result);
158 }
#define MAXINT8LEN
Definition: int8.c:30
char * pstrdup(const char *in)
Definition: mcxt.c:1186
static char * buf
Definition: pg_test_fsync.c:68
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:339
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
long val
Definition: informix.c:684

◆ int8pl()

Datum int8pl ( PG_FUNCTION_ARGS  )

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

544 {
545  int64 arg1 = PG_GETARG_INT64(0);
546  int64 arg2 = PG_GETARG_INT64(1);
547  int64 result;
548 
549  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
550  ereport(ERROR,
551  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
552  errmsg("bigint out of range")));
553  PG_RETURN_INT64(result);
554 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:784
#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 164 of file int8.c.

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

165 {
167 
169 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
static char * buf
Definition: pg_test_fsync.c:68
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

◆ int8send()

Datum int8send ( PG_FUNCTION_ARGS  )

Definition at line 175 of file int8.c.

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

176 {
177  int64 arg1 = PG_GETARG_INT64(0);
179 
180  pq_begintypsend(&buf);
181  pq_sendint64(&buf, arg1);
183 }
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:68
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8shl()

Datum int8shl ( PG_FUNCTION_ARGS  )

Definition at line 1130 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1131 {
1132  int64 arg1 = PG_GETARG_INT64(0);
1133  int32 arg2 = PG_GETARG_INT32(1);
1134 
1135  PG_RETURN_INT64(arg1 << arg2);
1136 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
signed int int32
Definition: c.h:346
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8shr()

Datum int8shr ( PG_FUNCTION_ARGS  )

Definition at line 1139 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1140 {
1141  int64 arg1 = PG_GETARG_INT64(0);
1142  int32 arg2 = PG_GETARG_INT32(1);
1143 
1144  PG_RETURN_INT64(arg1 >> arg2);
1145 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
signed int int32
Definition: c.h:346
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ int8smaller()

Datum int8smaller ( PG_FUNCTION_ARGS  )

Definition at line 789 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

790 {
791  int64 arg1 = PG_GETARG_INT64(0);
792  int64 arg2 = PG_GETARG_INT64(1);
793  int64 result;
794 
795  result = ((arg1 < arg2) ? arg1 : arg2);
796 
797  PG_RETURN_INT64(result);
798 }
#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 521 of file int8.c.

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

522 {
523  int64 arg = PG_GETARG_INT64(0);
524  int64 result;
525 
526  if (unlikely(arg == PG_INT64_MIN))
527  ereport(ERROR,
528  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
529  errmsg("bigint out of range")));
530  result = -arg;
531  PG_RETURN_INT64(result);
532 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:443
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
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 535 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_INT64.

536 {
537  int64 arg = PG_GETARG_INT64(0);
538 
539  PG_RETURN_INT64(arg);
540 }
#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 1113 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1114 {
1115  int64 arg1 = PG_GETARG_INT64(0);
1116  int64 arg2 = PG_GETARG_INT64(1);
1117 
1118  PG_RETURN_INT64(arg1 ^ arg2);
1119 }
#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 1291 of file int8.c.

References arg, PG_GETARG_OID, and PG_RETURN_INT64.

1292 {
1293  Oid arg = PG_GETARG_OID(0);
1294 
1295  PG_RETURN_INT64((int64) arg);
1296 }
#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 57 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().

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