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 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 1165 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().

1166 {
1168  int64 result;
1169 
1170  /* Round arg to nearest integer (but it's still in float form) */
1171  arg = rint(arg);
1172 
1173  if (unlikely(arg < (double) PG_INT64_MIN) ||
1174  unlikely(arg > (double) PG_INT64_MAX) ||
1175  unlikely(isnan(arg)))
1176  ereport(ERROR,
1177  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1178  errmsg("bigint out of range")));
1179 
1180  result = (int64) arg;
1181 
1182  PG_RETURN_INT64(result);
1183 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_INT64_MAX
Definition: c.h:392
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
#define PG_INT64_MIN
Definition: c.h:391
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:200

◆ ftoi8()

Datum ftoi8 ( PG_FUNCTION_ARGS  )

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

1201 {
1203  float8 darg;
1204 
1205  /* Round arg to nearest integer (but it's still in float form) */
1206  darg = rint(arg);
1207 
1208  if (unlikely(arg < (float4) PG_INT64_MIN) ||
1209  unlikely(arg > (float4) PG_INT64_MAX) ||
1210  unlikely(isnan(arg)))
1211  ereport(ERROR,
1212  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1213  errmsg("bigint out of range")));
1214 
1215  PG_RETURN_INT64((int64) darg);
1216 }
#define PG_INT64_MAX
Definition: c.h:392
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
#define PG_INT64_MIN
Definition: c.h:391
double rint(double x)
Definition: rint.c:22
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:438
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:200

◆ generate_series_int8()

Datum generate_series_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1243 of file int8.c.

References generate_series_step_int8().

1244 {
1245  return generate_series_step_int8(fcinfo);
1246 }
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1249

◆ generate_series_step_int8()

Datum generate_series_step_int8 ( PG_FUNCTION_ARGS  )

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

1250 {
1251  FuncCallContext *funcctx;
1252  generate_series_fctx *fctx;
1253  int64 result;
1254  MemoryContext oldcontext;
1255 
1256  /* stuff done only on the first call of the function */
1257  if (SRF_IS_FIRSTCALL())
1258  {
1259  int64 start = PG_GETARG_INT64(0);
1260  int64 finish = PG_GETARG_INT64(1);
1261  int64 step = 1;
1262 
1263  /* see if we were given an explicit step size */
1264  if (PG_NARGS() == 3)
1265  step = PG_GETARG_INT64(2);
1266  if (step == 0)
1267  ereport(ERROR,
1268  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1269  errmsg("step size cannot equal zero")));
1270 
1271  /* create a function context for cross-call persistence */
1272  funcctx = SRF_FIRSTCALL_INIT();
1273 
1274  /*
1275  * switch to memory context appropriate for multiple function calls
1276  */
1277  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1278 
1279  /* allocate memory for user context */
1280  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1281 
1282  /*
1283  * Use fctx to keep state from call to call. Seed current with the
1284  * original start value
1285  */
1286  fctx->current = start;
1287  fctx->finish = finish;
1288  fctx->step = step;
1289 
1290  funcctx->user_fctx = fctx;
1291  MemoryContextSwitchTo(oldcontext);
1292  }
1293 
1294  /* stuff done on every call of the function */
1295  funcctx = SRF_PERCALL_SETUP();
1296 
1297  /*
1298  * get the saved state and use current as the result for this iteration
1299  */
1300  fctx = funcctx->user_fctx;
1301  result = fctx->current;
1302 
1303  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1304  (fctx->step < 0 && fctx->current >= fctx->finish))
1305  {
1306  /*
1307  * Increment current in preparation for next iteration. If next-value
1308  * computation overflows, this is the final result.
1309  */
1310  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1311  fctx->step = 0;
1312 
1313  /* do when there is more left to send */
1314  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1315  }
1316  else
1317  /* do when there is no more left */
1318  SRF_RETURN_DONE(funcctx);
1319 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:293
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:297
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:299
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1786
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:149
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:168
void * user_fctx
Definition: funcapi.h:91
void * palloc(Size size)
Definition: mcxt.c:835
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:317
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:295

◆ i8tod()

Datum i8tod ( PG_FUNCTION_ARGS  )

Definition at line 1151 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT8.

