Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

int8.h File Reference

#include "fmgr.h"
Include dependency graph for int8.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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 int8inc_any (PG_FUNCTION_ARGS)
Datum int8inc_float8_float8 (PG_FUNCTION_ARGS)
Datum int8larger (PG_FUNCTION_ARGS)
Datum int8smaller (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 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 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)

Function Documentation

Datum dtoi8 ( PG_FUNCTION_ARGS   ) 

Definition at line 1292 of file int8.c.

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

Referenced by int8_to_char().

{
    float8      arg = PG_GETARG_FLOAT8(0);
    int64       result;

    /* Round arg to nearest integer (but it's still in float form) */
    arg = rint(arg);

    /*
     * Does it fit in an int64?  Avoid assuming that we have handy constants
     * defined for the range boundaries, instead test for overflow by
     * reverse-conversion.
     */
    result = (int64) arg;

    if ((float8) result != arg)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));

    PG_RETURN_INT64(result);
}

Datum ftoi8 ( PG_FUNCTION_ARGS   ) 

Definition at line 1330 of file int8.c.

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

{
    float4      arg = PG_GETARG_FLOAT4(0);
    int64       result;
    float8      darg;

    /* Round arg to nearest integer (but it's still in float form) */
    darg = rint(arg);

    /*
     * Does it fit in an int64?  Avoid assuming that we have handy constants
     * defined for the range boundaries, instead test for overflow by
     * reverse-conversion.
     */
    result = (int64) darg;

    if ((float8) result != darg)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));

    PG_RETURN_INT64(result);
}

Datum generate_series_int8 ( PG_FUNCTION_ARGS   ) 

Definition at line 1383 of file int8.c.

References generate_series_step_int8().

{
    return generate_series_step_int8(fcinfo);
}

Datum generate_series_step_int8 ( PG_FUNCTION_ARGS   ) 

Definition at line 1389 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_GETARG_INT64, PG_NARGS, SAMESIGN, 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().

{
    FuncCallContext *funcctx;
    generate_series_fctx *fctx;
    int64       result;
    MemoryContext oldcontext;

    /* stuff done only on the first call of the function */
    if (SRF_IS_FIRSTCALL())
    {
        int64       start = PG_GETARG_INT64(0);
        int64       finish = PG_GETARG_INT64(1);
        int64       step = 1;

        /* see if we were given an explicit step size */
        if (PG_NARGS() == 3)
            step = PG_GETARG_INT64(2);
        if (step == 0)
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("step size cannot equal zero")));

        /* create a function context for cross-call persistence */
        funcctx = SRF_FIRSTCALL_INIT();

        /*
         * switch to memory context appropriate for multiple function calls
         */
        oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);

        /* allocate memory for user context */
        fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));

        /*
         * Use fctx to keep state from call to call. Seed current with the
         * original start value
         */
        fctx->current = start;
        fctx->finish = finish;
        fctx->step = step;

        funcctx->user_fctx = fctx;
        MemoryContextSwitchTo(oldcontext);
    }

    /* stuff done on every call of the function */
    funcctx = SRF_PERCALL_SETUP();

    /*
     * get the saved state and use current as the result for this iteration
     */
    fctx = funcctx->user_fctx;
    result = fctx->current;

    if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
        (fctx->step < 0 && fctx->current >= fctx->finish))
    {
        /* increment current in preparation for next iteration */
        fctx->current += fctx->step;

        /* if next-value computation overflows, this is the final result */
        if (SAMESIGN(result, fctx->step) && !SAMESIGN(result, fctx->current))
            fctx->step = 0;

        /* do when there is more left to send */
        SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
    }
    else
        /* do when there is no more left */
        SRF_RETURN_DONE(funcctx);
}

Datum i8tod ( PG_FUNCTION_ARGS   ) 

Definition at line 1278 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT8.

{
    int64       arg = PG_GETARG_INT64(0);
    float8      result;

    result = arg;

    PG_RETURN_FLOAT8(result);
}

