Header And Logo

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

Defines | Typedefs | Functions

numeric.h File Reference

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

Go to the source code of this file.

Defines

#define NUMERIC_MAX_PRECISION   1000
#define NUMERIC_MAX_DISPLAY_SCALE   NUMERIC_MAX_PRECISION
#define NUMERIC_MIN_DISPLAY_SCALE   0
#define NUMERIC_MAX_RESULT_SCALE   (NUMERIC_MAX_PRECISION * 2)
#define NUMERIC_MIN_SIG_DIGITS   16
#define DatumGetNumeric(X)   ((Numeric) PG_DETOAST_DATUM(X))
#define DatumGetNumericCopy(X)   ((Numeric) PG_DETOAST_DATUM_COPY(X))
#define NumericGetDatum(X)   PointerGetDatum(X)
#define PG_GETARG_NUMERIC(n)   DatumGetNumeric(PG_GETARG_DATUM(n))
#define PG_GETARG_NUMERIC_COPY(n)   DatumGetNumericCopy(PG_GETARG_DATUM(n))
#define PG_RETURN_NUMERIC(x)   return NumericGetDatum(x)

Typedefs

typedef struct NumericDataNumeric

Functions

bool numeric_is_nan (Numeric num)
int32 numeric_maximum_size (int32 typmod)
char * numeric_out_sci (Numeric num, int scale)

Define Documentation

#define DatumGetNumeric (   X  )     ((Numeric) PG_DETOAST_DATUM(X))
#define DatumGetNumericCopy (   X  )     ((Numeric) PG_DETOAST_DATUM_COPY(X))

Definition at line 49 of file numeric.h.

#define NUMERIC_MAX_DISPLAY_SCALE   NUMERIC_MAX_PRECISION

Definition at line 28 of file numeric.h.

Referenced by log_var(), numeric_exp(), numeric_ln(), numeric_sqrt(), power_var(), and select_div_scale().

#define NUMERIC_MAX_PRECISION   1000

Definition at line 23 of file numeric.h.

Referenced by numeric_recv(), numerictypmodin(), and set_var_from_str().

#define NUMERIC_MAX_RESULT_SCALE   (NUMERIC_MAX_PRECISION * 2)

Definition at line 31 of file numeric.h.

Referenced by exp_var(), numeric_exp(), numeric_recv(), numeric_round(), numeric_trunc(), and power_var().

#define NUMERIC_MIN_DISPLAY_SCALE   0

Definition at line 29 of file numeric.h.

Referenced by log_var(), numeric_exp(), numeric_ln(), numeric_sqrt(), power_var(), and select_div_scale().

#define NUMERIC_MIN_SIG_DIGITS   16

Definition at line 38 of file numeric.h.

Referenced by log_var(), numeric_exp(), numeric_ln(), numeric_sqrt(), power_var(), and select_div_scale().

#define NumericGetDatum (   X  )     PointerGetDatum(X)
#define PG_GETARG_NUMERIC (   n  )     DatumGetNumeric(PG_GETARG_DATUM(n))
#define PG_GETARG_NUMERIC_COPY (   n  )     DatumGetNumericCopy(PG_GETARG_DATUM(n))

Definition at line 52 of file numeric.h.

#define PG_RETURN_NUMERIC (   x  )     return NumericGetDatum(x)

Typedef Documentation

typedef struct NumericData* Numeric

Definition at line 42 of file numeric.h.


Function Documentation

bool numeric_is_nan ( Numeric  num  ) 

Definition at line 561 of file numeric.c.

References NUMERIC_IS_NAN.

Referenced by gbt_numeric_penalty().

{
    return NUMERIC_IS_NAN(num);
}

int32 numeric_maximum_size ( int32  typmod  ) 

Definition at line 572 of file numeric.c.

References DEC_DIGITS, NUMERIC_HDRSZ, and VARHDRSZ.

Referenced by type_maximum_size().

{
    int         precision;
    int         numeric_digits;

    if (typmod < (int32) (VARHDRSZ))
        return -1;

    /* precision (ie, max # of digits) is in upper bits of typmod */
    precision = ((typmod - VARHDRSZ) >> 16) & 0xffff;

    /*
     * This formula computes the maximum number of NumericDigits we could need
     * in order to store the specified number of decimal digits. Because the
     * weight is stored as a number of NumericDigits rather than a number of
     * decimal digits, it's possible that the first NumericDigit will contain
     * only a single decimal digit.  Thus, the first two decimal digits can
     * require two NumericDigits to store, but it isn't until we reach
     * DEC_DIGITS + 2 decimal digits that we potentially need a third
     * NumericDigit.
     */
    numeric_digits = (precision + 2 * (DEC_DIGITS - 1)) / DEC_DIGITS;

    /*
     * In most cases, the size of a numeric will be smaller than the value
     * computed below, because the varlena header will typically get toasted
     * down to a single byte before being stored on disk, and it may also be
     * possible to use a short numeric header.  But our job here is to compute
     * the worst case.
     */
    return NUMERIC_HDRSZ + (numeric_digits * sizeof(NumericDigit));
}

char* numeric_out_sci ( Numeric  num,
int  scale 
)

Definition at line 611 of file numeric.c.

References get_str_from_var_sci(), init_var_from_num(), NUMERIC_IS_NAN, and pstrdup().

Referenced by int8_to_char(), and numeric_to_char().

{
    NumericVar  x;
    char       *str;

    /*
     * Handle NaN
     */
    if (NUMERIC_IS_NAN(num))
        return pstrdup("NaN");

    init_var_from_num(num, &x);

    str = get_str_from_var_sci(&x, scale);

    return str;
}