1152 {
1153  int64 arg = PG_GETARG_INT64(0);
1154  float8 result;
1155 
1156  result = arg;
1157 
1158  PG_RETURN_FLOAT8(result);
1159 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ i8tof()

Datum i8tof ( PG_FUNCTION_ARGS  )

Definition at line 1186 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT4.

1187 {
1188  int64 arg = PG_GETARG_INT64(0);
1189  float4 result;
1190 
1191  result = arg;
1192 
1193  PG_RETURN_FLOAT4(result);
1194 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
float float4
Definition: c.h:438
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ i8tooid()

Datum i8tooid ( PG_FUNCTION_ARGS  )

Definition at line 1219 of file int8.c.

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

1220 {
1221  int64 arg = PG_GETARG_INT64(0);
1222 
1223  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1224  ereport(ERROR,
1225  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1226  errmsg("OID out of range")));
1227 
1228  PG_RETURN_OID((Oid) arg);
1229 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_UINT32_MAX
Definition: c.h:390
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:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define PG_RETURN_OID(x)
Definition: fmgr.h:320

◆ int28()

Datum int28 ( PG_FUNCTION_ARGS  )

Definition at line 1130 of file int8.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT64.

1131 {
1132  int16 arg = PG_GETARG_INT16(0);
1133 
1134  PG_RETURN_INT64((int64) arg);
1135 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
void * arg

◆ int28div()

Datum int28div ( PG_FUNCTION_ARGS  )

Definition at line 1023 of file int8.c.

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

1024 {
1025  int16 arg1 = PG_GETARG_INT16(0);
1026  int64 arg2 = PG_GETARG_INT64(1);
1027 
1028  if (unlikely(arg2 == 0))
1029  {
1030  ereport(ERROR,
1031  (errcode(ERRCODE_DIVISION_BY_ZERO),
1032  errmsg("division by zero")));
1033  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1034  PG_RETURN_NULL();
1035  }
1036 
1037  /* No overflow is possible */
1038  PG_RETURN_INT64((int64) arg1 / arg2);
1039 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:236
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int28mi()

Datum int28mi ( PG_FUNCTION_ARGS  )

Definition at line 995 of file int8.c.

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

996 {
997  int16 arg1 = PG_GETARG_INT16(0);
998  int64 arg2 = PG_GETARG_INT64(1);
999  int64 result;
1000 
1001  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1002  ereport(ERROR,
1003  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1004  errmsg("bigint out of range")));
1005  PG_RETURN_INT64(result);
1006 }
signed short int16
Definition: c.h:293
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:175
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:236
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int28mul()

Datum int28mul ( PG_FUNCTION_ARGS  )

Definition at line 1009 of file int8.c.

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

1010 {
1011  int16 arg1 = PG_GETARG_INT16(0);
1012  int64 arg2 = PG_GETARG_INT64(1);
1013  int64 result;
1014 
1015  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1016  ereport(ERROR,
1017  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1018  errmsg("bigint out of range")));
1019  PG_RETURN_INT64(result);
1020 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:236
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:201
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int28pl()

Datum int28pl ( PG_FUNCTION_ARGS  )

Definition at line 981 of file int8.c.

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

982 {
983  int16 arg1 = PG_GETARG_INT16(0);
984  int64 arg2 = PG_GETARG_INT64(1);
985  int64 result;
986 
987  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
988  ereport(ERROR,
989  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
990  errmsg("bigint out of range")));
991  PG_RETURN_INT64(result);
992 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:236
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:149
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int48()

Datum int48 ( PG_FUNCTION_ARGS  )

Definition at line 1109 of file int8.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT64.

1110 {
1111  int32 arg = PG_GETARG_INT32(0);
1112 
1113  PG_RETURN_INT64((int64) arg);
1114 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
signed int int32
Definition: c.h:294
void * arg

◆ int48div()

Datum int48div ( PG_FUNCTION_ARGS  )

Definition at line 881 of file int8.c.

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

882 {
883  int32 arg1 = PG_GETARG_INT32(0);
884  int64 arg2 = PG_GETARG_INT64(1);
885 
886  if (unlikely(arg2 == 0))
887  {
888  ereport(ERROR,
889  (errcode(ERRCODE_DIVISION_BY_ZERO),
890  errmsg("division by zero")));
891  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
892  PG_RETURN_NULL();
893  }
894 
895  /* No overflow is possible */
896  PG_RETURN_INT64((int64) arg1 / arg2);
897 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#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:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int48mi()

Datum int48mi ( PG_FUNCTION_ARGS  )

Definition at line 853 of file int8.c.

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

854 {
855  int32 arg1 = PG_GETARG_INT32(0);
856  int64 arg2 = PG_GETARG_INT64(1);
857  int64 result;
858 
859  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
860  ereport(ERROR,
861  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
862  errmsg("bigint out of range")));
863  PG_RETURN_INT64(result);
864 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:175
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#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:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int48mul()

Datum int48mul ( PG_FUNCTION_ARGS  )

Definition at line 867 of file int8.c.

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

868 {
869  int32 arg1 = PG_GETARG_INT32(0);
870  int64 arg2 = PG_GETARG_INT64(1);
871  int64 result;
872 
873  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
874  ereport(ERROR,
875  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
876  errmsg("bigint out of range")));
877  PG_RETURN_INT64(result);
878 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#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:201
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int48pl()

Datum int48pl ( PG_FUNCTION_ARGS  )

Definition at line 839 of file int8.c.

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

840 {
841  int32 arg1 = PG_GETARG_INT32(0);
842  int64 arg2 = PG_GETARG_INT64(1);
843  int64 result;
844 
845  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
846  ereport(ERROR,
847  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
848  errmsg("bigint out of range")));
849  PG_RETURN_INT64(result);
850 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#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:149
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int82()

Datum int82 ( PG_FUNCTION_ARGS  )

Definition at line 1138 of file int8.c.

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

1139 {
1140  int64 arg = PG_GETARG_INT64(0);
1141 
1142  if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
1143  ereport(ERROR,
1144  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1145  errmsg("smallint out of range")));
1146 
1147  PG_RETURN_INT16((int16) arg);
1148 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT16(x)
Definition: fmgr.h:316
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:385
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_INT16_MAX
Definition: c.h:386
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int82div()

Datum int82div ( PG_FUNCTION_ARGS  )

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

943 {
944  int64 arg1 = PG_GETARG_INT64(0);
945  int16 arg2 = PG_GETARG_INT16(1);
946  int64 result;
947 
948  if (unlikely(arg2 == 0))
949  {
950  ereport(ERROR,
951  (errcode(ERRCODE_DIVISION_BY_ZERO),
952  errmsg("division by zero")));
953  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
954  PG_RETURN_NULL();
955  }
956 
957  /*
958  * INT64_MIN / -1 is problematic, since the result can't be represented on
959  * a two's-complement machine. Some machines produce INT64_MIN, some
960  * produce zero, some throw an exception. We can dodge the problem by
961  * recognizing that division by -1 is the same as negation.
962  */
963  if (arg2 == -1)
964  {
965  if (unlikely(arg1 == PG_INT64_MIN))
966  ereport(ERROR,
967  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
968  errmsg("bigint out of range")));
969  result = -arg1;
970  PG_RETURN_INT64(result);
971  }
972 
973  /* No overflow is possible */
974 
975  result = arg1 / arg2;
976 
977  PG_RETURN_INT64(result);
978 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:391
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int82mi()

Datum int82mi ( PG_FUNCTION_ARGS  )

Definition at line 914 of file int8.c.

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

915 {
916  int64 arg1 = PG_GETARG_INT64(0);
917  int16 arg2 = PG_GETARG_INT16(1);
918  int64 result;
919 
920  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
921  ereport(ERROR,
922  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
923  errmsg("bigint out of range")));
924  PG_RETURN_INT64(result);
925 }
signed short int16
Definition: c.h:293
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:175
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:236
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int82mul()

Datum int82mul ( PG_FUNCTION_ARGS  )

Definition at line 928 of file int8.c.

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

929 {
930  int64 arg1 = PG_GETARG_INT64(0);
931  int16 arg2 = PG_GETARG_INT16(1);
932  int64 result;
933 
934  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
935  ereport(ERROR,
936  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
937  errmsg("bigint out of range")));
938  PG_RETURN_INT64(result);
939 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:236
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:201
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:293
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int82pl()

Datum int82pl ( PG_FUNCTION_ARGS  )

Definition at line 900 of file int8.c.

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

901 {
902  int64 arg1 = PG_GETARG_INT64(0);
903  int16 arg2 = PG_GETARG_INT16(1);
904  int64 result;
905 
906  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
907  ereport(ERROR,
908  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
909  errmsg("bigint out of range")));
910  PG_RETURN_INT64(result);
911 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:236
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:149
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int84()

Datum int84 ( PG_FUNCTION_ARGS  )

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

1118 {
1119  int64 arg = PG_GETARG_INT64(0);
1120 
1121  if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
1122  ereport(ERROR,
1123  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1124  errmsg("integer out of range")));
1125 
1126  PG_RETURN_INT32((int32) arg);
1127 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#define ERROR
Definition: elog.h:43
#define PG_INT32_MIN
Definition: c.h:388
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_INT32_MAX
Definition: c.h:389
void * arg
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int84div()

Datum int84div ( PG_FUNCTION_ARGS  )

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

801 {
802  int64 arg1 = PG_GETARG_INT64(0);
803  int32 arg2 = PG_GETARG_INT32(1);
804  int64 result;
805 
806  if (arg2 == 0)
807  {
808  ereport(ERROR,
809  (errcode(ERRCODE_DIVISION_BY_ZERO),
810  errmsg("division by zero")));
811  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
812  PG_RETURN_NULL();
813  }
814 
815  /*
816  * INT64_MIN / -1 is problematic, since the result can't be represented on
817  * a two's-complement machine. Some machines produce INT64_MIN, some
818  * produce zero, some throw an exception. We can dodge the problem by
819  * recognizing that division by -1 is the same as negation.
820  */
821  if (arg2 == -1)
822  {
823  if (unlikely(arg1 == PG_INT64_MIN))
824  ereport(ERROR,
825  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
826  errmsg("bigint out of range")));
827  result = -arg1;
828  PG_RETURN_INT64(result);
829  }
830 
831  /* No overflow is possible */
832 
833  result = arg1 / arg2;
834 
835  PG_RETURN_INT64(result);
836 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:391
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int84mi()

Datum int84mi ( PG_FUNCTION_ARGS  )

Definition at line 772 of file int8.c.

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

773 {
774  int64 arg1 = PG_GETARG_INT64(0);
775  int32 arg2 = PG_GETARG_INT32(1);
776  int64 result;
777 
778  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
779  ereport(ERROR,
780  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
781  errmsg("bigint out of range")));
782  PG_RETURN_INT64(result);
783 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:175
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#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:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int84mul()

Datum int84mul ( PG_FUNCTION_ARGS  )

Definition at line 786 of file int8.c.

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

787 {
788  int64 arg1 = PG_GETARG_INT64(0);
789  int32 arg2 = PG_GETARG_INT32(1);
790  int64 result;
791 
792  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
793  ereport(ERROR,
794  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
795  errmsg("bigint out of range")));
796  PG_RETURN_INT64(result);
797 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#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:201
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:234
signed int int32
Definition: c.h:294
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int84pl()

Datum int84pl ( PG_FUNCTION_ARGS  )

Definition at line 758 of file int8.c.

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

759 {
760  int64 arg1 = PG_GETARG_INT64(0);
761  int32 arg2 = PG_GETARG_INT32(1);
762  int64 result;
763 
764  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
765  ereport(ERROR,
766  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
767  errmsg("bigint out of range")));
768  PG_RETURN_INT64(result);
769 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#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:149
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8abs()

Datum int8abs ( PG_FUNCTION_ARGS  )

Definition at line 584 of file int8.c.

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

585 {
586  int64 arg1 = PG_GETARG_INT64(0);
587  int64 result;
588 
589  if (unlikely(arg1 == PG_INT64_MIN))
590  ereport(ERROR,
591  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
592  errmsg("bigint out of range")));
593  result = (arg1 < 0) ? -arg1 : arg1;
594  PG_RETURN_INT64(result);
595 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:391
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8and()

Datum int8and ( PG_FUNCTION_ARGS  )

Definition at line 1052 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1053 {
1054  int64 arg1 = PG_GETARG_INT64(0);
1055  int64 arg2 = PG_GETARG_INT64(1);
1056 
1057  PG_RETURN_INT64(arg1 & arg2);
1058 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8dec()

Datum int8dec ( PG_FUNCTION_ARGS  )

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

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

◆ int8dec_any()

Datum int8dec_any ( PG_FUNCTION_ARGS  )

Definition at line 727 of file int8.c.

References int8dec().

728 {
729  return int8dec(fcinfo);
730 }
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:668

◆ int8div()

Datum int8div ( PG_FUNCTION_ARGS  )

Definition at line 542 of file int8.c.

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

543 {
544  int64 arg1 = PG_GETARG_INT64(0);
545  int64 arg2 = PG_GETARG_INT64(1);
546  int64 result;
547 
548  if (arg2 == 0)
549  {
550  ereport(ERROR,
551  (errcode(ERRCODE_DIVISION_BY_ZERO),
552  errmsg("division by zero")));
553  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
554  PG_RETURN_NULL();
555  }
556 
557  /*
558  * INT64_MIN / -1 is problematic, since the result can't be represented on
559  * a two's-complement machine. Some machines produce INT64_MIN, some
560  * produce zero, some throw an exception. We can dodge the problem by
561  * recognizing that division by -1 is the same as negation.
562  */
563  if (arg2 == -1)
564  {
565  if (unlikely(arg1 == PG_INT64_MIN))
566  ereport(ERROR,
567  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
568  errmsg("bigint out of range")));
569  result = -arg1;
570  PG_RETURN_INT64(result);
571  }
572 
573  /* No overflow is possible */
574 
575  result = arg1 / arg2;
576 
577  PG_RETURN_INT64(result);
578 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:391
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define PG_RETURN_NULL()
Definition: fmgr.h:305

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

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

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

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

◆ int8inc()

Datum int8inc ( PG_FUNCTION_ARGS  )

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

631 {
632  /*
633  * When int8 is pass-by-reference, we provide this special case to avoid
634  * palloc overhead for COUNT(): when called as an aggregate, we know that
635  * the argument is modifiable local storage, so just update it in-place.
636  * (If int8 is pass-by-value, then of course this is useless as well as
637  * incorrect, so just ifdef it out.)
638  */
639 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
640  if (AggCheckCallContext(fcinfo, NULL))
641  {
642  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
643 
644  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
645  ereport(ERROR,
646  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
647  errmsg("bigint out of range")));
648 
649  PG_RETURN_POINTER(arg);
650  }
651  else
652 #endif
653  {
654  /* Not called as an aggregate, so just do it the dumb way */
655  int64 arg = PG_GETARG_INT64(0);
656  int64 result;
657 
658  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
659  ereport(ERROR,
660  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
661  errmsg("bigint out of range")));
662 
663  PG_RETURN_INT64(result);
664  }
665 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#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:149
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:3471
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8inc_any()

Datum int8inc_any ( PG_FUNCTION_ARGS  )

Definition at line 715 of file int8.c.

References int8inc().

716 {
717  return int8inc(fcinfo);
718 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:630

◆ int8inc_float8_float8()

Datum int8inc_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 721 of file int8.c.

References int8inc().

722 {
723  return int8inc(fcinfo);
724 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:630

◆ int8larger()

Datum int8larger ( PG_FUNCTION_ARGS  )

Definition at line 734 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

735 {
736  int64 arg1 = PG_GETARG_INT64(0);
737  int64 arg2 = PG_GETARG_INT64(1);
738  int64 result;
739 
740  result = ((arg1 > arg2) ? arg1 : arg2);
741 
742  PG_RETURN_INT64(result);
743 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

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

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

◆ int8mi()

Datum int8mi ( PG_FUNCTION_ARGS  )

Definition at line 514 of file int8.c.

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

515 {
516  int64 arg1 = PG_GETARG_INT64(0);
517  int64 arg2 = PG_GETARG_INT64(1);
518  int64 result;
519 
520  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
521  ereport(ERROR,
522  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
523  errmsg("bigint out of range")));
524  PG_RETURN_INT64(result);
525 }
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:175
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8mod()

Datum int8mod ( PG_FUNCTION_ARGS  )

Definition at line 601 of file int8.c.

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

602 {
603  int64 arg1 = PG_GETARG_INT64(0);
604  int64 arg2 = PG_GETARG_INT64(1);
605 
606  if (unlikely(arg2 == 0))
607  {
608  ereport(ERROR,
609  (errcode(ERRCODE_DIVISION_BY_ZERO),
610  errmsg("division by zero")));
611  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
612  PG_RETURN_NULL();
613  }
614 
615  /*
616  * Some machines throw a floating-point exception for INT64_MIN % -1,
617  * which is a bit silly since the correct answer is perfectly
618  * well-defined, namely zero.
619  */
620  if (arg2 == -1)
621  PG_RETURN_INT64(0);
622 
623  /* No overflow is possible */
624 
625  PG_RETURN_INT64(arg1 % arg2);
626 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ int8mul()

Datum int8mul ( PG_FUNCTION_ARGS  )

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

529 {
530  int64 arg1 = PG_GETARG_INT64(0);
531  int64 arg2 = PG_GETARG_INT64(1);
532  int64 result;
533 
534  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
535  ereport(ERROR,
536  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
537  errmsg("bigint out of range")));
538  PG_RETURN_INT64(result);
539 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:201
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

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

◆ int8not()

Datum int8not ( PG_FUNCTION_ARGS  )

Definition at line 1079 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1080 {
1081  int64 arg1 = PG_GETARG_INT64(0);
1082 
1083  PG_RETURN_INT64(~arg1);
1084 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8or()

Datum int8or ( PG_FUNCTION_ARGS  )

Definition at line 1061 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1062 {
1063  int64 arg1 = PG_GETARG_INT64(0);
1064  int64 arg2 = PG_GETARG_INT64(1);
1065 
1066  PG_RETURN_INT64(arg1 | arg2);
1067 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:1063
static char * buf
Definition: pg_test_fsync.c:67
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:186
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
long val
Definition: informix.c:689

◆ int8pl()

Datum int8pl ( PG_FUNCTION_ARGS  )

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

501 {
502  int64 arg1 = PG_GETARG_INT64(0);
503  int64 arg2 = PG_GETARG_INT64(1);
504  int64 result;
505 
506  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
507  ereport(ERROR,
508  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
509  errmsg("bigint out of range")));
510  PG_RETURN_INT64(result);
511 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
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:149
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ 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:327
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
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:330
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:247

◆ int8shl()

Datum int8shl ( PG_FUNCTION_ARGS  )

Definition at line 1087 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1088 {
1089  int64 arg1 = PG_GETARG_INT64(0);
1090  int32 arg2 = PG_GETARG_INT32(1);
1091 
1092  PG_RETURN_INT64(arg1 << arg2);
1093 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
signed int int32
Definition: c.h:294
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8shr()

Datum int8shr ( PG_FUNCTION_ARGS  )

Definition at line 1096 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

1097 {
1098  int64 arg1 = PG_GETARG_INT64(0);
1099  int32 arg2 = PG_GETARG_INT32(1);
1100 
1101  PG_RETURN_INT64(arg1 >> arg2);
1102 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
signed int int32
Definition: c.h:294
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8smaller()

Datum int8smaller ( PG_FUNCTION_ARGS  )

Definition at line 746 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

747 {
748  int64 arg1 = PG_GETARG_INT64(0);
749  int64 arg2 = PG_GETARG_INT64(1);
750  int64 result;
751 
752  result = ((arg1 < arg2) ? arg1 : arg2);
753 
754  PG_RETURN_INT64(result);
755 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8um()

Datum int8um ( PG_FUNCTION_ARGS  )

Definition at line 478 of file int8.c.

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

479 {
480  int64 arg = PG_GETARG_INT64(0);
481  int64 result;
482 
483  if (unlikely(arg == PG_INT64_MIN))
484  ereport(ERROR,
485  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
486  errmsg("bigint out of range")));
487  result = -arg;
488  PG_RETURN_INT64(result);
489 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:391
#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:200
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8up()

Datum int8up ( PG_FUNCTION_ARGS  )

Definition at line 492 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_INT64.

493 {
494  int64 arg = PG_GETARG_INT64(0);
495 
496  PG_RETURN_INT64(arg);
497 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
void * arg
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ int8xor()

Datum int8xor ( PG_FUNCTION_ARGS  )

Definition at line 1070 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

1071 {
1072  int64 arg1 = PG_GETARG_INT64(0);
1073  int64 arg2 = PG_GETARG_INT64(1);
1074 
1075  PG_RETURN_INT64(arg1 ^ arg2);
1076 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247

◆ oidtoi8()

Datum oidtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1232 of file int8.c.

References arg, PG_GETARG_OID, and PG_RETURN_INT64.

1233 {
1234  Oid arg = PG_GETARG_OID(0);
1235 
1236  PG_RETURN_INT64((int64) arg);
1237 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
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:175
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define PG_INT64_MIN
Definition: c.h:391
#define ereport(elevel, rest)
Definition: elog.h:122
signed char int8
Definition: c.h:292
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:201
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define unlikely(x)
Definition: c.h:200