Datum i8tof ( PG_FUNCTION_ARGS   ) 

Definition at line 1316 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT4.

{
    int64       arg = PG_GETARG_INT64(0);
    float4      result;

    result = arg;

    PG_RETURN_FLOAT4(result);
}

Datum i8tooid ( PG_FUNCTION_ARGS   ) 

Definition at line 1355 of file int8.c.

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

{
    int64       arg = PG_GETARG_INT64(0);
    Oid         result;

    result = (Oid) arg;

    /* Test for overflow by reverse-conversion. */
    if ((int64) result != arg)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("OID out of range")));

    PG_RETURN_OID(result);
}

Datum int28 ( PG_FUNCTION_ARGS   ) 

Definition at line 1253 of file int8.c.

References arg, PG_GETARG_INT16, and PG_RETURN_INT64.

{
    int16       arg = PG_GETARG_INT16(0);

    PG_RETURN_INT64((int64) arg);
}

Datum int28div ( PG_FUNCTION_ARGS   ) 

Definition at line 1142 of file int8.c.

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

{
    int16       arg1 = PG_GETARG_INT16(0);
    int64       arg2 = PG_GETARG_INT64(1);

    if (arg2 == 0)
    {
        ereport(ERROR,
                (errcode(ERRCODE_DIVISION_BY_ZERO),
                 errmsg("division by zero")));
        /* ensure compiler realizes we mustn't reach the division (gcc bug) */
        PG_RETURN_NULL();
    }

    /* No overflow is possible */
    PG_RETURN_INT64((int64) arg1 / arg2);
}

Datum int28eq ( PG_FUNCTION_ARGS   ) 

Definition at line 431 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int16       val1 = PG_GETARG_INT16(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 == val2);
}

Datum int28ge ( PG_FUNCTION_ARGS   ) 

Definition at line 476 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int16       val1 = PG_GETARG_INT16(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 >= val2);
}

Datum int28gt ( PG_FUNCTION_ARGS   ) 

Definition at line 458 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int16       val1 = PG_GETARG_INT16(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 > val2);
}

Datum int28le ( PG_FUNCTION_ARGS   ) 

Definition at line 467 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int16       val1 = PG_GETARG_INT16(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 <= val2);
}

Datum int28lt ( PG_FUNCTION_ARGS   ) 

Definition at line 449 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int16       val1 = PG_GETARG_INT16(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 < val2);
}

Datum int28mi ( PG_FUNCTION_ARGS   ) 

Definition at line 1094 of file int8.c.

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

