#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <limits.h>
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/sortsupport.h"
Go to the source code of this file.
Defines | |
#define | M_PI 3.14159265358979323846 |
#define | MAXFLOATWIDTH 64 |
#define | MAXDOUBLEWIDTH 128 |
#define | CHECKFLOATVAL(val, inf_is_valid, zero_is_valid) |
#define | cbrt my_cbrt |
Functions | |
static int | float4_cmp_internal (float4 a, float4 b) |
static int | float8_cmp_internal (float8 a, float8 b) |
static double | cbrt (double x) |
double | get_float8_infinity (void) |
float | get_float4_infinity (void) |
double | get_float8_nan (void) |
float | get_float4_nan (void) |
int | is_infinite (double val) |
Datum | float4in (PG_FUNCTION_ARGS) |
Datum | float4out (PG_FUNCTION_ARGS) |
Datum | float4recv (PG_FUNCTION_ARGS) |
Datum | float4send (PG_FUNCTION_ARGS) |
Datum | float8in (PG_FUNCTION_ARGS) |
Datum | float8out (PG_FUNCTION_ARGS) |
Datum | float8recv (PG_FUNCTION_ARGS) |
Datum | float8send (PG_FUNCTION_ARGS) |
Datum | float4abs (PG_FUNCTION_ARGS) |
Datum | float4um (PG_FUNCTION_ARGS) |
Datum | float4up (PG_FUNCTION_ARGS) |
Datum | float4larger (PG_FUNCTION_ARGS) |
Datum | float4smaller (PG_FUNCTION_ARGS) |
Datum | float8abs (PG_FUNCTION_ARGS) |
Datum | float8um (PG_FUNCTION_ARGS) |
Datum | float8up (PG_FUNCTION_ARGS) |
Datum | float8larger (PG_FUNCTION_ARGS) |
Datum | float8smaller (PG_FUNCTION_ARGS) |
Datum | float4pl (PG_FUNCTION_ARGS) |
Datum | float4mi (PG_FUNCTION_ARGS) |
Datum | float4mul (PG_FUNCTION_ARGS) |
Datum | float4div (PG_FUNCTION_ARGS) |
Datum | float8pl (PG_FUNCTION_ARGS) |
Datum | float8mi (PG_FUNCTION_ARGS) |
Datum | float8mul (PG_FUNCTION_ARGS) |
Datum | float8div (PG_FUNCTION_ARGS) |
Datum | float4eq (PG_FUNCTION_ARGS) |
Datum | float4ne (PG_FUNCTION_ARGS) |
Datum | float4lt (PG_FUNCTION_ARGS) |
Datum | float4le (PG_FUNCTION_ARGS) |
Datum | float4gt (PG_FUNCTION_ARGS) |
Datum | float4ge (PG_FUNCTION_ARGS) |
Datum | btfloat4cmp (PG_FUNCTION_ARGS) |
static int | btfloat4fastcmp (Datum x, Datum y, SortSupport ssup) |
Datum | btfloat4sortsupport (PG_FUNCTION_ARGS) |
Datum | float8eq (PG_FUNCTION_ARGS) |
Datum | float8ne (PG_FUNCTION_ARGS) |
Datum | float8lt (PG_FUNCTION_ARGS) |
Datum | float8le (PG_FUNCTION_ARGS) |
Datum | float8gt (PG_FUNCTION_ARGS) |
Datum | float8ge (PG_FUNCTION_ARGS) |
Datum | btfloat8cmp (PG_FUNCTION_ARGS) |
static int | btfloat8fastcmp (Datum x, Datum y, SortSupport ssup) |
Datum | btfloat8sortsupport (PG_FUNCTION_ARGS) |
Datum | btfloat48cmp (PG_FUNCTION_ARGS) |
Datum | btfloat84cmp (PG_FUNCTION_ARGS) |
Datum | ftod (PG_FUNCTION_ARGS) |
Datum | dtof (PG_FUNCTION_ARGS) |
Datum | dtoi4 (PG_FUNCTION_ARGS) |
Datum | dtoi2 (PG_FUNCTION_ARGS) |
Datum | i4tod (PG_FUNCTION_ARGS) |
Datum | i2tod (PG_FUNCTION_ARGS) |
Datum | ftoi4 (PG_FUNCTION_ARGS) |
Datum | ftoi2 (PG_FUNCTION_ARGS) |
Datum | i4tof (PG_FUNCTION_ARGS) |
Datum | i2tof (PG_FUNCTION_ARGS) |
Datum | dround (PG_FUNCTION_ARGS) |
Datum | dceil (PG_FUNCTION_ARGS) |
Datum | dfloor (PG_FUNCTION_ARGS) |
Datum | dsign (PG_FUNCTION_ARGS) |
Datum | dtrunc (PG_FUNCTION_ARGS) |
Datum | dsqrt (PG_FUNCTION_ARGS) |
Datum | dcbrt (PG_FUNCTION_ARGS) |
Datum | dpow (PG_FUNCTION_ARGS) |
Datum | dexp (PG_FUNCTION_ARGS) |
Datum | dlog1 (PG_FUNCTION_ARGS) |
Datum | dlog10 (PG_FUNCTION_ARGS) |
Datum | dacos (PG_FUNCTION_ARGS) |
Datum | dasin (PG_FUNCTION_ARGS) |
Datum | datan (PG_FUNCTION_ARGS) |
Datum | datan2 (PG_FUNCTION_ARGS) |
Datum | dcos (PG_FUNCTION_ARGS) |
Datum | dcot (PG_FUNCTION_ARGS) |
Datum | dsin (PG_FUNCTION_ARGS) |
Datum | dtan (PG_FUNCTION_ARGS) |
Datum | degrees (PG_FUNCTION_ARGS) |
Datum | dpi (PG_FUNCTION_ARGS) |
Datum | radians (PG_FUNCTION_ARGS) |
Datum | drandom (PG_FUNCTION_ARGS) |
Datum | setseed (PG_FUNCTION_ARGS) |
static float8 * | check_float8_array (ArrayType *transarray, const char *caller, int n) |
Datum | float8_accum (PG_FUNCTION_ARGS) |
Datum | float4_accum (PG_FUNCTION_ARGS) |
Datum | float8_avg (PG_FUNCTION_ARGS) |
Datum | float8_var_pop (PG_FUNCTION_ARGS) |
Datum | float8_var_samp (PG_FUNCTION_ARGS) |
Datum | float8_stddev_pop (PG_FUNCTION_ARGS) |
Datum | float8_stddev_samp (PG_FUNCTION_ARGS) |
Datum | float8_regr_accum (PG_FUNCTION_ARGS) |
Datum | float8_regr_sxx (PG_FUNCTION_ARGS) |
Datum | float8_regr_syy (PG_FUNCTION_ARGS) |
Datum | float8_regr_sxy (PG_FUNCTION_ARGS) |
Datum | float8_regr_avgx (PG_FUNCTION_ARGS) |
Datum | float8_regr_avgy (PG_FUNCTION_ARGS) |
Datum | float8_covar_pop (PG_FUNCTION_ARGS) |
Datum | float8_covar_samp (PG_FUNCTION_ARGS) |
Datum | float8_corr (PG_FUNCTION_ARGS) |
Datum | float8_regr_r2 (PG_FUNCTION_ARGS) |
Datum | float8_regr_slope (PG_FUNCTION_ARGS) |
Datum | float8_regr_intercept (PG_FUNCTION_ARGS) |
Datum | float48pl (PG_FUNCTION_ARGS) |
Datum | float48mi (PG_FUNCTION_ARGS) |
Datum | float48mul (PG_FUNCTION_ARGS) |
Datum | float48div (PG_FUNCTION_ARGS) |
Datum | float84pl (PG_FUNCTION_ARGS) |
Datum | float84mi (PG_FUNCTION_ARGS) |
Datum | float84mul (PG_FUNCTION_ARGS) |
Datum | float84div (PG_FUNCTION_ARGS) |
Datum | float48eq (PG_FUNCTION_ARGS) |
Datum | float48ne (PG_FUNCTION_ARGS) |
Datum | float48lt (PG_FUNCTION_ARGS) |
Datum | float48le (PG_FUNCTION_ARGS) |
Datum | float48gt (PG_FUNCTION_ARGS) |
Datum | float48ge (PG_FUNCTION_ARGS) |
Datum | float84eq (PG_FUNCTION_ARGS) |
Datum | float84ne (PG_FUNCTION_ARGS) |
Datum | float84lt (PG_FUNCTION_ARGS) |
Datum | float84le (PG_FUNCTION_ARGS) |
Datum | float84gt (PG_FUNCTION_ARGS) |
Datum | float84ge (PG_FUNCTION_ARGS) |
Datum | width_bucket_float8 (PG_FUNCTION_ARGS) |
Variables | |
int | extra_float_digits = 0 |
#define CHECKFLOATVAL | ( | val, | ||
inf_is_valid, | ||||
zero_is_valid | ||||
) |
do { \ if (isinf(val) && !(inf_is_valid)) \ ereport(ERROR, \ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), \ errmsg("value out of range: overflow"))); \ \ if ((val) == 0.0 && !(zero_is_valid)) \ ereport(ERROR, \ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), \ errmsg("value out of range: underflow"))); \ } while(0)
Definition at line 50 of file float.c.
Referenced by dacos(), dasin(), datan(), datan2(), dcbrt(), dcos(), dcot(), degrees(), dexp(), dlog1(), dlog10(), dpow(), dsin(), dsqrt(), dtan(), dtof(), float48div(), float48mi(), float48mul(), float48pl(), float4_accum(), float4div(), float4in(), float4mi(), float4mul(), float4pl(), float84div(), float84mi(), float84mul(), float84pl(), float8_accum(), float8_corr(), float8_covar_pop(), float8_covar_samp(), float8_regr_accum(), float8_regr_intercept(), float8_regr_r2(), float8_regr_slope(), float8_regr_sxx(), float8_regr_sxy(), float8_regr_syy(), float8_stddev_pop(), float8_stddev_samp(), float8_var_pop(), float8_var_samp(), float8div(), float8in(), float8mi(), float8mul(), float8pl(), and radians().
#define M_PI 3.14159265358979323846 |
#define MAXDOUBLEWIDTH 128 |
Definition at line 45 of file float.c.
Referenced by float8out().
#define MAXFLOATWIDTH 64 |
Definition at line 44 of file float.c.
Referenced by float4out().
Datum btfloat48cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1097 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_INT32.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); /* widen float4 to float8 and then compare */ PG_RETURN_INT32(float8_cmp_internal(arg1, arg2)); }
Datum btfloat4cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 956 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_INT32.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_INT32(float4_cmp_internal(arg1, arg2)); }
static int btfloat4fastcmp | ( | Datum | x, | |
Datum | y, | |||
SortSupport | ssup | |||
) | [static] |
Definition at line 965 of file float.c.
References DatumGetFloat4, and float4_cmp_internal().
{ float4 arg1 = DatumGetFloat4(x); float4 arg2 = DatumGetFloat4(y); return float4_cmp_internal(arg1, arg2); }
Datum btfloat4sortsupport | ( | PG_FUNCTION_ARGS | ) |
Definition at line 974 of file float.c.
References SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.
{ SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); ssup->comparator = btfloat4fastcmp; PG_RETURN_VOID(); }
Datum btfloat84cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1107 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_INT32.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); /* widen float4 to float8 and then compare */ PG_RETURN_INT32(float8_cmp_internal(arg1, arg2)); }
Datum btfloat8cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1070 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_INT32.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_INT32(float8_cmp_internal(arg1, arg2)); }
static int btfloat8fastcmp | ( | Datum | x, | |
Datum | y, | |||
SortSupport | ssup | |||
) | [static] |
Definition at line 1079 of file float.c.
References DatumGetFloat8, and float8_cmp_internal().
{ float8 arg1 = DatumGetFloat8(x); float8 arg2 = DatumGetFloat8(y); return float8_cmp_internal(arg1, arg2); }
Datum btfloat8sortsupport | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1088 of file float.c.
References SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.
{ SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); ssup->comparator = btfloat8fastcmp; PG_RETURN_VOID(); }
static double cbrt | ( | double | x | ) | [static] |
Definition at line 2809 of file float.c.
{ int isneg = (x < 0.0); double absx = fabs(x); double tmpres = pow(absx, (double) 1.0 / (double) 3.0); /* * The result is somewhat inaccurate --- not really pow()'s fault, as the * exponent it's handed contains roundoff error. We can improve the * accuracy by doing one iteration of Newton's formula. Beware of zero * input however. */ if (tmpres > 0.0) tmpres -= (tmpres - absx / (tmpres * tmpres)) / (double) 3.0; return isneg ? -tmpres : tmpres; }
Definition at line 1793 of file float.c.
References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, elog, ERROR, and FLOAT8OID.
Referenced by float4_accum(), float8_accum(), float8_avg(), float8_corr(), float8_covar_pop(), float8_covar_samp(), float8_regr_accum(), float8_regr_avgx(), float8_regr_avgy(), float8_regr_intercept(), float8_regr_r2(), float8_regr_slope(), float8_regr_sxx(), float8_regr_sxy(), float8_regr_syy(), float8_stddev_pop(), float8_stddev_samp(), float8_var_pop(), and float8_var_samp().
{ /* * We expect the input to be an N-element float array; verify that. We * don't need to use deconstruct_array() since the array data is just * going to look like a C array of N float8 values. */ if (ARR_NDIM(transarray) != 1 || ARR_DIMS(transarray)[0] != n || ARR_HASNULL(transarray) || ARR_ELEMTYPE(transarray) != FLOAT8OID) elog(ERROR, "%s: expected %d-element float8 array", caller, n); return (float8 *) ARR_DATA_PTR(transarray); }
Datum dacos | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1523 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; /* * We use errno here because the trigonometric functions are cyclic and * hard to check for underflow. */ errno = 0; result = acos(arg1); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); CHECKFLOATVAL(result, isinf(arg1), true); PG_RETURN_FLOAT8(result); }
Datum dasin | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1548 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; errno = 0; result = asin(arg1); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); CHECKFLOATVAL(result, isinf(arg1), true); PG_RETURN_FLOAT8(result); }
Datum datan | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1569 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; errno = 0; result = atan(arg1); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); CHECKFLOATVAL(result, isinf(arg1), true); PG_RETURN_FLOAT8(result); }
Datum datan2 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1590 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; errno = 0; result = atan2(arg1, arg2); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT8(result); }
Datum dcbrt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1377 of file float.c.
References cbrt, CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; result = cbrt(arg1); CHECKFLOATVAL(result, isinf(arg1), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum dceil | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1290 of file float.c.
References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); PG_RETURN_FLOAT8(ceil(arg1)); }
Datum dcos | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1612 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; errno = 0; result = cos(arg1); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); CHECKFLOATVAL(result, isinf(arg1), true); PG_RETURN_FLOAT8(result); }
Datum dcot | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1633 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; errno = 0; result = tan(arg1); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); result = 1.0 / result; CHECKFLOATVAL(result, true /* cotan(pi/2) == inf */ , true); PG_RETURN_FLOAT8(result); }
Datum degrees | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1697 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; result = arg1 * (180.0 / M_PI); CHECKFLOATVAL(result, isinf(arg1), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum dexp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1445 of file float.c.
References CHECKFLOATVAL, get_float8_infinity(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; errno = 0; result = exp(arg1); if (errno == ERANGE && result != 0 && !isinf(result)) result = get_float8_infinity(); CHECKFLOATVAL(result, isinf(arg1), false); PG_RETURN_FLOAT8(result); }
Datum dfloor | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1302 of file float.c.
References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); PG_RETURN_FLOAT8(floor(arg1)); }
Datum dlog1 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1464 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; /* * Emit particular SQLSTATE error codes for ln(). This is required by the * SQL standard. */ if (arg1 == 0.0) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of zero"))); if (arg1 < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of a negative number"))); result = log(arg1); CHECKFLOATVAL(result, isinf(arg1), arg1 == 1); PG_RETURN_FLOAT8(result); }
Datum dlog10 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1493 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; /* * Emit particular SQLSTATE error codes for log(). The SQL spec doesn't * define log(), but it does define ln(), so it makes sense to emit the * same error code for an analogous error condition. */ if (arg1 == 0.0) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of zero"))); if (arg1 < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of a negative number"))); result = log10(arg1); CHECKFLOATVAL(result, isinf(arg1), arg1 == 1); PG_RETURN_FLOAT8(result); }
Datum dpi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1713 of file float.c.
References M_PI, and PG_RETURN_FLOAT8.
{ PG_RETURN_FLOAT8(M_PI); }
Datum dpow | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1392 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_infinity(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; /* * The SQL spec requires that we emit a particular SQLSTATE error code for * certain error conditions. Specifically, we don't return a * divide-by-zero error code for 0 ^ -1. */ if (arg1 == 0 && arg2 < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION), errmsg("zero raised to a negative power is undefined"))); if (arg1 < 0 && floor(arg2) != arg2) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION), errmsg("a negative number raised to a non-integer power yields a complex result"))); /* * pow() sets errno only on some platforms, depending on whether it * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we try to avoid using * errno. However, some platform/CPU combinations return errno == EDOM * and result == Nan for negative arg1 and very large arg2 (they must be * using something different from our floor() test to decide it's * invalid). Other platforms (HPPA) return errno == ERANGE and a large * (HUGE_VAL) but finite result to signal overflow. */ errno = 0; result = pow(arg1, arg2); if (errno == EDOM && isnan(result)) { if ((fabs(arg1) > 1 && arg2 >= 0) || (fabs(arg1) < 1 && arg2 < 0)) /* The sign of Inf is not significant in this case. */ result = get_float8_infinity(); else if (fabs(arg1) != 1) result = 0; else result = 1; } else if (errno == ERANGE && result != 0 && !isinf(result)) result = get_float8_infinity(); CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum drandom | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1739 of file float.c.
References MAX_RANDOM_VALUE, PG_RETURN_FLOAT8, and random().
{ float8 result; /* result [0.0 - 1.0) */ result = (double) random() / ((double) MAX_RANDOM_VALUE + 1); PG_RETURN_FLOAT8(result); }
Datum dround | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1278 of file float.c.
References PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and rint().
{ float8 arg1 = PG_GETARG_FLOAT8(0); PG_RETURN_FLOAT8(rint(arg1)); }
Datum dsign | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1315 of file float.c.
References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; if (arg1 > 0) result = 1.0; else if (arg1 < 0) result = -1.0; else result = 0.0; PG_RETURN_FLOAT8(result); }
Datum dsin | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1655 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; errno = 0; result = sin(arg1); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); CHECKFLOATVAL(result, isinf(arg1), true); PG_RETURN_FLOAT8(result); }
Datum dsqrt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1356 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; if (arg1 < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION), errmsg("cannot take square root of a negative number"))); result = sqrt(arg1); CHECKFLOATVAL(result, isinf(arg1), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum dtan | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1676 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; errno = 0; result = tan(arg1); if (errno != 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); CHECKFLOATVAL(result, true /* tan(pi/2) == Inf */ , true); PG_RETURN_FLOAT8(result); }
Datum dtof | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1139 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT4.
{ float8 num = PG_GETARG_FLOAT8(0); CHECKFLOATVAL((float4) num, isinf(num), num == 0); PG_RETURN_FLOAT4((float4) num); }
Datum dtoi2 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1173 of file float.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_FLOAT8, PG_RETURN_INT16, and rint().
{ float8 num = PG_GETARG_FLOAT8(0); if (num < SHRT_MIN || num > SHRT_MAX || isnan(num)) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("smallint out of range"))); PG_RETURN_INT16((int16) rint(num)); }
Datum dtoi4 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1153 of file float.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_FLOAT8, PG_RETURN_INT32, and rint().
{ float8 num = PG_GETARG_FLOAT8(0); int32 result; /* 'Inf' is handled by INT_MAX */ if (num < INT_MIN || num > INT_MAX || isnan(num)) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("integer out of range"))); result = (int32) rint(num); PG_RETURN_INT32(result); }
Datum dtrunc | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1338 of file float.c.
References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; if (arg1 >= 0) result = floor(arg1); else result = -floor(-arg1); PG_RETURN_FLOAT8(result); }
Datum float48div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2522 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; if (arg2 == 0.0) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); result = arg1 / arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum float48eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2612 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) == 0); }
Datum float48ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2657 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) >= 0); }
Datum float48gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2648 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) > 0); }
Datum float48le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2639 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) <= 0); }
Datum float48lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2630 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) < 0); }
Datum float48mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2497 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; result = arg1 - arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT8(result); }
Datum float48mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2509 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT8(result); }
Datum float48ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2621 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) != 0); }
Datum float48pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2485 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; result = arg1 + arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT8(result); }
Datum float4_accum | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1860 of file float.c.
References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, construct_array(), Float8GetDatumFast, FLOAT8OID, isinf(), NULL, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT4, and PG_RETURN_ARRAYTYPE_P.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); /* do computations as float8 */ float8 newval = PG_GETARG_FLOAT4(1); float8 *transvalues; float8 N, sumX, sumX2; transvalues = check_float8_array(transarray, "float4_accum", 3); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; N += 1.0; sumX += newval; CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newval), true); sumX2 += newval * newval; CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newval), true); /* * If we're invoked as an aggregate, we can cheat and modify our first * parameter in-place to reduce palloc overhead. Otherwise we construct a * new array with the updated transition data and return it. */ if (AggCheckCallContext(fcinfo, NULL)) { transvalues[0] = N; transvalues[1] = sumX; transvalues[2] = sumX2; PG_RETURN_ARRAYTYPE_P(transarray); } else { Datum transdatums[3]; ArrayType *result; transdatums[0] = Float8GetDatumFast(N); transdatums[1] = Float8GetDatumFast(sumX); transdatums[2] = Float8GetDatumFast(sumX2); result = construct_array(transdatums, 3, FLOAT8OID, sizeof(float8), FLOAT8PASSBYVAL, 'd'); PG_RETURN_ARRAYTYPE_P(result); } }
Definition at line 872 of file float.c.
Referenced by btfloat4cmp(), btfloat4fastcmp(), float4eq(), float4ge(), float4gt(), float4larger(), float4le(), float4lt(), float4ne(), and float4smaller().
{ /* * We consider all NANs to be equal and larger than any non-NAN. This is * somewhat arbitrary; the important thing is to have a consistent sort * order. */ if (isnan(a)) { if (isnan(b)) return 0; /* NAN = NAN */ else return 1; /* NAN > non-NAN */ } else if (isnan(b)) { return -1; /* non-NAN < NAN */ } else { if (a > b) return 1; else if (a < b) return -1; else return 0; } }
Datum float4abs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 598 of file float.c.
References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); PG_RETURN_FLOAT4((float4) fabs(arg1)); }
Datum float4div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 780 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); float4 result; if (arg2 == 0.0) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); result = arg1 / arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0); PG_RETURN_FLOAT4(result); }
Datum float4eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 902 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) == 0); }
Datum float4ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 947 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) >= 0); }
Datum float4gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 938 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) > 0); }
Datum float4in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 186 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float4_infinity(), get_float4_nan(), isinf(), PG_GETARG_CSTRING, PG_RETURN_FLOAT4, pg_strncasecmp(), and val.
Referenced by numeric_float4().
{ char *num = PG_GETARG_CSTRING(0); char *orig_num; double val; char *endptr; /* * endptr points to the first character _after_ the sequence we recognized * as a valid floating point number. orig_num points to the original input * string. */ orig_num = num; /* * Check for an empty-string input to begin with, to avoid the vagaries of * strtod() on different platforms. */ if (*num == '\0') ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type real: \"%s\"", orig_num))); /* skip leading whitespace */ while (*num != '\0' && isspace((unsigned char) *num)) num++; errno = 0; val = strtod(num, &endptr); /* did we not see anything that looks like a double? */ if (endptr == num || errno != 0) { int save_errno = errno; /* * C99 requires that strtod() accept NaN and [-]Infinity, but not all * platforms support that yet (and some accept them but set ERANGE * anyway...) Therefore, we check for these inputs ourselves. */ if (pg_strncasecmp(num, "NaN", 3) == 0) { val = get_float4_nan(); endptr = num + 3; } else if (pg_strncasecmp(num, "Infinity", 8) == 0) { val = get_float4_infinity(); endptr = num + 8; } else if (pg_strncasecmp(num, "-Infinity", 9) == 0) { val = -get_float4_infinity(); endptr = num + 9; } else if (save_errno == ERANGE) { /* * Some platforms return ERANGE for denormalized numbers (those * that are not zero, but are too close to zero to have full * precision). We'd prefer not to throw error for that, so try to * detect whether it's a "real" out-of-range condition by checking * to see if the result is zero or huge. */ if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("\"%s\" is out of range for type real", orig_num))); } else ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type real: \"%s\"", orig_num))); } #ifdef HAVE_BUGGY_SOLARIS_STRTOD else { /* * Many versions of Solaris have a bug wherein strtod sets endptr to * point one byte beyond the end of the string when given "inf" or * "infinity". */ if (endptr != num && endptr[-1] == '\0') endptr--; } #endif /* HAVE_BUGGY_SOLARIS_STRTOD */ #ifdef HAVE_BUGGY_IRIX_STRTOD /* * In some IRIX versions, strtod() recognizes only "inf", so if the input * is "infinity" we have to skip over "inity". Also, it may return * positive infinity for "-inf". */ if (isinf(val)) { if (pg_strncasecmp(num, "Infinity", 8) == 0) { val = get_float4_infinity(); endptr = num + 8; } else if (pg_strncasecmp(num, "-Infinity", 9) == 0) { val = -get_float4_infinity(); endptr = num + 9; } else if (pg_strncasecmp(num, "-inf", 4) == 0) { val = -get_float4_infinity(); endptr = num + 4; } } #endif /* HAVE_BUGGY_IRIX_STRTOD */ /* skip trailing whitespace */ while (*endptr != '\0' && isspace((unsigned char) *endptr)) endptr++; /* if there is any junk left at the end of the string, bail out */ if (*endptr != '\0') ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type real: \"%s\"", orig_num))); /* * if we get here, we have a legal double, still need to check to see if * it's a legal float4 */ CHECKFLOATVAL((float4) val, isinf(val), val == 0); PG_RETURN_FLOAT4((float4) val); }
Datum float4larger | ( | PG_FUNCTION_ARGS | ) |
Definition at line 627 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); float4 result; if (float4_cmp_internal(arg1, arg2) > 0) result = arg1; else result = arg2; PG_RETURN_FLOAT4(result); }
Datum float4le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 929 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) <= 0); }
Datum float4lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 920 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) < 0); }
Datum float4mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 755 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); float4 result; result = arg1 - arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT4(result); }
Datum float4mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 767 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); float4 result; result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT4(result); }
Datum float4ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 911 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) != 0); }
Datum float4out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 328 of file float.c.
References ascii(), extra_float_digits, is_infinite(), MAXFLOATWIDTH, palloc(), PG_GETARG_FLOAT4, PG_RETURN_CSTRING, and snprintf().
{ float4 num = PG_GETARG_FLOAT4(0); char *ascii = (char *) palloc(MAXFLOATWIDTH + 1); if (isnan(num)) PG_RETURN_CSTRING(strcpy(ascii, "NaN")); switch (is_infinite(num)) { case 1: strcpy(ascii, "Infinity"); break; case -1: strcpy(ascii, "-Infinity"); break; default: { int ndig = FLT_DIG + extra_float_digits; if (ndig < 1) ndig = 1; snprintf(ascii, MAXFLOATWIDTH + 1, "%.*g", ndig, num); } } PG_RETURN_CSTRING(ascii); }
Datum float4pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 735 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); float4 result; result = arg1 + arg2; /* * There isn't any way to check for underflow of addition/subtraction * because numbers near the underflow value have already been rounded to * the point where we can't detect that the two values were originally * different, e.g. on x86, '1e-45'::float4 == '2e-45'::float4 == * 1.4013e-45. */ CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT4(result); }
Datum float4recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 362 of file float.c.
References buf, PG_GETARG_POINTER, PG_RETURN_FLOAT4, and pq_getmsgfloat4().
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); PG_RETURN_FLOAT4(pq_getmsgfloat4(buf)); }
Datum float4send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 373 of file float.c.
References buf, PG_GETARG_FLOAT4, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendfloat4().
{ float4 num = PG_GETARG_FLOAT4(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendfloat4(&buf, num); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum float4smaller | ( | PG_FUNCTION_ARGS | ) |
Definition at line 641 of file float.c.
References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 arg2 = PG_GETARG_FLOAT4(1); float4 result; if (float4_cmp_internal(arg1, arg2) < 0) result = arg1; else result = arg2; PG_RETURN_FLOAT4(result); }
Datum float4um | ( | PG_FUNCTION_ARGS | ) |
Definition at line 609 of file float.c.
References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg1 = PG_GETARG_FLOAT4(0); float4 result; result = -arg1; PG_RETURN_FLOAT4(result); }
Datum float4up | ( | PG_FUNCTION_ARGS | ) |
Definition at line 619 of file float.c.
References arg, PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.
{ float4 arg = PG_GETARG_FLOAT4(0); PG_RETURN_FLOAT4(arg); }
Datum float84div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2585 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); float8 result; if (arg2 == 0.0) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); result = arg1 / arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum float84eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2669 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) == 0); }
Datum float84ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2714 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) >= 0); }
Datum float84gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2705 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) > 0); }
Datum float84le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2696 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) <= 0); }
Datum float84lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2687 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) < 0); }
Datum float84mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2558 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); float8 result; result = arg1 - arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT8(result); }
Datum float84mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2571 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); float8 result; result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT8(result); }
Datum float84ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2678 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) != 0); }
Datum float84pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2545 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float4 arg2 = PG_GETARG_FLOAT4(1); float8 result; result = arg1 + arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT8(result); }
Datum float8_accum | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1809 of file float.c.
References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, construct_array(), Float8GetDatumFast, FLOAT8OID, isinf(), NULL, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, and PG_RETURN_ARRAYTYPE_P.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 newval = PG_GETARG_FLOAT8(1); float8 *transvalues; float8 N, sumX, sumX2; transvalues = check_float8_array(transarray, "float8_accum", 3); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; N += 1.0; sumX += newval; CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newval), true); sumX2 += newval * newval; CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newval), true); /* * If we're invoked as an aggregate, we can cheat and modify our first * parameter in-place to reduce palloc overhead. Otherwise we construct a * new array with the updated transition data and return it. */ if (AggCheckCallContext(fcinfo, NULL)) { transvalues[0] = N; transvalues[1] = sumX; transvalues[2] = sumX2; PG_RETURN_ARRAYTYPE_P(transarray); } else { Datum transdatums[3]; ArrayType *result; transdatums[0] = Float8GetDatumFast(N); transdatums[1] = Float8GetDatumFast(sumX); transdatums[2] = Float8GetDatumFast(sumX2); result = construct_array(transdatums, 3, FLOAT8OID, sizeof(float8), FLOAT8PASSBYVAL, 'd'); PG_RETURN_ARRAYTYPE_P(result); } }
Datum float8_avg | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1913 of file float.c.
References check_float8_array(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX; transvalues = check_float8_array(transarray, "float8_avg", 3); N = transvalues[0]; sumX = transvalues[1]; /* ignore sumX2 */ /* SQL defines AVG of no values to be NULL */ if (N == 0.0) PG_RETURN_NULL(); PG_RETURN_FLOAT8(sumX / N); }
Definition at line 986 of file float.c.
Referenced by btfloat48cmp(), btfloat84cmp(), btfloat8cmp(), btfloat8fastcmp(), float48eq(), float48ge(), float48gt(), float48le(), float48lt(), float48ne(), float84eq(), float84ge(), float84gt(), float84le(), float84lt(), float84ne(), float8eq(), float8ge(), float8gt(), float8larger(), float8le(), float8lt(), float8ne(), and float8smaller().
{ /* * We consider all NANs to be equal and larger than any non-NAN. This is * somewhat arbitrary; the important thing is to have a consistent sort * order. */ if (isnan(a)) { if (isnan(b)) return 0; /* NAN = NAN */ else return 1; /* NAN > non-NAN */ } else if (isnan(b)) { return -1; /* non-NAN < NAN */ } else { if (a > b) return 1; else if (a < b) return -1; else return 0; } }
Datum float8_corr | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2318 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, sumY, sumY2, sumXY, numeratorX, numeratorY, numeratorXY; transvalues = check_float8_array(transarray, "float8_corr", 6); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; sumY = transvalues[3]; sumY2 = transvalues[4]; sumXY = transvalues[5]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numeratorX = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true); numeratorY = N * sumY2 - sumY * sumY; CHECKFLOATVAL(numeratorY, isinf(sumY2) || isinf(sumY), true); numeratorXY = N * sumXY - sumX * sumY; CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) || isinf(sumY), true); if (numeratorX <= 0 || numeratorY <= 0) PG_RETURN_NULL(); PG_RETURN_FLOAT8(numeratorXY / sqrt(numeratorX * numeratorY)); }
Datum float8_covar_pop | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2262 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumY, sumXY, numerator; transvalues = check_float8_array(transarray, "float8_covar_pop", 6); N = transvalues[0]; sumX = transvalues[1]; sumY = transvalues[3]; sumXY = transvalues[5]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numerator = N * sumXY - sumX * sumY; CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) || isinf(sumY), true); PG_RETURN_FLOAT8(numerator / (N * N)); }
Datum float8_covar_samp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2290 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumY, sumXY, numerator; transvalues = check_float8_array(transarray, "float8_covar_samp", 6); N = transvalues[0]; sumX = transvalues[1]; sumY = transvalues[3]; sumXY = transvalues[5]; /* if N is <= 1 we should return NULL */ if (N < 2.0) PG_RETURN_NULL(); numerator = N * sumXY - sumX * sumY; CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) || isinf(sumY), true); PG_RETURN_FLOAT8(numerator / (N * (N - 1.0))); }
Datum float8_regr_accum | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2065 of file float.c.
References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, construct_array(), Float8GetDatumFast, FLOAT8OID, isinf(), NULL, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, and PG_RETURN_ARRAYTYPE_P.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 newvalY = PG_GETARG_FLOAT8(1); float8 newvalX = PG_GETARG_FLOAT8(2); float8 *transvalues; float8 N, sumX, sumX2, sumY, sumY2, sumXY; transvalues = check_float8_array(transarray, "float8_regr_accum", 6); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; sumY = transvalues[3]; sumY2 = transvalues[4]; sumXY = transvalues[5]; N += 1.0; sumX += newvalX; CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newvalX), true); sumX2 += newvalX * newvalX; CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newvalX), true); sumY += newvalY; CHECKFLOATVAL(sumY, isinf(transvalues[3]) || isinf(newvalY), true); sumY2 += newvalY * newvalY; CHECKFLOATVAL(sumY2, isinf(transvalues[4]) || isinf(newvalY), true); sumXY += newvalX * newvalY; CHECKFLOATVAL(sumXY, isinf(transvalues[5]) || isinf(newvalX) || isinf(newvalY), true); /* * If we're invoked as an aggregate, we can cheat and modify our first * parameter in-place to reduce palloc overhead. Otherwise we construct a * new array with the updated transition data and return it. */ if (AggCheckCallContext(fcinfo, NULL)) { transvalues[0] = N; transvalues[1] = sumX; transvalues[2] = sumX2; transvalues[3] = sumY; transvalues[4] = sumY2; transvalues[5] = sumXY; PG_RETURN_ARRAYTYPE_P(transarray); } else { Datum transdatums[6]; ArrayType *result; transdatums[0] = Float8GetDatumFast(N); transdatums[1] = Float8GetDatumFast(sumX); transdatums[2] = Float8GetDatumFast(sumX2); transdatums[3] = Float8GetDatumFast(sumY); transdatums[4] = Float8GetDatumFast(sumY2); transdatums[5] = Float8GetDatumFast(sumXY); result = construct_array(transdatums, 6, FLOAT8OID, sizeof(float8), FLOAT8PASSBYVAL, 'd'); PG_RETURN_ARRAYTYPE_P(result); } }
Datum float8_regr_avgx | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2224 of file float.c.
References check_float8_array(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX; transvalues = check_float8_array(transarray, "float8_regr_avgx", 6); N = transvalues[0]; sumX = transvalues[1]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); PG_RETURN_FLOAT8(sumX / N); }
Datum float8_regr_avgy | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2243 of file float.c.
References check_float8_array(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumY; transvalues = check_float8_array(transarray, "float8_regr_avgy", 6); N = transvalues[0]; sumY = transvalues[3]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); PG_RETURN_FLOAT8(sumY / N); }
Datum float8_regr_intercept | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2437 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, sumY, sumXY, numeratorX, numeratorXXY; transvalues = check_float8_array(transarray, "float8_regr_intercept", 6); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; sumY = transvalues[3]; sumXY = transvalues[5]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numeratorX = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true); numeratorXXY = sumY * sumX2 - sumX * sumXY; CHECKFLOATVAL(numeratorXXY, isinf(sumY) || isinf(sumX2) || isinf(sumX) || isinf(sumXY), true); if (numeratorX <= 0) PG_RETURN_NULL(); PG_RETURN_FLOAT8(numeratorXXY / numeratorX); }
Datum float8_regr_r2 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2358 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, sumY, sumY2, sumXY, numeratorX, numeratorY, numeratorXY; transvalues = check_float8_array(transarray, "float8_regr_r2", 6); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; sumY = transvalues[3]; sumY2 = transvalues[4]; sumXY = transvalues[5]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numeratorX = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true); numeratorY = N * sumY2 - sumY * sumY; CHECKFLOATVAL(numeratorY, isinf(sumY2) || isinf(sumY), true); numeratorXY = N * sumXY - sumX * sumY; CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) || isinf(sumY), true); if (numeratorX <= 0) PG_RETURN_NULL(); /* per spec, horizontal line produces 1.0 */ if (numeratorY <= 0) PG_RETURN_FLOAT8(1.0); PG_RETURN_FLOAT8((numeratorXY * numeratorXY) / (numeratorX * numeratorY)); }
Datum float8_regr_slope | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2402 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, sumY, sumXY, numeratorX, numeratorXY; transvalues = check_float8_array(transarray, "float8_regr_slope", 6); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; sumY = transvalues[3]; sumXY = transvalues[5]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numeratorX = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true); numeratorXY = N * sumXY - sumX * sumY; CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) || isinf(sumY), true); if (numeratorX <= 0) PG_RETURN_NULL(); PG_RETURN_FLOAT8(numeratorXY / numeratorX); }
Datum float8_regr_sxx | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2136 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, numerator; transvalues = check_float8_array(transarray, "float8_regr_sxx", 6); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numerator = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true); /* Watch out for roundoff error producing a negative numerator */ if (numerator <= 0.0) PG_RETURN_FLOAT8(0.0); PG_RETURN_FLOAT8(numerator / N); }
Datum float8_regr_sxy | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2194 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumY, sumXY, numerator; transvalues = check_float8_array(transarray, "float8_regr_sxy", 6); N = transvalues[0]; sumX = transvalues[1]; sumY = transvalues[3]; sumXY = transvalues[5]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numerator = N * sumXY - sumX * sumY; CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) || isinf(sumY), true); /* A negative result is valid here */ PG_RETURN_FLOAT8(numerator / N); }
Datum float8_regr_syy | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2165 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumY, sumY2, numerator; transvalues = check_float8_array(transarray, "float8_regr_syy", 6); N = transvalues[0]; sumY = transvalues[3]; sumY2 = transvalues[4]; /* if N is 0 we should return NULL */ if (N < 1.0) PG_RETURN_NULL(); numerator = N * sumY2 - sumY * sumY; CHECKFLOATVAL(numerator, isinf(sumY2) || isinf(sumY), true); /* Watch out for roundoff error producing a negative numerator */ if (numerator <= 0.0) PG_RETURN_FLOAT8(0.0); PG_RETURN_FLOAT8(numerator / N); }
Datum float8_stddev_pop | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1991 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, numerator; transvalues = check_float8_array(transarray, "float8_stddev_pop", 3); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; /* Population stddev is undefined when N is 0, so return NULL */ if (N == 0.0) PG_RETURN_NULL(); numerator = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true); /* Watch out for roundoff error producing a negative numerator */ if (numerator <= 0.0) PG_RETURN_FLOAT8(0.0); PG_RETURN_FLOAT8(sqrt(numerator / (N * N))); }
Datum float8_stddev_samp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2020 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, numerator; transvalues = check_float8_array(transarray, "float8_stddev_samp", 3); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; /* Sample stddev is undefined when N is 0 or 1, so return NULL */ if (N <= 1.0) PG_RETURN_NULL(); numerator = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true); /* Watch out for roundoff error producing a negative numerator */ if (numerator <= 0.0) PG_RETURN_FLOAT8(0.0); PG_RETURN_FLOAT8(sqrt(numerator / (N * (N - 1.0)))); }
Datum float8_var_pop | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1933 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, numerator; transvalues = check_float8_array(transarray, "float8_var_pop", 3); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; /* Population variance is undefined when N is 0, so return NULL */ if (N == 0.0) PG_RETURN_NULL(); numerator = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true); /* Watch out for roundoff error producing a negative numerator */ if (numerator <= 0.0) PG_RETURN_FLOAT8(0.0); PG_RETURN_FLOAT8(numerator / (N * N)); }
Datum float8_var_samp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1962 of file float.c.
References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.
{ ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); float8 *transvalues; float8 N, sumX, sumX2, numerator; transvalues = check_float8_array(transarray, "float8_var_samp", 3); N = transvalues[0]; sumX = transvalues[1]; sumX2 = transvalues[2]; /* Sample variance is undefined when N is 0 or 1, so return NULL */ if (N <= 1.0) PG_RETURN_NULL(); numerator = N * sumX2 - sumX * sumX; CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true); /* Watch out for roundoff error producing a negative numerator */ if (numerator <= 0.0) PG_RETURN_FLOAT8(0.0); PG_RETURN_FLOAT8(numerator / (N * (N - 1.0))); }
Datum float8abs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 664 of file float.c.
References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); PG_RETURN_FLOAT8(fabs(arg1)); }
Datum float8div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 844 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; if (arg2 == 0.0) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); result = arg1 / arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum float8eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1016 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) == 0); }
Datum float8ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1061 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) >= 0); }
Datum float8gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1052 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) > 0); }
Datum float8in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 391 of file float.c.
References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_infinity(), get_float8_nan(), isinf(), PG_GETARG_CSTRING, PG_RETURN_FLOAT8, pg_strncasecmp(), and val.
Referenced by numeric_float8().
{ char *num = PG_GETARG_CSTRING(0); char *orig_num; double val; char *endptr; /* * endptr points to the first character _after_ the sequence we recognized * as a valid floating point number. orig_num points to the original input * string. */ orig_num = num; /* * Check for an empty-string input to begin with, to avoid the vagaries of * strtod() on different platforms. */ if (*num == '\0') ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type double precision: \"%s\"", orig_num))); /* skip leading whitespace */ while (*num != '\0' && isspace((unsigned char) *num)) num++; errno = 0; val = strtod(num, &endptr); /* did we not see anything that looks like a double? */ if (endptr == num || errno != 0) { int save_errno = errno; /* * C99 requires that strtod() accept NaN and [-]Infinity, but not all * platforms support that yet (and some accept them but set ERANGE * anyway...) Therefore, we check for these inputs ourselves. */ if (pg_strncasecmp(num, "NaN", 3) == 0) { val = get_float8_nan(); endptr = num + 3; } else if (pg_strncasecmp(num, "Infinity", 8) == 0) { val = get_float8_infinity(); endptr = num + 8; } else if (pg_strncasecmp(num, "-Infinity", 9) == 0) { val = -get_float8_infinity(); endptr = num + 9; } else if (save_errno == ERANGE) { /* * Some platforms return ERANGE for denormalized numbers (those * that are not zero, but are too close to zero to have full * precision). We'd prefer not to throw error for that, so try to * detect whether it's a "real" out-of-range condition by checking * to see if the result is zero or huge. */ if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("\"%s\" is out of range for type double precision", orig_num))); } else ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type double precision: \"%s\"", orig_num))); } #ifdef HAVE_BUGGY_SOLARIS_STRTOD else { /* * Many versions of Solaris have a bug wherein strtod sets endptr to * point one byte beyond the end of the string when given "inf" or * "infinity". */ if (endptr != num && endptr[-1] == '\0') endptr--; } #endif /* HAVE_BUGGY_SOLARIS_STRTOD */ #ifdef HAVE_BUGGY_IRIX_STRTOD /* * In some IRIX versions, strtod() recognizes only "inf", so if the input * is "infinity" we have to skip over "inity". Also, it may return * positive infinity for "-inf". */ if (isinf(val)) { if (pg_strncasecmp(num, "Infinity", 8) == 0) { val = get_float8_infinity(); endptr = num + 8; } else if (pg_strncasecmp(num, "-Infinity", 9) == 0) { val = -get_float8_infinity(); endptr = num + 9; } else if (pg_strncasecmp(num, "-inf", 4) == 0) { val = -get_float8_infinity(); endptr = num + 4; } } #endif /* HAVE_BUGGY_IRIX_STRTOD */ /* skip trailing whitespace */ while (*endptr != '\0' && isspace((unsigned char) *endptr)) endptr++; /* if there is any junk left at the end of the string, bail out */ if (*endptr != '\0') ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type double precision: \"%s\"", orig_num))); CHECKFLOATVAL(val, true, true); PG_RETURN_FLOAT8(val); }
Datum float8larger | ( | PG_FUNCTION_ARGS | ) |
Definition at line 694 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; if (float8_cmp_internal(arg1, arg2) > 0) result = arg1; else result = arg2; PG_RETURN_FLOAT8(result); }
Datum float8le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1043 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) <= 0); }
Datum float8lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1034 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) < 0); }
Datum float8mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 817 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; result = arg1 - arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT8(result); }
Datum float8mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 830 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT8(result); }
Datum float8ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1025 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) != 0); }
Datum float8out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 529 of file float.c.
References ascii(), extra_float_digits, is_infinite(), MAXDOUBLEWIDTH, palloc(), PG_GETARG_FLOAT8, PG_RETURN_CSTRING, and snprintf().
{ float8 num = PG_GETARG_FLOAT8(0); char *ascii = (char *) palloc(MAXDOUBLEWIDTH + 1); if (isnan(num)) PG_RETURN_CSTRING(strcpy(ascii, "NaN")); switch (is_infinite(num)) { case 1: strcpy(ascii, "Infinity"); break; case -1: strcpy(ascii, "-Infinity"); break; default: { int ndig = DBL_DIG + extra_float_digits; if (ndig < 1) ndig = 1; snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num); } } PG_RETURN_CSTRING(ascii); }
Datum float8pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 804 of file float.c.
References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; result = arg1 + arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT8(result); }
Datum float8recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 563 of file float.c.
References buf, PG_GETARG_POINTER, PG_RETURN_FLOAT8, and pq_getmsgfloat8().
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); PG_RETURN_FLOAT8(pq_getmsgfloat8(buf)); }
Datum float8send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 574 of file float.c.
References buf, PG_GETARG_FLOAT8, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendfloat8().
{ float8 num = PG_GETARG_FLOAT8(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendfloat8(&buf, num); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum float8smaller | ( | PG_FUNCTION_ARGS | ) |
Definition at line 708 of file float.c.
References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 arg2 = PG_GETARG_FLOAT8(1); float8 result; if (float8_cmp_internal(arg1, arg2) < 0) result = arg1; else result = arg2; PG_RETURN_FLOAT8(result); }
Datum float8um | ( | PG_FUNCTION_ARGS | ) |
Definition at line 676 of file float.c.
References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; result = -arg1; PG_RETURN_FLOAT8(result); }
Datum float8up | ( | PG_FUNCTION_ARGS | ) |
Definition at line 686 of file float.c.
References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg = PG_GETARG_FLOAT8(0); PG_RETURN_FLOAT8(arg); }
Datum ftod | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1127 of file float.c.
References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT8.
{ float4 num = PG_GETARG_FLOAT4(0); PG_RETURN_FLOAT8((float8) num); }
Datum ftoi2 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1231 of file float.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_FLOAT4, PG_RETURN_INT16, and rint().
{ float4 num = PG_GETARG_FLOAT4(0); if (num < SHRT_MIN || num > SHRT_MAX || isnan(num)) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("smallint out of range"))); PG_RETURN_INT16((int16) rint(num)); }
Datum ftoi4 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1214 of file float.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_FLOAT4, PG_RETURN_INT32, and rint().
{ float4 num = PG_GETARG_FLOAT4(0); if (num < INT_MIN || num > INT_MAX || isnan(num)) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("integer out of range"))); PG_RETURN_INT32((int32) rint(num)); }
float get_float4_infinity | ( | void | ) |
Definition at line 115 of file float.c.
Referenced by float4in(), gistpenalty(), leftmostvalue_float4(), and range_gist_penalty().
{ #ifdef INFINITY /* C99 standard way */ return (float) INFINITY; #else /* * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the * largest normal double. We assume forcing an overflow will get us a * true infinity. */ return (float) (HUGE_VAL * HUGE_VAL); #endif }
float get_float4_nan | ( | void | ) |
Definition at line 145 of file float.c.
Referenced by float4in(), and numeric_float4().
{ #ifdef NAN /* C99 standard way */ return (float) NAN; #else /* Assume we can get a NAN via zero divide */ return (float) (0.0 / 0.0); #endif }
double get_float8_infinity | ( | void | ) |
Definition at line 98 of file float.c.
Referenced by check_special_value(), compute_range_stats(), dexp(), dpow(), float8in(), gbt_ts_dist(), get_distance(), gistindex_keytest(), leftmostvalue_float8(), and pg_hypot().
{ #ifdef INFINITY /* C99 standard way */ return (double) INFINITY; #else /* * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the * largest normal double. We assume forcing an overflow will get us a * true infinity. */ return (double) (HUGE_VAL * HUGE_VAL); #endif }
double get_float8_nan | ( | void | ) |
Definition at line 132 of file float.c.
Referenced by check_special_value(), float8in(), numeric_float8(), numeric_float8_no_overflow(), and pg_hypot().
{ /* (double) NAN doesn't work on some NetBSD/MIPS releases */ #if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__)) /* C99 standard way */ return (double) NAN; #else /* Assume we can get a NAN via zero divide */ return (double) (0.0 / 0.0); #endif }
Datum i2tod | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1202 of file float.c.
References PG_GETARG_INT16, and PG_RETURN_FLOAT8.
{ int16 num = PG_GETARG_INT16(0); PG_RETURN_FLOAT8((float8) num); }
Datum i2tof | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1260 of file float.c.
References PG_GETARG_INT16, and PG_RETURN_FLOAT4.
{ int16 num = PG_GETARG_INT16(0); PG_RETURN_FLOAT4((float4) num); }
Datum i4tod | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1190 of file float.c.
References PG_GETARG_INT32, and PG_RETURN_FLOAT8.
{ int32 num = PG_GETARG_INT32(0); PG_RETURN_FLOAT8((float8) num); }
Datum i4tof | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1248 of file float.c.
References PG_GETARG_INT32, and PG_RETURN_FLOAT4.
{ int32 num = PG_GETARG_INT32(0); PG_RETURN_FLOAT4((float4) num); }
int is_infinite | ( | double | val | ) |
Definition at line 165 of file float.c.
References isinf().
Referenced by calc_length_hist_frac(), float4_to_char(), float4out(), float8_to_char(), float8out(), and get_len_position().
Datum radians | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1723 of file float.c.
References CHECKFLOATVAL, isinf(), M_PI, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.
{ float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; result = arg1 * (M_PI / 180.0); CHECKFLOATVAL(result, isinf(arg1), arg1 == 0); PG_RETURN_FLOAT8(result); }
Datum setseed | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1754 of file float.c.
References elog, ERROR, MAX_RANDOM_VALUE, PG_GETARG_FLOAT8, PG_RETURN_VOID, and srandom().
Referenced by assign_random_seed().
{ float8 seed = PG_GETARG_FLOAT8(0); int iseed; if (seed < -1 || seed > 1) elog(ERROR, "setseed parameter %f out of range [-1,1]", seed); iseed = (int) (seed * MAX_RANDOM_VALUE); srandom((unsigned int) iseed); PG_RETURN_VOID(); }
Datum width_bucket_float8 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2737 of file float.c.
References ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, PG_GETARG_INT32, and PG_RETURN_INT32.
{ float8 operand = PG_GETARG_FLOAT8(0); float8 bound1 = PG_GETARG_FLOAT8(1); float8 bound2 = PG_GETARG_FLOAT8(2); int32 count = PG_GETARG_INT32(3); int32 result; if (count <= 0.0) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), errmsg("count must be greater than zero"))); if (isnan(operand) || isnan(bound1) || isnan(bound2)) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), errmsg("operand, lower bound, and upper bound cannot be NaN"))); /* Note that we allow "operand" to be infinite */ if (isinf(bound1) || isinf(bound2)) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), errmsg("lower and upper bounds must be finite"))); if (bound1 < bound2) { if (operand < bound1) result = 0; else if (operand >= bound2) { result = count + 1; /* check for overflow */ if (result < count) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("integer out of range"))); } else result = ((float8) count * (operand - bound1) / (bound2 - bound1)) + 1; } else if (bound1 > bound2) { if (operand > bound1) result = 0; else if (operand <= bound2) { result = count + 1; /* check for overflow */ if (result < count) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("integer out of range"))); } else result = ((float8) count * (bound1 - operand) / (bound1 - bound2)) + 1; } else { ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), errmsg("lower bound cannot equal upper bound"))); result = 0; /* keep the compiler quiet */ } PG_RETURN_INT32(result); }
int extra_float_digits = 0 |
Definition at line 68 of file float.c.
Referenced by cube_out(), float4out(), float8out(), pair_encode(), set_transmission_modes(), and single_encode().