PostgreSQL Source Code  git master
int8.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include "common/int.h"
#include "funcapi.h"
#include "libpq/pqformat.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)
 

Macro Definition Documentation

◆ MAXINT8LEN

#define MAXINT8LEN   25

Definition at line 28 of file int8.c.

Referenced by int8out().

Function Documentation

◆ dtoi8()

Datum dtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1205 of file int8.c.

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

Referenced by int8_to_char().

1206 {
1208  int64 result;
1209 
1210  /* Round arg to nearest integer (but it's still in float form) */
1211  arg = rint(arg);
1212 
1213  if (unlikely(arg < (double) PG_INT64_MIN) ||
1214  unlikely(arg > (double) PG_INT64_MAX) ||
1215  unlikely(isnan(arg)))
1216  ereport(ERROR,
1217  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1218  errmsg("bigint out of range")));
1219 
1220  result = (int64) arg;
1221 
1222  PG_RETURN_INT64(result);
1223 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:251
#define PG_INT64_MAX
Definition: c.h:411
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:458
#define PG_INT64_MIN
Definition: c.h:410
double rint(double x)
Definition: rint.c:22
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208

◆ ftoi8()

Datum ftoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1240 of file int8.c.

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

1241 {
1243  float8 darg;
1244 
1245  /* Round arg to nearest integer (but it's still in float form) */
1246  darg = rint(arg);
1247 
1248  if (unlikely(arg < (float4) PG_INT64_MIN) ||
1249  unlikely(arg > (float4) PG_INT64_MAX) ||
1250  unlikely(isnan(arg)))
1251  ereport(ERROR,
1252  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1253  errmsg("bigint out of range")));
1254 
1255  PG_RETURN_INT64((int64) darg);
1256 }
#define PG_INT64_MAX
Definition: c.h:411
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:458
#define PG_INT64_MIN
Definition: c.h:410
double rint(double x)
Definition: rint.c:22
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:250
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:457
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208

◆ generate_series_int8()

Datum generate_series_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1283 of file int8.c.

References generate_series_step_int8().

1284 {
1285  return generate_series_step_int8(fcinfo);
1286 }
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1289

◆ generate_series_step_int8()

Datum generate_series_step_int8 ( PG_FUNCTION_ARGS  )

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

1290 {
1291  FuncCallContext *funcctx;
1292  generate_series_fctx *fctx;
1293  int64 result;
1294  MemoryContext oldcontext;
1295 
1296  /* stuff done only on the first call of the function */
1297  if (SRF_IS_FIRSTCALL())
1298  {
1299  int64 start = PG_GETARG_INT64(0);
1300  int64 finish = PG_GETARG_INT64(1);
1301  int64 step = 1;
1302 
1303  /* see if we were given an explicit step size */
1304  if (PG_NARGS() == 3)
1305  step = PG_GETARG_INT64(2);
1306  if (step == 0)
1307  ereport(ERROR,
1308  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1309  errmsg("step size cannot equal zero")));
1310 
1311  /* create a function context for cross-call persistence */
1312  funcctx = SRF_FIRSTCALL_INIT();
1313 
1314  /*
1315  * switch to memory context appropriate for multiple function calls
1316  */
1317  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1318 
1319  /* allocate memory for user context */
1320  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1321 
1322  /*
1323  * Use fctx to keep state from call to call. Seed current with the
1324  * original start value
1325  */
1326  fctx->current = start;
1327  fctx->finish = finish;
1328  fctx->step = step;
1329 
1330  funcctx->user_fctx = fctx;
1331  MemoryContextSwitchTo(oldcontext);
1332  }
1333 
1334  /* stuff done on every call of the function */
1335  funcctx = SRF_PERCALL_SETUP();
1336 
1337  /*
1338  * get the saved state and use current as the result for this iteration
1339  */
1340  fctx = funcctx->user_fctx;
1341  result = fctx->current;
1342 
1343  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1344  (fctx->step < 0 && fctx->current >= fctx->finish))
1345  {
1346  /*
1347  * Increment current in preparation for next iteration. If next-value
1348  * computation overflows, this is the final result.
1349  */
1350  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1351  fctx->step = 0;
1352 
1353  /* do when there is more left to send */
1354  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1355  }
1356  else
1357  /* do when there is no more left */
1358  SRF_RETURN_DONE(funcctx);
1359 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:294
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:298
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:300
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1877
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:167
int32 current
Definition: int.c:45
int32 finish
Definition: int.c:46
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:110
#define PG_NARGS()
Definition: fmgr.h:173
void * user_fctx
Definition: funcapi.h:91
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:318
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:296