{
    int16       arg1 = PG_GETARG_INT16(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 - arg2;

    /*
     * Overflow check.  If the inputs are of the same sign then their
     * difference cannot overflow.  If they are of different signs then the
     * result should be of the same sign as the first input.
     */
    if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int28mul ( PG_FUNCTION_ARGS   ) 

Definition at line 1115 of file int8.c.

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

{
    int16       arg1 = PG_GETARG_INT16(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 * arg2;

    /*
     * Overflow check.  We basically check to see if result / arg2 gives arg1
     * again.  There is one case where this fails: arg2 = 0 (which cannot
     * overflow).
     *
     * Since the division is likely much more expensive than the actual
     * multiplication, we'd like to skip it where possible.  The best bang for
     * the buck seems to be to check whether both inputs are in the int32
     * range; if so, no overflow is possible.
     */
    if (arg2 != (int64) ((int32) arg2) &&
        result / arg2 != arg1)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int28ne ( PG_FUNCTION_ARGS   ) 

Definition at line 440 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int16       val1 = PG_GETARG_INT16(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 != val2);
}

Datum int28pl ( PG_FUNCTION_ARGS   ) 

Definition at line 1073 of file int8.c.

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

{
    int16       arg1 = PG_GETARG_INT16(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 + arg2;

    /*
     * Overflow check.  If the inputs are of different signs then their sum
     * cannot overflow.  If the inputs are of the same sign, their sum had
     * better be that sign too.
     */
    if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int48 ( PG_FUNCTION_ARGS   ) 

Definition at line 1228 of file int8.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT64.

{
    int32       arg = PG_GETARG_INT32(0);

    PG_RETURN_INT64((int64) arg);
}

Datum int48div ( PG_FUNCTION_ARGS   ) 

Definition at line 945 of file int8.c.

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

{
    int32       arg1 = PG_GETARG_INT32(0);
    int64       arg2 = PG_GETARG_INT64(1);

    if (arg2 == 0)
    {
        ereport(ERROR,
                (errcode(ERRCODE_DIVISION_BY_ZERO),
                 errmsg("division by zero")));
        /* ensure compiler realizes we mustn't reach the division (gcc bug) */
        PG_RETURN_NULL();
    }

    /* No overflow is possible */
    PG_RETURN_INT64((int64) arg1 / arg2);
}

Datum int48eq ( PG_FUNCTION_ARGS   ) 

Definition at line 317 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int32       val1 = PG_GETARG_INT32(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 == val2);
}

Datum int48ge ( PG_FUNCTION_ARGS   ) 

Definition at line 362 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int32       val1 = PG_GETARG_INT32(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 >= val2);
}

Datum int48gt ( PG_FUNCTION_ARGS   ) 

Definition at line 344 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int32       val1 = PG_GETARG_INT32(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 > val2);
}

Datum int48le ( PG_FUNCTION_ARGS   ) 

Definition at line 353 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int32       val1 = PG_GETARG_INT32(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 <= val2);
}

Datum int48lt ( PG_FUNCTION_ARGS   ) 

Definition at line 335 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int32       val1 = PG_GETARG_INT32(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 < val2);
}

Datum int48mi ( PG_FUNCTION_ARGS   ) 

Definition at line 897 of file int8.c.

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

{
    int32       arg1 = PG_GETARG_INT32(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 - arg2;

    /*
     * Overflow check.  If the inputs are of the same sign then their
     * difference cannot overflow.  If they are of different signs then the
     * result should be of the same sign as the first input.
     */
    if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int48mul ( PG_FUNCTION_ARGS   ) 

Definition at line 918 of file int8.c.

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

{
    int32       arg1 = PG_GETARG_INT32(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 * arg2;

    /*
     * Overflow check.  We basically check to see if result / arg2 gives arg1
     * again.  There is one case where this fails: arg2 = 0 (which cannot
     * overflow).
     *
     * Since the division is likely much more expensive than the actual
     * multiplication, we'd like to skip it where possible.  The best bang for
     * the buck seems to be to check whether both inputs are in the int32
     * range; if so, no overflow is possible.
     */
    if (arg2 != (int64) ((int32) arg2) &&
        result / arg2 != arg1)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int48ne ( PG_FUNCTION_ARGS   ) 

Definition at line 326 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int32       val1 = PG_GETARG_INT32(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 != val2);
}

Datum int48pl ( PG_FUNCTION_ARGS   ) 

Definition at line 876 of file int8.c.

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

{
    int32       arg1 = PG_GETARG_INT32(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 + arg2;

    /*
     * Overflow check.  If the inputs are of different signs then their sum
     * cannot overflow.  If the inputs are of the same sign, their sum had
     * better be that sign too.
     */
    if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int82 ( PG_FUNCTION_ARGS   ) 

Definition at line 1261 of file int8.c.

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

{
    int64       arg = PG_GETARG_INT64(0);
    int16       result;

    result = (int16) arg;

    /* Test for overflow by reverse-conversion. */
    if ((int64) result != arg)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("smallint out of range")));

    PG_RETURN_INT16(result);
}

Datum int82div ( PG_FUNCTION_ARGS   ) 

Definition at line 1033 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int16       arg2 = PG_GETARG_INT16(1);
    int64       result;

    if (arg2 == 0)
    {
        ereport(ERROR,
                (errcode(ERRCODE_DIVISION_BY_ZERO),
                 errmsg("division by zero")));
        /* ensure compiler realizes we mustn't reach the division (gcc bug) */
        PG_RETURN_NULL();
    }

    /*
     * INT64_MIN / -1 is problematic, since the result can't be represented on
     * a two's-complement machine.  Some machines produce INT64_MIN, some
     * produce zero, some throw an exception.  We can dodge the problem by
     * recognizing that division by -1 is the same as negation.
     */
    if (arg2 == -1)
    {
        result = -arg1;
        /* overflow check (needed for INT64_MIN) */
        if (arg1 != 0 && SAMESIGN(result, arg1))
            ereport(ERROR,
                    (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                     errmsg("bigint out of range")));
        PG_RETURN_INT64(result);
    }

    /* No overflow is possible */

    result = arg1 / arg2;

    PG_RETURN_INT64(result);
}

Datum int82eq ( PG_FUNCTION_ARGS   ) 

Definition at line 374 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int16       val2 = PG_GETARG_INT16(1);

    PG_RETURN_BOOL(val1 == val2);
}

Datum int82ge ( PG_FUNCTION_ARGS   ) 

Definition at line 419 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int16       val2 = PG_GETARG_INT16(1);

    PG_RETURN_BOOL(val1 >= val2);
}

