Exemplo n.º 1
0
Datum decimal64_inc(PG_FUNCTION_ARGS)
{
        PGDecimal64 a = PG_GETARG_DECIMAL64(0);
        PGDecimal64 one;
        PGDecimal64 ret;
        DECLARE_DEC_CTXT(DEC_INIT_DECIMAL64);

        decDoubleFromInt32(&one, 1);
        decDoubleAdd(&ret, &a, &one, &dc);
        PG_RETURN_DECIMAL64(ret);
}
Exemplo n.º 2
0
Datum decimal64_add(PG_FUNCTION_ARGS)
{
        PGDecimal64 a = PG_GETARG_DECIMAL64(0);
        PGDecimal64 b = PG_GETARG_DECIMAL64(1);
        PGDecimal64 ret;

        DECLARE_DEC_CTXT(DEC_INIT_DECIMAL64);
        decDoubleAdd(&ret, &a, &b, &dc); 
        DEC_CHK_STATUS(dc, DEC_STATUS_OFUF, "decimal64 overflow"); 

        PG_RETURN_DECIMAL64(ret);
}
Exemplo n.º 3
0
int testDecDouble()
{
    int i;
    decDouble a, b;
    decContext set;
    char string[DECDOUBLE_String];

    decContextDefault(&set, DEC_INIT_DECDOUBLE); // initialize

    decDoubleFromString(&a, "0.13", &set);
    decDoubleFromString(&b, "8.7", &set);

    for (i = 0; i < 10; i++)
        decDoubleAdd(&b, &a, &b, &set);    // b += a;

    decDoubleToString(&b, string);

    printf("dec064: 8.7 + 0.13 * 10 => %s\n", string);
    return 0;
}