◆ i8tod()

Datum i8tod ( PG_FUNCTION_ARGS  )

Definition at line 1191 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT8.

1192 {
1193  int64 arg = PG_GETARG_INT64(0);
1194  float8 result;
1195 
1196  result = arg;
1197 
1198  PG_RETURN_FLOAT8(result);
1199 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double float8
Definition: c.h:458
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ i8tof()

Datum i8tof ( PG_FUNCTION_ARGS  )

Definition at line 1226 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT4.

1227 {
1228  int64 arg = PG_GETARG_INT64(0);
1229  float4 result;
1230 
1231  result = arg;
1232 
1233  PG_RETURN_FLOAT4(result);
1234 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:330
float float4
Definition: c.h:457
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ i8tooid()

Datum i8tooid ( PG_FUNCTION_ARGS  )

Definition at line 1259 of file int8.c.

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

1260 {
1261  int64 arg = PG_GETARG_INT64(0);
1262 
1263  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1264  ereport(ERROR,
1265  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1266  errmsg("OID out of range")));
1267 
1268  PG_RETURN_OID((Oid) arg);
1269 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_UINT32_MAX
Definition: c.h:409
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
#define PG_RETURN_OID(x)
Definition: fmgr.h:325

◆ in_range_int8_int8()

Datum in_range_int8_int8 ( PG_FUNCTION_ARGS  )

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

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

◆ int28()

Datum int28 ( PG_FUNCTION_ARGS  )

Definition at line 1170 of file int8.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT64.

1171 {
1172  int16 arg = PG_GETARG_INT16(0);
1173 
1174  PG_RETURN_INT64((int64) arg);
1175 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
void * arg

◆ int28div()

Datum int28div ( PG_FUNCTION_ARGS  )

Definition at line 1063 of file int8.c.

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

1064 {
1065  int16 arg1 = PG_GETARG_INT16(0);
1066  int64 arg2 = PG_GETARG_INT64(1);
1067 
1068  if (unlikely(arg2 == 0))
1069  {
1070  ereport(ERROR,
1071  (errcode(ERRCODE_DIVISION_BY_ZERO),
1072  errmsg("division by zero")));
1073  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1074  PG_RETURN_NULL();
1075  }
1076 
1077  /* No overflow is possible */
1078  PG_RETURN_INT64((int64) arg1 / arg2);
1079 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int28eq()

Datum int28eq ( PG_FUNCTION_ARGS  )

Definition at line 419 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

420 {
421  int16 val1 = PG_GETARG_INT16(0);
422  int64 val2 = PG_GETARG_INT64(1);
423 
424  PG_RETURN_BOOL(val1 == val2);
425 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28ge()

Datum int28ge ( PG_FUNCTION_ARGS  )

Definition at line 464 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

465 {
466  int16 val1 = PG_GETARG_INT16(0);
467  int64 val2 = PG_GETARG_INT64(1);
468 
469  PG_RETURN_BOOL(val1 >= val2);
470 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28gt()

Datum int28gt ( PG_FUNCTION_ARGS  )

Definition at line 446 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

447 {
448  int16 val1 = PG_GETARG_INT16(0);
449  int64 val2 = PG_GETARG_INT64(1);
450 
451  PG_RETURN_BOOL(val1 > val2);
452 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28le()

Datum int28le ( PG_FUNCTION_ARGS  )

Definition at line 455 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

456 {
457  int16 val1 = PG_GETARG_INT16(0);
458  int64 val2 = PG_GETARG_INT64(1);
459 
460  PG_RETURN_BOOL(val1 <= val2);
461 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28lt()

Datum int28lt ( PG_FUNCTION_ARGS  )

Definition at line 437 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

438 {
439  int16 val1 = PG_GETARG_INT16(0);
440  int64 val2 = PG_GETARG_INT64(1);
441 
442  PG_RETURN_BOOL(val1 < val2);
443 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28mi()

Datum int28mi ( PG_FUNCTION_ARGS  )

Definition at line 1035 of file int8.c.

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

1036 {
1037  int16 arg1 = PG_GETARG_INT16(0);
1038  int64 arg2 = PG_GETARG_INT64(1);
1039  int64 result;
1040 
1041  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1042  ereport(ERROR,
1043  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1044  errmsg("bigint out of range")));
1045  PG_RETURN_INT64(result);
1046 }
signed short int16
Definition: c.h:312
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:199
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28mul()

Datum int28mul ( PG_FUNCTION_ARGS  )

Definition at line 1049 of file int8.c.

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

1050 {
1051  int16 arg1 = PG_GETARG_INT16(0);
1052  int64 arg2 = PG_GETARG_INT64(1);
1053  int64 result;
1054 
1055  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1056  ereport(ERROR,
1057  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1058  errmsg("bigint out of range")));
1059  PG_RETURN_INT64(result);
1060 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:231
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28ne()

Datum int28ne ( PG_FUNCTION_ARGS  )

Definition at line 428 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

429 {
430  int16 val1 = PG_GETARG_INT16(0);
431  int64 val2 = PG_GETARG_INT64(1);
432 
433  PG_RETURN_BOOL(val1 != val2);
434 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int28pl()

Datum int28pl ( PG_FUNCTION_ARGS  )

Definition at line 1021 of file int8.c.

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

1022 {
1023  int16 arg1 = PG_GETARG_INT16(0);
1024  int64 arg2 = PG_GETARG_INT64(1);
1025  int64 result;
1026 
1027  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1028  ereport(ERROR,
1029  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1030  errmsg("bigint out of range")));
1031  PG_RETURN_INT64(result);
1032 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:167
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48()

Datum int48 ( PG_FUNCTION_ARGS  )

Definition at line 1149 of file int8.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT64.

1150 {
1151  int32 arg = PG_GETARG_INT32(0);
1152 
1153  PG_RETURN_INT64((int64) arg);
1154 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
signed int int32
Definition: c.h:313
void * arg

◆ int48div()

Datum int48div ( PG_FUNCTION_ARGS  )

Definition at line 921 of file int8.c.

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

922 {
923  int32 arg1 = PG_GETARG_INT32(0);
924  int64 arg2 = PG_GETARG_INT64(1);
925 
926  if (unlikely(arg2 == 0))
927  {
928  ereport(ERROR,
929  (errcode(ERRCODE_DIVISION_BY_ZERO),
930  errmsg("division by zero")));
931  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
932  PG_RETURN_NULL();
933  }
934 
935  /* No overflow is possible */
936  PG_RETURN_INT64((int64) arg1 / arg2);
937 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int48eq()

Datum int48eq ( PG_FUNCTION_ARGS  )

Definition at line 305 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

306 {
307  int32 val1 = PG_GETARG_INT32(0);
308  int64 val2 = PG_GETARG_INT64(1);
309 
310  PG_RETURN_BOOL(val1 == val2);
311 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48ge()

Datum int48ge ( PG_FUNCTION_ARGS  )

Definition at line 350 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

351 {
352  int32 val1 = PG_GETARG_INT32(0);
353  int64 val2 = PG_GETARG_INT64(1);
354 
355  PG_RETURN_BOOL(val1 >= val2);
356 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48gt()

Datum int48gt ( PG_FUNCTION_ARGS  )

Definition at line 332 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

333 {
334  int32 val1 = PG_GETARG_INT32(0);
335  int64 val2 = PG_GETARG_INT64(1);
336 
337  PG_RETURN_BOOL(val1 > val2);
338 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48le()

Datum int48le ( PG_FUNCTION_ARGS  )

Definition at line 341 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

342 {
343  int32 val1 = PG_GETARG_INT32(0);
344  int64 val2 = PG_GETARG_INT64(1);
345 
346  PG_RETURN_BOOL(val1 <= val2);
347 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48lt()

Datum int48lt ( PG_FUNCTION_ARGS  )

Definition at line 323 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

324 {
325  int32 val1 = PG_GETARG_INT32(0);
326  int64 val2 = PG_GETARG_INT64(1);
327 
328  PG_RETURN_BOOL(val1 < val2);
329 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48mi()

Datum int48mi ( PG_FUNCTION_ARGS  )

Definition at line 893 of file int8.c.

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

894 {
895  int32 arg1 = PG_GETARG_INT32(0);
896  int64 arg2 = PG_GETARG_INT64(1);
897  int64 result;
898 
899  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
900  ereport(ERROR,
901  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
902  errmsg("bigint out of range")));
903  PG_RETURN_INT64(result);
904 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:199
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48mul()

Datum int48mul ( PG_FUNCTION_ARGS  )

Definition at line 907 of file int8.c.

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

908 {
909  int32 arg1 = PG_GETARG_INT32(0);
910  int64 arg2 = PG_GETARG_INT64(1);
911  int64 result;
912 
913  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
914  ereport(ERROR,
915  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
916  errmsg("bigint out of range")));
917  PG_RETURN_INT64(result);
918 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:231
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48ne()

Datum int48ne ( PG_FUNCTION_ARGS  )

Definition at line 314 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

315 {
316  int32 val1 = PG_GETARG_INT32(0);
317  int64 val2 = PG_GETARG_INT64(1);
318 
319  PG_RETURN_BOOL(val1 != val2);
320 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int48pl()

Datum int48pl ( PG_FUNCTION_ARGS  )

Definition at line 879 of file int8.c.

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

880 {
881  int32 arg1 = PG_GETARG_INT32(0);
882  int64 arg2 = PG_GETARG_INT64(1);
883  int64 result;
884 
885  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
886  ereport(ERROR,
887  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
888  errmsg("bigint out of range")));
889  PG_RETURN_INT64(result);
890 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:167
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82()

Datum int82 ( PG_FUNCTION_ARGS  )

Definition at line 1178 of file int8.c.

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

1179 {
1180  int64 arg = PG_GETARG_INT64(0);
1181 
1182  if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
1183  ereport(ERROR,
1184  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1185  errmsg("smallint out of range")));
1186 
1187  PG_RETURN_INT16((int16) arg);
1188 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:404
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_INT16_MAX
Definition: c.h:405
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82div()

Datum int82div ( PG_FUNCTION_ARGS  )

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

983 {
984  int64 arg1 = PG_GETARG_INT64(0);
985  int16 arg2 = PG_GETARG_INT16(1);
986  int64 result;
987 
988  if (unlikely(arg2 == 0))
989  {
990  ereport(ERROR,
991  (errcode(ERRCODE_DIVISION_BY_ZERO),
992  errmsg("division by zero")));
993  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
994  PG_RETURN_NULL();
995  }
996 
997  /*
998  * INT64_MIN / -1 is problematic, since the result can't be represented on
999  * a two's-complement machine. Some machines produce INT64_MIN, some
1000  * produce zero, some throw an exception. We can dodge the problem by
1001  * recognizing that division by -1 is the same as negation.
1002  */
1003  if (arg2 == -1)
1004  {
1005  if (unlikely(arg1 == PG_INT64_MIN))
1006  ereport(ERROR,
1007  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1008  errmsg("bigint out of range")));
1009  result = -arg1;
1010  PG_RETURN_INT64(result);
1011  }
1012 
1013  /* No overflow is possible */
1014 
1015  result = arg1 / arg2;
1016 
1017  PG_RETURN_INT64(result);
1018 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:410
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int82eq()

Datum int82eq ( PG_FUNCTION_ARGS  )

Definition at line 362 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

363 {
364  int64 val1 = PG_GETARG_INT64(0);
365  int16 val2 = PG_GETARG_INT16(1);
366 
367  PG_RETURN_BOOL(val1 == val2);
368 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82ge()

Datum int82ge ( PG_FUNCTION_ARGS  )

Definition at line 407 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

408 {
409  int64 val1 = PG_GETARG_INT64(0);
410  int16 val2 = PG_GETARG_INT16(1);
411 
412  PG_RETURN_BOOL(val1 >= val2);
413 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82gt()

Datum int82gt ( PG_FUNCTION_ARGS  )

Definition at line 389 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

390 {
391  int64 val1 = PG_GETARG_INT64(0);
392  int16 val2 = PG_GETARG_INT16(1);
393 
394  PG_RETURN_BOOL(val1 > val2);
395 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82le()

Datum int82le ( PG_FUNCTION_ARGS  )

Definition at line 398 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

399 {
400  int64 val1 = PG_GETARG_INT64(0);
401  int16 val2 = PG_GETARG_INT16(1);
402 
403  PG_RETURN_BOOL(val1 <= val2);
404 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82lt()

Datum int82lt ( PG_FUNCTION_ARGS  )

Definition at line 380 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

381 {
382  int64 val1 = PG_GETARG_INT64(0);
383  int16 val2 = PG_GETARG_INT16(1);
384 
385  PG_RETURN_BOOL(val1 < val2);
386 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82mi()

Datum int82mi ( PG_FUNCTION_ARGS  )

Definition at line 954 of file int8.c.

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

955 {
956  int64 arg1 = PG_GETARG_INT64(0);
957  int16 arg2 = PG_GETARG_INT16(1);
958  int64 result;
959 
960  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
961  ereport(ERROR,
962  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
963  errmsg("bigint out of range")));
964  PG_RETURN_INT64(result);
965 }
signed short int16
Definition: c.h:312
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:199
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82mul()

Datum int82mul ( PG_FUNCTION_ARGS  )

Definition at line 968 of file int8.c.

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

969 {
970  int64 arg1 = PG_GETARG_INT64(0);
971  int16 arg2 = PG_GETARG_INT16(1);
972  int64 result;
973 
974  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
975  ereport(ERROR,
976  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
977  errmsg("bigint out of range")));
978  PG_RETURN_INT64(result);
979 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:231
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82ne()

Datum int82ne ( PG_FUNCTION_ARGS  )

Definition at line 371 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

372 {
373  int64 val1 = PG_GETARG_INT64(0);
374  int16 val2 = PG_GETARG_INT16(1);
375 
376  PG_RETURN_BOOL(val1 != val2);
377 }
signed short int16
Definition: c.h:312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int82pl()

Datum int82pl ( PG_FUNCTION_ARGS  )

Definition at line 940 of file int8.c.

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

941 {
942  int64 arg1 = PG_GETARG_INT64(0);
943  int16 arg2 = PG_GETARG_INT16(1);
944  int64 result;
945 
946  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
947  ereport(ERROR,
948  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
949  errmsg("bigint out of range")));
950  PG_RETURN_INT64(result);
951 }
signed short int16
Definition: c.h:312
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:241
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:167
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84()

Datum int84 ( PG_FUNCTION_ARGS  )

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

1158 {
1159  int64 arg = PG_GETARG_INT64(0);
1160 
1161  if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
1162  ereport(ERROR,
1163  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1164  errmsg("integer out of range")));
1165 
1166  PG_RETURN_INT32((int32) arg);
1167 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:319
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:407
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_INT32_MAX
Definition: c.h:408
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84div()

Datum int84div ( PG_FUNCTION_ARGS  )

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

841 {
842  int64 arg1 = PG_GETARG_INT64(0);
843  int32 arg2 = PG_GETARG_INT32(1);
844  int64 result;
845 
846  if (arg2 == 0)
847  {
848  ereport(ERROR,
849  (errcode(ERRCODE_DIVISION_BY_ZERO),
850  errmsg("division by zero")));
851  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
852  PG_RETURN_NULL();
853  }
854 
855  /*
856  * INT64_MIN / -1 is problematic, since the result can't be represented on
857  * a two's-complement machine. Some machines produce INT64_MIN, some
858  * produce zero, some throw an exception. We can dodge the problem by
859  * recognizing that division by -1 is the same as negation.
860  */
861  if (arg2 == -1)
862  {
863  if (unlikely(arg1 == PG_INT64_MIN))
864  ereport(ERROR,
865  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
866  errmsg("bigint out of range")));
867  result = -arg1;
868  PG_RETURN_INT64(result);
869  }
870 
871  /* No overflow is possible */
872 
873  result = arg1 / arg2;
874 
875  PG_RETURN_INT64(result);
876 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:410
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ int84eq()

Datum int84eq ( PG_FUNCTION_ARGS  )

Definition at line 248 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

249 {
250  int64 val1 = PG_GETARG_INT64(0);
251  int32 val2 = PG_GETARG_INT32(1);
252 
253  PG_RETURN_BOOL(val1 == val2);
254 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84ge()

Datum int84ge ( PG_FUNCTION_ARGS  )

Definition at line 293 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

294 {
295  int64 val1 = PG_GETARG_INT64(0);
296  int32 val2 = PG_GETARG_INT32(1);
297 
298  PG_RETURN_BOOL(val1 >= val2);
299 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84gt()

Datum int84gt ( PG_FUNCTION_ARGS  )

Definition at line 275 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

276 {
277  int64 val1 = PG_GETARG_INT64(0);
278  int32 val2 = PG_GETARG_INT32(1);
279 
280  PG_RETURN_BOOL(val1 > val2);
281 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84le()

Datum int84le ( PG_FUNCTION_ARGS  )

Definition at line 284 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

285 {
286  int64 val1 = PG_GETARG_INT64(0);
287  int32 val2 = PG_GETARG_INT32(1);
288 
289  PG_RETURN_BOOL(val1 <= val2);
290 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84lt()

Datum int84lt ( PG_FUNCTION_ARGS  )

Definition at line 266 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

267 {
268  int64 val1 = PG_GETARG_INT64(0);
269  int32 val2 = PG_GETARG_INT32(1);
270 
271  PG_RETURN_BOOL(val1 < val2);
272 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84mi()

Datum int84mi ( PG_FUNCTION_ARGS  )

Definition at line 812 of file int8.c.

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

813 {
814  int64 arg1 = PG_GETARG_INT64(0);
815  int32 arg2 = PG_GETARG_INT32(1);
816  int64 result;
817 
818  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
819  ereport(ERROR,
820  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
821  errmsg("bigint out of range")));
822  PG_RETURN_INT64(result);
823 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:199
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84mul()

Datum int84mul ( PG_FUNCTION_ARGS  )

Definition at line 826 of file int8.c.

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

827 {
828  int64 arg1 = PG_GETARG_INT64(0);
829  int32 arg2 = PG_GETARG_INT32(1);
830  int64 result;
831 
832  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
833  ereport(ERROR,
834  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
835  errmsg("bigint out of range")));
836  PG_RETURN_INT64(result);
837 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:231
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84ne()

Datum int84ne ( PG_FUNCTION_ARGS  )

Definition at line 257 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

258 {
259  int64 val1 = PG_GETARG_INT64(0);
260  int32 val2 = PG_GETARG_INT32(1);
261 
262  PG_RETURN_BOOL(val1 != val2);
263 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:313
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int84pl()

Datum int84pl ( PG_FUNCTION_ARGS  )

Definition at line 798 of file int8.c.

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

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

◆ int8abs()

Datum int8abs ( PG_FUNCTION_ARGS  )

Definition at line 624 of file int8.c.

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

625 {
626  int64 arg1 = PG_GETARG_INT64(0);
627  int64 result;
628 
629  if (unlikely(arg1 == PG_INT64_MIN))
630  ereport(ERROR,
631  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
632  errmsg("bigint out of range")));
633  result = (arg1 < 0) ? -arg1 : arg1;
634  PG_RETURN_INT64(result);
635 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:410
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8and()

Datum int8and ( PG_FUNCTION_ARGS  )

Definition at line 1092 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1093 {
1094  int64 arg1 = PG_GETARG_INT64(0);
1095  int64 arg2 = PG_GETARG_INT64(1);
1096 
1097  PG_RETURN_INT64(arg1 & arg2);
1098 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8dec()

Datum int8dec ( PG_FUNCTION_ARGS  )

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

709 {
710  /*
711  * When int8 is pass-by-reference, we provide this special case to avoid
712  * palloc overhead for COUNT(): when called as an aggregate, we know that
713  * the argument is modifiable local storage, so just update it in-place.
714  * (If int8 is pass-by-value, then of course this is useless as well as
715  * incorrect, so just ifdef it out.)
716  */
717 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
718  if (AggCheckCallContext(fcinfo, NULL))
719  {
720  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
721 
722  if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
723  ereport(ERROR,
724  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
725  errmsg("bigint out of range")));
726  PG_RETURN_POINTER(arg);
727  }
728  else
729 #endif
730  {
731  /* Not called as an aggregate, so just do it the dumb way */
732  int64 arg = PG_GETARG_INT64(0);
733  int64 result;
734 
735  if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
736  ereport(ERROR,
737  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
738  errmsg("bigint out of range")));
739 
740  PG_RETURN_INT64(result);
741  }
742 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:199
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:3492
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8dec_any()

Datum int8dec_any ( PG_FUNCTION_ARGS  )

Definition at line 767 of file int8.c.

References int8dec().

768 {
769  return int8dec(fcinfo);
770 }
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:708

◆ int8div()

Datum int8div ( PG_FUNCTION_ARGS  )

Definition at line 582 of file int8.c.

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

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

◆ int8eq()

Datum int8eq ( PG_FUNCTION_ARGS  )

Definition at line 191 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

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

◆ int8ge()

Datum int8ge ( PG_FUNCTION_ARGS  )

Definition at line 236 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

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

◆ int8gt()

Datum int8gt ( PG_FUNCTION_ARGS  )

Definition at line 218 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

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

◆ int8in()

Datum int8in ( PG_FUNCTION_ARGS  )

Definition at line 133 of file int8.c.

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

Referenced by defGetInt64().

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

◆ int8inc()

Datum int8inc ( PG_FUNCTION_ARGS  )

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

671 {
672  /*
673  * When int8 is pass-by-reference, we provide this special case to avoid
674  * palloc overhead for COUNT(): when called as an aggregate, we know that
675  * the argument is modifiable local storage, so just update it in-place.
676  * (If int8 is pass-by-value, then of course this is useless as well as
677  * incorrect, so just ifdef it out.)
678  */
679 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
680  if (AggCheckCallContext(fcinfo, NULL))
681  {
682  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
683 
684  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
685  ereport(ERROR,
686  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
687  errmsg("bigint out of range")));
688 
689  PG_RETURN_POINTER(arg);
690  }
691  else
692 #endif
693  {
694  /* Not called as an aggregate, so just do it the dumb way */
695  int64 arg = PG_GETARG_INT64(0);
696  int64 result;
697 
698  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
699  ereport(ERROR,
700  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
701  errmsg("bigint out of range")));
702 
703  PG_RETURN_INT64(result);
704  }
705 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:167
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:3492
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8inc_any()

Datum int8inc_any ( PG_FUNCTION_ARGS  )

Definition at line 755 of file int8.c.

References int8inc().

756 {
757  return int8inc(fcinfo);
758 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:670

◆ int8inc_float8_float8()

Datum int8inc_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 761 of file int8.c.

References int8inc().

762 {
763  return int8inc(fcinfo);
764 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:670

◆ int8larger()

Datum int8larger ( PG_FUNCTION_ARGS  )

Definition at line 774 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

775 {
776  int64 arg1 = PG_GETARG_INT64(0);
777  int64 arg2 = PG_GETARG_INT64(1);
778  int64 result;
779 
780  result = ((arg1 > arg2) ? arg1 : arg2);
781 
782  PG_RETURN_INT64(result);
783 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8le()

Datum int8le ( PG_FUNCTION_ARGS  )

Definition at line 227 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

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

◆ int8lt()

Datum int8lt ( PG_FUNCTION_ARGS  )

Definition at line 209 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

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

◆ int8mi()

Datum int8mi ( PG_FUNCTION_ARGS  )

Definition at line 554 of file int8.c.

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

555 {
556  int64 arg1 = PG_GETARG_INT64(0);
557  int64 arg2 = PG_GETARG_INT64(1);
558  int64 result;
559 
560  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
561  ereport(ERROR,
562  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
563  errmsg("bigint out of range")));
564  PG_RETURN_INT64(result);
565 }
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:199
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8mod()

Datum int8mod ( PG_FUNCTION_ARGS  )

Definition at line 641 of file int8.c.

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

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

◆ int8mul()

Datum int8mul ( PG_FUNCTION_ARGS  )

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

569 {
570  int64 arg1 = PG_GETARG_INT64(0);
571  int64 arg2 = PG_GETARG_INT64(1);
572  int64 result;
573 
574  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
575  ereport(ERROR,
576  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
577  errmsg("bigint out of range")));
578  PG_RETURN_INT64(result);
579 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:231
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8ne()

Datum int8ne ( PG_FUNCTION_ARGS  )

Definition at line 200 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

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

◆ int8not()

Datum int8not ( PG_FUNCTION_ARGS  )

Definition at line 1119 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1120 {
1121  int64 arg1 = PG_GETARG_INT64(0);
1122 
1123  PG_RETURN_INT64(~arg1);
1124 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8or()

Datum int8or ( PG_FUNCTION_ARGS  )

Definition at line 1101 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1102 {
1103  int64 arg1 = PG_GETARG_INT64(0);
1104  int64 arg2 = PG_GETARG_INT64(1);
1105 
1106  PG_RETURN_INT64(arg1 | arg2);
1107 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8out()

Datum int8out ( PG_FUNCTION_ARGS  )

Definition at line 146 of file int8.c.

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

Referenced by int8_to_char().

147 {
148  int64 val = PG_GETARG_INT64(0);
149  char buf[MAXINT8LEN + 1];
150  char *result;
151 
152  pg_lltoa(val, buf);
153  result = pstrdup(buf);
154  PG_RETURN_CSTRING(result);
155 }
#define MAXINT8LEN
Definition: int8.c:28
char * pstrdup(const char *in)
Definition: mcxt.c:1161
static char * buf
Definition: pg_test_fsync.c:67
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:186
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252
long val
Definition: informix.c:689

◆ int8pl()

Datum int8pl ( PG_FUNCTION_ARGS  )

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

541 {
542  int64 arg1 = PG_GETARG_INT64(0);
543  int64 arg2 = PG_GETARG_INT64(1);
544  int64 result;
545 
546  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
547  ereport(ERROR,
548  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
549  errmsg("bigint out of range")));
550  PG_RETURN_INT64(result);
551 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:167
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8recv()

Datum int8recv ( PG_FUNCTION_ARGS  )

Definition at line 161 of file int8.c.

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

162 {
164 
166 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
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 172 of file int8.c.

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

173 {
174  int64 arg1 = PG_GETARG_INT64(0);
176 
177  pq_begintypsend(&buf);
178  pq_sendint64(&buf, arg1);
180 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
static void pq_sendint64(StringInfo buf, int64 i)
Definition: pqformat.h:156
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:335
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8shl()

Datum int8shl ( PG_FUNCTION_ARGS  )

Definition at line 1127 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1128 {
1129  int64 arg1 = PG_GETARG_INT64(0);
1130  int32 arg2 = PG_GETARG_INT32(1);
1131 
1132  PG_RETURN_INT64(arg1 << arg2);
1133 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
signed int int32
Definition: c.h:313
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8shr()

Datum int8shr ( PG_FUNCTION_ARGS  )

Definition at line 1136 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1137 {
1138  int64 arg1 = PG_GETARG_INT64(0);
1139  int32 arg2 = PG_GETARG_INT32(1);
1140 
1141  PG_RETURN_INT64(arg1 >> arg2);
1142 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
signed int int32
Definition: c.h:313
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8smaller()

Datum int8smaller ( PG_FUNCTION_ARGS  )

Definition at line 786 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

787 {
788  int64 arg1 = PG_GETARG_INT64(0);
789  int64 arg2 = PG_GETARG_INT64(1);
790  int64 result;
791 
792  result = ((arg1 < arg2) ? arg1 : arg2);
793 
794  PG_RETURN_INT64(result);
795 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8um()

Datum int8um ( PG_FUNCTION_ARGS  )

Definition at line 518 of file int8.c.

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

519 {
520  int64 arg = PG_GETARG_INT64(0);
521  int64 result;
522 
523  if (unlikely(arg == PG_INT64_MIN))
524  ereport(ERROR,
525  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
526  errmsg("bigint out of range")));
527  result = -arg;
528  PG_RETURN_INT64(result);
529 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:410
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:208
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ int8up()

Datum int8up ( PG_FUNCTION_ARGS  )

Definition at line 532 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_INT64.

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

◆ int8xor()

Datum int8xor ( PG_FUNCTION_ARGS  )

Definition at line 1110 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1111 {
1112  int64 arg1 = PG_GETARG_INT64(0);
1113  int64 arg2 = PG_GETARG_INT64(1);
1114 
1115  PG_RETURN_INT64(arg1 ^ arg2);
1116 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252

◆ oidtoi8()

Datum oidtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1272 of file int8.c.

References arg, PG_GETARG_OID, and PG_RETURN_INT64.

1273 {
1274  Oid arg = PG_GETARG_OID(0);
1275 
1276  PG_RETURN_INT64((int64) arg);
1277 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:332
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:245
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  if (unlikely(tmp == PG_INT64_MIN))
106  goto out_of_range;
107  tmp = -tmp;
108  }
109 
110  *result = tmp;
111  return true;
112 
113 out_of_range:
114  if (!errorOK)
115  ereport(ERROR,
116  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
117  errmsg("value \"%s\" is out of range for type %s",
118  str, "bigint")));
119  return false;
120 
121 invalid_syntax:
122  if (!errorOK)
123  ereport(ERROR,
124  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
125  errmsg("invalid input syntax for integer: \"%s\"",
126  str)));
127  return false;
128 }
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:199
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:410
#define ereport(elevel, rest)
Definition: elog.h:122
signed char int8
Definition: c.h:311
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:231
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:208