Datum int82gt ( PG_FUNCTION_ARGS   ) 

Definition at line 401 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int16       val2 = PG_GETARG_INT16(1);

    PG_RETURN_BOOL(val1 > val2);
}

Datum int82le ( PG_FUNCTION_ARGS   ) 

Definition at line 410 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int16       val2 = PG_GETARG_INT16(1);

    PG_RETURN_BOOL(val1 <= val2);
}

Datum int82lt ( PG_FUNCTION_ARGS   ) 

Definition at line 392 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int16       val2 = PG_GETARG_INT16(1);

    PG_RETURN_BOOL(val1 < val2);
}

Datum int82mi ( PG_FUNCTION_ARGS   ) 

Definition at line 985 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int16       arg2 = PG_GETARG_INT16(1);
    int64       result;

    result = arg1 - arg2;

    /*
     * Overflow check.  If the inputs are of the same sign then their
     * difference cannot overflow.  If they are of different signs then the
     * result should be of the same sign as the first input.
     */
    if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int82mul ( PG_FUNCTION_ARGS   ) 

Definition at line 1006 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int16       arg2 = PG_GETARG_INT16(1);
    int64       result;

    result = arg1 * arg2;

    /*
     * Overflow check.  We basically check to see if result / arg1 gives arg2
     * again.  There is one case where this fails: arg1 = 0 (which cannot
     * overflow).
     *
     * Since the division is likely much more expensive than the actual
     * multiplication, we'd like to skip it where possible.  The best bang for
     * the buck seems to be to check whether both inputs are in the int32
     * range; if so, no overflow is possible.
     */
    if (arg1 != (int64) ((int32) arg1) &&
        result / arg1 != arg2)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int82ne ( PG_FUNCTION_ARGS   ) 

Definition at line 383 of file int8.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int16       val2 = PG_GETARG_INT16(1);

    PG_RETURN_BOOL(val1 != val2);
}

Datum int82pl ( PG_FUNCTION_ARGS   ) 

Definition at line 964 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int16       arg2 = PG_GETARG_INT16(1);
    int64       result;

    result = arg1 + arg2;

    /*
     * Overflow check.  If the inputs are of different signs then their sum
     * cannot overflow.  If the inputs are of the same sign, their sum had
     * better be that sign too.
     */
    if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int84 ( PG_FUNCTION_ARGS   ) 

Definition at line 1236 of file int8.c.

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

Referenced by int8_to_char().

{
    int64       arg = PG_GETARG_INT64(0);
    int32       result;

    result = (int32) arg;

    /* Test for overflow by reverse-conversion. */
    if ((int64) result != arg)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("integer out of range")));

    PG_RETURN_INT32(result);
}

Datum int84div ( PG_FUNCTION_ARGS   ) 

Definition at line 836 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int32       arg2 = PG_GETARG_INT32(1);
    int64       result;

    if (arg2 == 0)
    {
        ereport(ERROR,
                (errcode(ERRCODE_DIVISION_BY_ZERO),
                 errmsg("division by zero")));
        /* ensure compiler realizes we mustn't reach the division (gcc bug) */
        PG_RETURN_NULL();
    }

    /*
     * INT64_MIN / -1 is problematic, since the result can't be represented on
     * a two's-complement machine.  Some machines produce INT64_MIN, some
     * produce zero, some throw an exception.  We can dodge the problem by
     * recognizing that division by -1 is the same as negation.
     */
    if (arg2 == -1)
    {
        result = -arg1;
        /* overflow check (needed for INT64_MIN) */
        if (arg1 != 0 && SAMESIGN(result, arg1))
            ereport(ERROR,
                    (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                     errmsg("bigint out of range")));
        PG_RETURN_INT64(result);
    }

    /* No overflow is possible */

    result = arg1 / arg2;

    PG_RETURN_INT64(result);
}

Datum int84eq ( PG_FUNCTION_ARGS   ) 

Definition at line 260 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int32       val2 = PG_GETARG_INT32(1);

    PG_RETURN_BOOL(val1 == val2);
}

Datum int84ge ( PG_FUNCTION_ARGS   ) 

Definition at line 305 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int32       val2 = PG_GETARG_INT32(1);

    PG_RETURN_BOOL(val1 >= val2);
}

Datum int84gt ( PG_FUNCTION_ARGS   ) 

Definition at line 287 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int32       val2 = PG_GETARG_INT32(1);

    PG_RETURN_BOOL(val1 > val2);
}

Datum int84le ( PG_FUNCTION_ARGS   ) 

Definition at line 296 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int32       val2 = PG_GETARG_INT32(1);

    PG_RETURN_BOOL(val1 <= val2);
}

Datum int84lt ( PG_FUNCTION_ARGS   ) 

Definition at line 278 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int32       val2 = PG_GETARG_INT32(1);

    PG_RETURN_BOOL(val1 < val2);
}

Datum int84mi ( PG_FUNCTION_ARGS   ) 

Definition at line 788 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int32       arg2 = PG_GETARG_INT32(1);
    int64       result;

    result = arg1 - arg2;

    /*
     * Overflow check.  If the inputs are of the same sign then their
     * difference cannot overflow.  If they are of different signs then the
     * result should be of the same sign as the first input.
     */
    if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int84mul ( PG_FUNCTION_ARGS   ) 

Definition at line 809 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int32       arg2 = PG_GETARG_INT32(1);
    int64       result;

    result = arg1 * arg2;

    /*
     * Overflow check.  We basically check to see if result / arg1 gives arg2
     * again.  There is one case where this fails: arg1 = 0 (which cannot
     * overflow).
     *
     * Since the division is likely much more expensive than the actual
     * multiplication, we'd like to skip it where possible.  The best bang for
     * the buck seems to be to check whether both inputs are in the int32
     * range; if so, no overflow is possible.
     */
    if (arg1 != (int64) ((int32) arg1) &&
        result / arg1 != arg2)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int84ne ( PG_FUNCTION_ARGS   ) 

Definition at line 269 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int32       val2 = PG_GETARG_INT32(1);

    PG_RETURN_BOOL(val1 != val2);
}

Datum int84pl ( PG_FUNCTION_ARGS   ) 

Definition at line 767 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int32       arg2 = PG_GETARG_INT32(1);
    int64       result;

    result = arg1 + arg2;

    /*
     * Overflow check.  If the inputs are of different signs then their sum
     * cannot overflow.  If the inputs are of the same sign, their sum had
     * better be that sign too.
     */
    if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int8abs ( PG_FUNCTION_ARGS   ) 

Definition at line 630 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       result;

    result = (arg1 < 0) ? -arg1 : arg1;
    /* overflow check (needed for INT64_MIN) */
    if (result < 0)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int8and ( PG_FUNCTION_ARGS   ) 

Definition at line 1171 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);

    PG_RETURN_INT64(arg1 & arg2);
}

Datum int8div ( PG_FUNCTION_ARGS   ) 

Definition at line 587 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    if (arg2 == 0)
    {
        ereport(ERROR,
                (errcode(ERRCODE_DIVISION_BY_ZERO),
                 errmsg("division by zero")));
        /* ensure compiler realizes we mustn't reach the division (gcc bug) */
        PG_RETURN_NULL();
    }

    /*
     * INT64_MIN / -1 is problematic, since the result can't be represented on
     * a two's-complement machine.  Some machines produce INT64_MIN, some
     * produce zero, some throw an exception.  We can dodge the problem by
     * recognizing that division by -1 is the same as negation.
     */
    if (arg2 == -1)
    {
        result = -arg1;
        /* overflow check (needed for INT64_MIN) */
        if (arg1 != 0 && SAMESIGN(result, arg1))
            ereport(ERROR,
                    (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                     errmsg("bigint out of range")));
        PG_RETURN_INT64(result);
    }

    /* No overflow is possible */

    result = arg1 / arg2;

    PG_RETURN_INT64(result);
}

Datum int8eq ( PG_FUNCTION_ARGS   ) 

Definition at line 203 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 == val2);
}

Datum int8ge ( PG_FUNCTION_ARGS   ) 

Definition at line 248 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 >= val2);
}

Datum int8gt ( PG_FUNCTION_ARGS   ) 

Definition at line 230 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 > val2);
}

Datum int8in ( PG_FUNCTION_ARGS   ) 

Definition at line 145 of file int8.c.

References PG_GETARG_CSTRING, PG_RETURN_INT64, and scanint8().

Referenced by defGetInt64().

{
    char       *str = PG_GETARG_CSTRING(0);
    int64       result;

    (void) scanint8(str, false, &result);
    PG_RETURN_INT64(result);
}

Datum int8inc ( PG_FUNCTION_ARGS   ) 

Definition at line 677 of file int8.c.

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

Referenced by int8inc_any(), and int8inc_float8_float8().

{
    /*
     * When int8 is pass-by-reference, we provide this special case to avoid
     * palloc overhead for COUNT(): when called as an aggregate, we know that
     * the argument is modifiable local storage, so just update it in-place.
     * (If int8 is pass-by-value, then of course this is useless as well as
     * incorrect, so just ifdef it out.)
     */
#ifndef USE_FLOAT8_BYVAL        /* controls int8 too */
    if (AggCheckCallContext(fcinfo, NULL))
    {
        int64      *arg = (int64 *) PG_GETARG_POINTER(0);
        int64       result;

        result = *arg + 1;
        /* Overflow check */
        if (result < 0 && *arg > 0)
            ereport(ERROR,
                    (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                     errmsg("bigint out of range")));

        *arg = result;
        PG_RETURN_POINTER(arg);
    }
    else
#endif
    {
        /* Not called as an aggregate, so just do it the dumb way */
        int64       arg = PG_GETARG_INT64(0);
        int64       result;

        result = arg + 1;
        /* Overflow check */
        if (result < 0 && arg > 0)
            ereport(ERROR,
                    (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                     errmsg("bigint out of range")));

        PG_RETURN_INT64(result);
    }
}

Datum int8inc_any ( PG_FUNCTION_ARGS   ) 

Definition at line 730 of file int8.c.

References int8inc().

{
    return int8inc(fcinfo);
}

Datum int8inc_float8_float8 ( PG_FUNCTION_ARGS   ) 

Definition at line 736 of file int8.c.

References int8inc().

{
    return int8inc(fcinfo);
}

Datum int8larger ( PG_FUNCTION_ARGS   ) 

Definition at line 743 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = ((arg1 > arg2) ? arg1 : arg2);

    PG_RETURN_INT64(result);
}

Datum int8le ( PG_FUNCTION_ARGS   ) 

Definition at line 239 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 <= val2);
}

Datum int8lt ( PG_FUNCTION_ARGS   ) 

Definition at line 221 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 < val2);
}

Datum int8mi ( PG_FUNCTION_ARGS   ) 

Definition at line 534 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 - arg2;

    /*
     * Overflow check.  If the inputs are of the same sign then their
     * difference cannot overflow.  If they are of different signs then the
     * result should be of the same sign as the first input.
     */
    if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int8mod ( PG_FUNCTION_ARGS   ) 

Definition at line 648 of file int8.c.

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);

    if (arg2 == 0)
    {
        ereport(ERROR,
                (errcode(ERRCODE_DIVISION_BY_ZERO),
                 errmsg("division by zero")));
        /* ensure compiler realizes we mustn't reach the division (gcc bug) */
        PG_RETURN_NULL();
    }

    /*
     * Some machines throw a floating-point exception for INT64_MIN % -1,
     * which is a bit silly since the correct answer is perfectly
     * well-defined, namely zero.
     */
    if (arg2 == -1)
        PG_RETURN_INT64(0);

    /* No overflow is possible */

    PG_RETURN_INT64(arg1 % arg2);
}

Datum int8mul ( PG_FUNCTION_ARGS   ) 

Definition at line 555 of file int8.c.

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

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

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 * arg2;

    /*
     * Overflow check.  We basically check to see if result / arg2 gives arg1
     * again.  There are two cases where this fails: arg2 = 0 (which cannot
     * overflow) and arg1 = INT64_MIN, arg2 = -1 (where the division itself
     * will overflow and thus incorrectly match).
     *
     * Since the division is likely much more expensive than the actual
     * multiplication, we'd like to skip it where possible.  The best bang for
     * the buck seems to be to check whether both inputs are in the int32
     * range; if so, no overflow is possible.
     */
    if (arg1 != (int64) ((int32) arg1) || arg2 != (int64) ((int32) arg2))
    {
        if (arg2 != 0 &&
            ((arg2 == -1 && arg1 < 0 && result < 0) ||
             result / arg2 != arg1))
            ereport(ERROR,
                    (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                     errmsg("bigint out of range")));
    }
    PG_RETURN_INT64(result);
}

Datum int8ne ( PG_FUNCTION_ARGS   ) 

Definition at line 212 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_BOOL.

{
    int64       val1 = PG_GETARG_INT64(0);
    int64       val2 = PG_GETARG_INT64(1);

    PG_RETURN_BOOL(val1 != val2);
}

Datum int8not ( PG_FUNCTION_ARGS   ) 

Definition at line 1198 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);

    PG_RETURN_INT64(~arg1);
}

Datum int8or ( PG_FUNCTION_ARGS   ) 

Definition at line 1180 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);

    PG_RETURN_INT64(arg1 | arg2);
}

Datum int8out ( PG_FUNCTION_ARGS   ) 

Definition at line 158 of file int8.c.

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

Referenced by int8_to_char().

{
    int64       val = PG_GETARG_INT64(0);
    char        buf[MAXINT8LEN + 1];
    char       *result;

    pg_lltoa(val, buf);
    result = pstrdup(buf);
    PG_RETURN_CSTRING(result);
}

Datum int8pl ( PG_FUNCTION_ARGS   ) 

Definition at line 513 of file int8.c.

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

Referenced by int8range_canonical().

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = arg1 + arg2;

    /*
     * Overflow check.  If the inputs are of different signs then their sum
     * cannot overflow.  If the inputs are of the same sign, their sum had
     * better be that sign too.
     */
    if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int8recv ( PG_FUNCTION_ARGS   ) 
Datum int8send ( PG_FUNCTION_ARGS   ) 
Datum int8shl ( PG_FUNCTION_ARGS   ) 

Definition at line 1206 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);
    int32       arg2 = PG_GETARG_INT32(1);

    PG_RETURN_INT64(arg1 << arg2);
}

Datum int8shr ( PG_FUNCTION_ARGS   ) 

Definition at line 1215 of file int8.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);
    int32       arg2 = PG_GETARG_INT32(1);

    PG_RETURN_INT64(arg1 >> arg2);
}

Datum int8smaller ( PG_FUNCTION_ARGS   ) 

Definition at line 755 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);
    int64       result;

    result = ((arg1 < arg2) ? arg1 : arg2);

    PG_RETURN_INT64(result);
}

Datum int8um ( PG_FUNCTION_ARGS   ) 

Definition at line 490 of file int8.c.

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

{
    int64       arg = PG_GETARG_INT64(0);
    int64       result;

    result = -arg;
    /* overflow check (needed for INT64_MIN) */
    if (arg != 0 && SAMESIGN(result, arg))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("bigint out of range")));
    PG_RETURN_INT64(result);
}

Datum int8up ( PG_FUNCTION_ARGS   ) 

Definition at line 505 of file int8.c.

References arg, PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg = PG_GETARG_INT64(0);

    PG_RETURN_INT64(arg);
}

Datum int8xor ( PG_FUNCTION_ARGS   ) 

Definition at line 1189 of file int8.c.

References PG_GETARG_INT64, and PG_RETURN_INT64.

{
    int64       arg1 = PG_GETARG_INT64(0);
    int64       arg2 = PG_GETARG_INT64(1);

    PG_RETURN_INT64(arg1 ^ arg2);
}

Datum oidtoi8 ( PG_FUNCTION_ARGS   ) 

Definition at line 1372 of file int8.c.

References arg, PG_GETARG_OID, and PG_RETURN_INT64.

{
    Oid         arg = PG_GETARG_OID(0);

    PG_RETURN_INT64((int64) arg);
}

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

Definition at line 55 of file int8.c.

References ereport, errcode(), errmsg(), ERROR, INT64CONST, and sign.

Referenced by int8in(), and make_const().

{
    const char *ptr = str;
    int64       tmp = 0;
    int         sign = 1;

    /*
     * Do our own scan, rather than relying on sscanf which might be broken
     * for long long.
     */

    /* skip leading spaces */
    while (*ptr && isspace((unsigned char) *ptr))
        ptr++;

    /* handle sign */
    if (*ptr == '-')
    {
        ptr++;

        /*
         * Do an explicit check for INT64_MIN.  Ugly though this is, it's
         * cleaner than trying to get the loop below to handle it portably.
         */
        if (strncmp(ptr, "9223372036854775808", 19) == 0)
        {
            tmp = -INT64CONST(0x7fffffffffffffff) - 1;
            ptr += 19;
            goto gotdigits;
        }
        sign = -1;
    }
    else if (*ptr == '+')
        ptr++;

    /* require at least one digit */
    if (!isdigit((unsigned char) *ptr))
    {
        if (errorOK)
            return false;
        else
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for integer: \"%s\"",
                            str)));
    }

    /* process digits */
    while (*ptr && isdigit((unsigned char) *ptr))
    {
        int64       newtmp = tmp * 10 + (*ptr++ - '0');

        if ((newtmp / 10) != tmp)       /* overflow? */
        {
            if (errorOK)
                return false;
            else
                ereport(ERROR,
                        (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                       errmsg("value \"%s\" is out of range for type bigint",
                              str)));
        }
        tmp = newtmp;
    }

gotdigits:

    /* allow trailing whitespace, but not other trailing chars */
    while (*ptr != '\0' && isspace((unsigned char) *ptr))
        ptr++;

    if (*ptr != '\0')
    {
        if (errorOK)
            return false;
        else
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for integer: \"%s\"",
                            str)));
    }

    *result = (sign < 0) ? -tmp : tmp;

    return true;
}