PostgreSQL Source Code  git master
float.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <limits.h>
#include "catalog/pg_type.h"
#include "common/int.h"
#include "libpq/pqformat.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/sortsupport.h"
Include dependency graph for float.c:

Go to the source code of this file.

Macros

#define M_PI   3.14159265358979323846
 
#define RADIANS_PER_DEGREE   0.0174532925199432957692
 
#define MAXFLOATWIDTH   64
 
#define MAXDOUBLEWIDTH   128
 
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
 
#define cbrt   my_cbrt
 
#define INIT_DEGREE_CONSTANTS()
 

Functions

static double sind_q1 (double x)
 
static double cosd_q1 (double x)
 
static void init_degree_constants (void)
 
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)
 
double float8in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string)
 
Datum float8out (PG_FUNCTION_ARGS)
 
char * float8out_internal (double num)
 
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)
 
int float4_cmp_internal (float4 a, float4 b)
 
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)
 
int float8_cmp_internal (float8 a, float8 b)
 
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)
 
static double asind_q1 (double x)
 
static double acosd_q1 (double x)
 
Datum dacosd (PG_FUNCTION_ARGS)
 
Datum dasind (PG_FUNCTION_ARGS)
 
Datum datand (PG_FUNCTION_ARGS)
 
Datum datan2d (PG_FUNCTION_ARGS)
 
static double sind_0_to_30 (double x)
 
static double cosd_0_to_60 (double x)
 
Datum dcosd (PG_FUNCTION_ARGS)
 
Datum dcotd (PG_FUNCTION_ARGS)
 
Datum dsind (PG_FUNCTION_ARGS)
 
Datum dtand (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 float8check_float8_array (ArrayType *transarray, const char *caller, int n)
 
Datum float8_combine (PG_FUNCTION_ARGS)
 
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_combine (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
 
static bool degree_consts_set = false
 
static float8 sin_30 = 0
 
static float8 one_minus_cos_60 = 0
 
static float8 asin_0_5 = 0
 
static float8 acos_0_5 = 0
 
static float8 atan_1_0 = 0
 
static float8 tan_45 = 0
 
static float8 cot_45 = 0
 
float8 degree_c_thirty = 30.0
 
float8 degree_c_forty_five = 45.0
 
float8 degree_c_sixty = 60.0
 
float8 degree_c_one_half = 0.5
 
float8 degree_c_one = 1.0
 

Macro Definition Documentation

◆ cbrt

#define cbrt   my_cbrt

Definition at line 107 of file float.c.

Referenced by dcbrt().

◆ CHECKFLOATVAL

#define CHECKFLOATVAL (   val,
  inf_is_valid,
  zero_is_valid 
)
Value:
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)
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
int isinf(double x)
int errmsg(const char *fmt,...)
Definition: elog.c:797
long val
Definition: informix.c:689

Definition at line 54 of file float.c.

Referenced by dacos(), dacosd(), dasin(), dasind(), datan(), datan2(), datan2d(), datand(), dcbrt(), dcos(), dcosd(), dcot(), dcotd(), degrees(), dexp(), dlog1(), dlog10(), dpow(), dsin(), dsind(), dsqrt(), dtan(), dtand(), dtof(), float48div(), float48mi(), float48mul(), float48pl(), float4_accum(), float4div(), float4in(), float4mi(), float4mul(), float4pl(), float84div(), float84mi(), float84mul(), float84pl(), float8_accum(), float8_combine(), float8_corr(), float8_covar_pop(), float8_covar_samp(), float8_regr_accum(), float8_regr_combine(), 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(), float8mi(), float8mul(), float8pl(), and radians().

◆ INIT_DEGREE_CONSTANTS

#define INIT_DEGREE_CONSTANTS ( )
Value:
do { \
init_degree_constants(); \
} while(0)
static bool degree_consts_set
Definition: float.c:72

Definition at line 1859 of file float.c.

Referenced by dacosd(), dasind(), datan2d(), datand(), dcosd(), dcotd(), dsind(), and dtand().

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 32 of file float.c.

Referenced by dpi().

◆ MAXDOUBLEWIDTH

#define MAXDOUBLEWIDTH   128

Definition at line 49 of file float.c.

Referenced by float8out_internal().

◆ MAXFLOATWIDTH

#define MAXFLOATWIDTH   64

Definition at line 48 of file float.c.

Referenced by float4out().

◆ RADIANS_PER_DEGREE

#define RADIANS_PER_DEGREE   0.0174532925199432957692

Definition at line 36 of file float.c.

Referenced by cosd_0_to_60(), degrees(), init_degree_constants(), radians(), and sind_0_to_30().

Function Documentation

◆ acosd_q1()

static double acosd_q1 ( double  x)
static

Definition at line 1909 of file float.c.

References acos_0_5, and asin_0_5.

Referenced by dacosd().

1910 {
1911  /*
1912  * Stitch together inverse sine and cosine functions for the ranges [0,
1913  * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
1914  * exactly 60 for x=0.5, so the result is a continuous monotonic function
1915  * over the full range.
1916  */
1917  if (x <= 0.5)
1918  {
1919  volatile float8 asin_x = asin(x);
1920 
1921  return 90.0 - (asin_x / asin_0_5) * 30.0;
1922  }
1923  else
1924  {
1925  volatile float8 acos_x = acos(x);
1926 
1927  return (acos_x / acos_0_5) * 60.0;
1928  }
1929 }
static float8 acos_0_5
Definition: float.c:76
double float8
Definition: c.h:439
static float8 asin_0_5
Definition: float.c:75

◆ asind_q1()

static double asind_q1 ( double  x)
static

Definition at line 1876 of file float.c.

References acos_0_5, and asin_0_5.

Referenced by dacosd(), and dasind().

1877 {
1878  /*
1879  * Stitch together inverse sine and cosine functions for the ranges [0,
1880  * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
1881  * exactly 30 for x=0.5, so the result is a continuous monotonic function
1882  * over the full range.
1883  */
1884  if (x <= 0.5)
1885  {
1886  volatile float8 asin_x = asin(x);
1887 
1888  return (asin_x / asin_0_5) * 30.0;
1889  }
1890  else
1891  {
1892  volatile float8 acos_x = acos(x);
1893 
1894  return 90.0 - (acos_x / acos_0_5) * 60.0;
1895  }
1896 }
static float8 acos_0_5
Definition: float.c:76
double float8
Definition: c.h:439
static float8 asin_0_5
Definition: float.c:75

◆ btfloat48cmp()

Datum btfloat48cmp ( PG_FUNCTION_ARGS  )

Definition at line 1164 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_INT32.

1165 {
1166  float4 arg1 = PG_GETARG_FLOAT4(0);
1167  float8 arg2 = PG_GETARG_FLOAT8(1);
1168 
1169  /* widen float4 to float8 and then compare */
1170  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1171 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ btfloat4cmp()

Datum btfloat4cmp ( PG_FUNCTION_ARGS  )

Definition at line 1023 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_INT32.

Referenced by leftmostvalue_float4().

1024 {
1025  float4 arg1 = PG_GETARG_FLOAT4(0);
1026  float4 arg2 = PG_GETARG_FLOAT4(1);
1027 
1028  PG_RETURN_INT32(float4_cmp_internal(arg1, arg2));
1029 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ btfloat4fastcmp()

static int btfloat4fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 1032 of file float.c.

References DatumGetFloat4, and float4_cmp_internal().

Referenced by btfloat4sortsupport().

1033 {
1034  float4 arg1 = DatumGetFloat4(x);
1035  float4 arg2 = DatumGetFloat4(y);
1036 
1037  return float4_cmp_internal(arg1, arg2);
1038 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
float float4
Definition: c.h:438
#define DatumGetFloat4(X)
Definition: postgres.h:686

◆ btfloat4sortsupport()

Datum btfloat4sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 1041 of file float.c.

References btfloat4fastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

1042 {
1044 
1045  ssup->comparator = btfloat4fastcmp;
1046  PG_RETURN_VOID();
1047 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
#define PG_RETURN_VOID()
Definition: fmgr.h:309
static int btfloat4fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: float.c:1032

◆ btfloat84cmp()

Datum btfloat84cmp ( PG_FUNCTION_ARGS  )

Definition at line 1174 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_INT32.

1175 {
1176  float8 arg1 = PG_GETARG_FLOAT8(0);
1177  float4 arg2 = PG_GETARG_FLOAT4(1);
1178 
1179  /* widen float4 to float8 and then compare */
1180  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1181 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ btfloat8cmp()

Datum btfloat8cmp ( PG_FUNCTION_ARGS  )

Definition at line 1137 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_INT32.

Referenced by leftmostvalue_float8().

1138 {
1139  float8 arg1 = PG_GETARG_FLOAT8(0);
1140  float8 arg2 = PG_GETARG_FLOAT8(1);
1141 
1142  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1143 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439

◆ btfloat8fastcmp()

static int btfloat8fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 1146 of file float.c.

References DatumGetFloat8, and float8_cmp_internal().

Referenced by btfloat8sortsupport().

1147 {
1148  float8 arg1 = DatumGetFloat8(x);
1149  float8 arg2 = DatumGetFloat8(y);
1150 
1151  return float8_cmp_internal(arg1, arg2);
1152 }
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define DatumGetFloat8(X)
Definition: postgres.h:734

◆ btfloat8sortsupport()

Datum btfloat8sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 1155 of file float.c.

References btfloat8fastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

1156 {
1158 
1159  ssup->comparator = btfloat8fastcmp;
1160  PG_RETURN_VOID();
1161 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static int btfloat8fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: float.c:1146
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
#define PG_RETURN_VOID()
Definition: fmgr.h:309

◆ cbrt()

static double cbrt ( double  x)
static

Definition at line 3590 of file float.c.

3591 {
3592  int isneg = (x < 0.0);
3593  double absx = fabs(x);
3594  double tmpres = pow(absx, (double) 1.0 / (double) 3.0);
3595 
3596  /*
3597  * The result is somewhat inaccurate --- not really pow()'s fault, as the
3598  * exponent it's handed contains roundoff error. We can improve the
3599  * accuracy by doing one iteration of Newton's formula. Beware of zero
3600  * input however.
3601  */
3602  if (tmpres > 0.0)
3603  tmpres -= (tmpres - absx / (tmpres * tmpres)) / (double) 3.0;
3604 
3605  return isneg ? -tmpres : tmpres;
3606 }

◆ check_float8_array()

static float8* check_float8_array ( ArrayType transarray,
const char *  caller,
int  n 
)
static

Definition at line 2471 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_combine(), float8_corr(), float8_covar_pop(), float8_covar_samp(), float8_regr_accum(), float8_regr_avgx(), float8_regr_avgy(), float8_regr_combine(), 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().

2472 {
2473  /*
2474  * We expect the input to be an N-element float array; verify that. We
2475  * don't need to use deconstruct_array() since the array data is just
2476  * going to look like a C array of N float8 values.
2477  */
2478  if (ARR_NDIM(transarray) != 1 ||
2479  ARR_DIMS(transarray)[0] != n ||
2480  ARR_HASNULL(transarray) ||
2481  ARR_ELEMTYPE(transarray) != FLOAT8OID)
2482  elog(ERROR, "%s: expected %d-element float8 array", caller, n);
2483  return (float8 *) ARR_DATA_PTR(transarray);
2484 }
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
#define ARR_DIMS(a)
Definition: array.h:279
#define ARR_DATA_PTR(a)
Definition: array.h:307
#define ARR_HASNULL(a)
Definition: array.h:276
#define FLOAT8OID
Definition: pg_type.h:419
#define ARR_NDIM(a)
Definition: array.h:275
#define elog
Definition: elog.h:219
#define ARR_ELEMTYPE(a)
Definition: array.h:277

◆ cosd_0_to_60()

static double cosd_0_to_60 ( double  x)
static

Definition at line 2086 of file float.c.

References one_minus_cos_60, and RADIANS_PER_DEGREE.

Referenced by cosd_q1(), and sind_q1().

2087 {
2088  volatile float8 one_minus_cos_x = 1.0 - cos(x * RADIANS_PER_DEGREE);
2089 
2090  return 1.0 - (one_minus_cos_x / one_minus_cos_60) / 2.0;
2091 }
double float8
Definition: c.h:439
#define RADIANS_PER_DEGREE
Definition: float.c:36
static float8 one_minus_cos_60
Definition: float.c:74

◆ cosd_q1()

static double cosd_q1 ( double  x)
static

Definition at line 2119 of file float.c.

References cosd_0_to_60(), and sind_0_to_30().

Referenced by dcosd(), dcotd(), dtand(), and init_degree_constants().

2120 {
2121  /*
2122  * Stitch together the sine and cosine functions for the ranges [0, 60]
2123  * and (60, 90]. These guarantee to return exact answers at their
2124  * endpoints, so the overall result is a continuous monotonic function
2125  * that gives exact results when x = 0, 60 and 90 degrees.
2126  */
2127  if (x <= 60.0)
2128  return cosd_0_to_60(x);
2129  else
2130  return sind_0_to_30(90.0 - x);
2131 }
static double cosd_0_to_60(double x)
Definition: float.c:2086
static double sind_0_to_30(double x)
Definition: float.c:2072

◆ dacos()

Datum dacos ( PG_FUNCTION_ARGS  )

Definition at line 1590 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1591 {
1592  float8 arg1 = PG_GETARG_FLOAT8(0);
1593  float8 result;
1594 
1595  /* Per the POSIX spec, return NaN if the input is NaN */
1596  if (isnan(arg1))
1598 
1599  /*
1600  * The principal branch of the inverse cosine function maps values in the
1601  * range [-1, 1] to values in the range [0, Pi], so we should reject any
1602  * inputs outside that range and the result will always be finite.
1603  */
1604  if (arg1 < -1.0 || arg1 > 1.0)
1605  ereport(ERROR,
1606  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1607  errmsg("input is out of range")));
1608 
1609  result = acos(arg1);
1610 
1611  CHECKFLOATVAL(result, false, true);
1612  PG_RETURN_FLOAT8(result);
1613 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dacosd()

Datum dacosd ( PG_FUNCTION_ARGS  )

Definition at line 1936 of file float.c.

References acosd_q1(), asind_q1(), CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), INIT_DEGREE_CONSTANTS, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1937 {
1938  float8 arg1 = PG_GETARG_FLOAT8(0);
1939  float8 result;
1940 
1941  /* Per the POSIX spec, return NaN if the input is NaN */
1942  if (isnan(arg1))
1944 
1946 
1947  /*
1948  * The principal branch of the inverse cosine function maps values in the
1949  * range [-1, 1] to values in the range [0, 180], so we should reject any
1950  * inputs outside that range and the result will always be finite.
1951  */
1952  if (arg1 < -1.0 || arg1 > 1.0)
1953  ereport(ERROR,
1954  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1955  errmsg("input is out of range")));
1956 
1957  if (arg1 >= 0.0)
1958  result = acosd_q1(arg1);
1959  else
1960  result = 90.0 + asind_q1(-arg1);
1961 
1962  CHECKFLOATVAL(result, false, true);
1963  PG_RETURN_FLOAT8(result);
1964 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
static double asind_q1(double x)
Definition: float.c:1876
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
static double acosd_q1(double x)
Definition: float.c:1909
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dasin()

Datum dasin ( PG_FUNCTION_ARGS  )

Definition at line 1620 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1621 {
1622  float8 arg1 = PG_GETARG_FLOAT8(0);
1623  float8 result;
1624 
1625  /* Per the POSIX spec, return NaN if the input is NaN */
1626  if (isnan(arg1))
1628 
1629  /*
1630  * The principal branch of the inverse sine function maps values in the
1631  * range [-1, 1] to values in the range [-Pi/2, Pi/2], so we should reject
1632  * any inputs outside that range and the result will always be finite.
1633  */
1634  if (arg1 < -1.0 || arg1 > 1.0)
1635  ereport(ERROR,
1636  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1637  errmsg("input is out of range")));
1638 
1639  result = asin(arg1);
1640 
1641  CHECKFLOATVAL(result, false, true);
1642  PG_RETURN_FLOAT8(result);
1643 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dasind()

Datum dasind ( PG_FUNCTION_ARGS  )

Definition at line 1971 of file float.c.

References asind_q1(), CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), INIT_DEGREE_CONSTANTS, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1972 {
1973  float8 arg1 = PG_GETARG_FLOAT8(0);
1974  float8 result;
1975 
1976  /* Per the POSIX spec, return NaN if the input is NaN */
1977  if (isnan(arg1))
1979 
1981 
1982  /*
1983  * The principal branch of the inverse sine function maps values in the
1984  * range [-1, 1] to values in the range [-90, 90], so we should reject any
1985  * inputs outside that range and the result will always be finite.
1986  */
1987  if (arg1 < -1.0 || arg1 > 1.0)
1988  ereport(ERROR,
1989  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1990  errmsg("input is out of range")));
1991 
1992  if (arg1 >= 0.0)
1993  result = asind_q1(arg1);
1994  else
1995  result = -asind_q1(-arg1);
1996 
1997  CHECKFLOATVAL(result, false, true);
1998  PG_RETURN_FLOAT8(result);
1999 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
static double asind_q1(double x)
Definition: float.c:1876
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ datan()

Datum datan ( PG_FUNCTION_ARGS  )

Definition at line 1650 of file float.c.

References CHECKFLOATVAL, get_float8_nan(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1651 {
1652  float8 arg1 = PG_GETARG_FLOAT8(0);
1653  float8 result;
1654 
1655  /* Per the POSIX spec, return NaN if the input is NaN */
1656  if (isnan(arg1))
1658 
1659  /*
1660  * The principal branch of the inverse tangent function maps all inputs to
1661  * values in the range [-Pi/2, Pi/2], so the result should always be
1662  * finite, even if the input is infinite.
1663  */
1664  result = atan(arg1);
1665 
1666  CHECKFLOATVAL(result, false, true);
1667  PG_RETURN_FLOAT8(result);
1668 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ datan2()

Datum datan2 ( PG_FUNCTION_ARGS  )

Definition at line 1675 of file float.c.

References CHECKFLOATVAL, get_float8_nan(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1676 {
1677  float8 arg1 = PG_GETARG_FLOAT8(0);
1678  float8 arg2 = PG_GETARG_FLOAT8(1);
1679  float8 result;
1680 
1681  /* Per the POSIX spec, return NaN if either input is NaN */
1682  if (isnan(arg1) || isnan(arg2))
1684 
1685  /*
1686  * atan2 maps all inputs to values in the range [-Pi, Pi], so the result
1687  * should always be finite, even if the inputs are infinite.
1688  */
1689  result = atan2(arg1, arg2);
1690 
1691  CHECKFLOATVAL(result, false, true);
1692  PG_RETURN_FLOAT8(result);
1693 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ datan2d()

Datum datan2d ( PG_FUNCTION_ARGS  )

Definition at line 2036 of file float.c.

References atan_1_0, CHECKFLOATVAL, get_float8_nan(), INIT_DEGREE_CONSTANTS, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

2037 {
2038  float8 arg1 = PG_GETARG_FLOAT8(0);
2039  float8 arg2 = PG_GETARG_FLOAT8(1);
2040  float8 result;
2041  volatile float8 atan2_arg1_arg2;
2042 
2043  /* Per the POSIX spec, return NaN if either input is NaN */
2044  if (isnan(arg1) || isnan(arg2))
2046 
2048 
2049  /*
2050  * atan2d maps all inputs to values in the range [-180, 180], so the
2051  * result should always be finite, even if the inputs are infinite.
2052  *
2053  * Note: this coding assumes that atan(1.0) is a suitable scaling constant
2054  * to get an exact result from atan2(). This might well fail on us at
2055  * some point, requiring us to decide exactly what inputs we think we're
2056  * going to guarantee an exact result for.
2057  */
2058  atan2_arg1_arg2 = atan2(arg1, arg2);
2059  result = (atan2_arg1_arg2 / atan_1_0) * 45.0;
2060 
2061  CHECKFLOATVAL(result, false, true);
2062  PG_RETURN_FLOAT8(result);
2063 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
static float8 atan_1_0
Definition: float.c:77
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ datand()

Datum datand ( PG_FUNCTION_ARGS  )

Definition at line 2006 of file float.c.

References atan_1_0, CHECKFLOATVAL, get_float8_nan(), INIT_DEGREE_CONSTANTS, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

2007 {
2008  float8 arg1 = PG_GETARG_FLOAT8(0);
2009  float8 result;
2010  volatile float8 atan_arg1;
2011 
2012  /* Per the POSIX spec, return NaN if the input is NaN */
2013  if (isnan(arg1))
2015 
2017 
2018  /*
2019  * The principal branch of the inverse tangent function maps all inputs to
2020  * values in the range [-90, 90], so the result should always be finite,
2021  * even if the input is infinite. Additionally, we take care to ensure
2022  * than when arg1 is 1, the result is exactly 45.
2023  */
2024  atan_arg1 = atan(arg1);
2025  result = (atan_arg1 / atan_1_0) * 45.0;
2026 
2027  CHECKFLOATVAL(result, false, true);
2028  PG_RETURN_FLOAT8(result);
2029 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
static float8 atan_1_0
Definition: float.c:77
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ dcbrt()

Datum dcbrt ( PG_FUNCTION_ARGS  )

Definition at line 1444 of file float.c.

References cbrt, CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1445 {
1446  float8 arg1 = PG_GETARG_FLOAT8(0);
1447  float8 result;
1448 
1449  result = cbrt(arg1);
1450  CHECKFLOATVAL(result, isinf(arg1), arg1 == 0);
1451  PG_RETURN_FLOAT8(result);
1452 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define cbrt
Definition: float.c:107
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ dceil()

Datum dceil ( PG_FUNCTION_ARGS  )

Definition at line 1357 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1358 {
1359  float8 arg1 = PG_GETARG_FLOAT8(0);
1360 
1361  PG_RETURN_FLOAT8(ceil(arg1));
1362 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439

◆ dcos()

Datum dcos ( PG_FUNCTION_ARGS  )

Definition at line 1700 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1701 {
1702  float8 arg1 = PG_GETARG_FLOAT8(0);
1703  float8 result;
1704 
1705  /* Per the POSIX spec, return NaN if the input is NaN */
1706  if (isnan(arg1))
1708 
1709  /*
1710  * cos() is periodic and so theoretically can work for all finite inputs,
1711  * but some implementations may choose to throw error if the input is so
1712  * large that there are no significant digits in the result. So we should
1713  * check for errors. POSIX allows an error to be reported either via
1714  * errno or via fetestexcept(), but currently we only support checking
1715  * errno. (fetestexcept() is rumored to report underflow unreasonably
1716  * early on some platforms, so it's not clear that believing it would be a
1717  * net improvement anyway.)
1718  *
1719  * For infinite inputs, POSIX specifies that the trigonometric functions
1720  * should return a domain error; but we won't notice that unless the
1721  * platform reports via errno, so also explicitly test for infinite
1722  * inputs.
1723  */
1724  errno = 0;
1725  result = cos(arg1);
1726  if (errno != 0 || isinf(arg1))
1727  ereport(ERROR,
1728  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1729  errmsg("input is out of range")));
1730 
1731  CHECKFLOATVAL(result, false, true);
1732  PG_RETURN_FLOAT8(result);
1733 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dcosd()

Datum dcosd ( PG_FUNCTION_ARGS  )

Definition at line 2138 of file float.c.

References CHECKFLOATVAL, cosd_q1(), ereport, errcode(), errmsg(), ERROR, get_float8_nan(), INIT_DEGREE_CONSTANTS, isinf(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and sign.

2139 {
2140  float8 arg1 = PG_GETARG_FLOAT8(0);
2141  float8 result;
2142  int sign = 1;
2143 
2144  /*
2145  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2146  * if the input is infinite.
2147  */
2148  if (isnan(arg1))
2150 
2151  if (isinf(arg1))
2152  ereport(ERROR,
2153  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2154  errmsg("input is out of range")));
2155 
2157 
2158  /* Reduce the range of the input to [0,90] degrees */
2159  arg1 = fmod(arg1, 360.0);
2160 
2161  if (arg1 < 0.0)
2162  {
2163  /* cosd(-x) = cosd(x) */
2164  arg1 = -arg1;
2165  }
2166 
2167  if (arg1 > 180.0)
2168  {
2169  /* cosd(360-x) = cosd(x) */
2170  arg1 = 360.0 - arg1;
2171  }
2172 
2173  if (arg1 > 90.0)
2174  {
2175  /* cosd(180-x) = -cosd(x) */
2176  arg1 = 180.0 - arg1;
2177  sign = -sign;
2178  }
2179 
2180  result = sign * cosd_q1(arg1);
2181 
2182  CHECKFLOATVAL(result, false, true);
2183  PG_RETURN_FLOAT8(result);
2184 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
char sign
Definition: informix.c:693
#define ereport(elevel, rest)
Definition: elog.h:122
static double cosd_q1(double x)
Definition: float.c:2119
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dcot()

Datum dcot ( PG_FUNCTION_ARGS  )

Definition at line 1740 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1741 {
1742  float8 arg1 = PG_GETARG_FLOAT8(0);
1743  float8 result;
1744 
1745  /* Per the POSIX spec, return NaN if the input is NaN */
1746  if (isnan(arg1))
1748 
1749  /* Be sure to throw an error if the input is infinite --- see dcos() */
1750  errno = 0;
1751  result = tan(arg1);
1752  if (errno != 0 || isinf(arg1))
1753  ereport(ERROR,
1754  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1755  errmsg("input is out of range")));
1756 
1757  result = 1.0 / result;
1758  CHECKFLOATVAL(result, true /* cot(0) == Inf */ , true);
1759  PG_RETURN_FLOAT8(result);
1760 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dcotd()

Datum dcotd ( PG_FUNCTION_ARGS  )

Definition at line 2191 of file float.c.

References CHECKFLOATVAL, cosd_q1(), cot_45, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), INIT_DEGREE_CONSTANTS, isinf(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, sign, and sind_q1().

2192 {
2193  float8 arg1 = PG_GETARG_FLOAT8(0);
2194  float8 result;
2195  volatile float8 cot_arg1;
2196  int sign = 1;
2197 
2198  /*
2199  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2200  * if the input is infinite.
2201  */
2202  if (isnan(arg1))
2204 
2205  if (isinf(arg1))
2206  ereport(ERROR,
2207  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2208  errmsg("input is out of range")));
2209 
2211 
2212  /* Reduce the range of the input to [0,90] degrees */
2213  arg1 = fmod(arg1, 360.0);
2214 
2215  if (arg1 < 0.0)
2216  {
2217  /* cotd(-x) = -cotd(x) */
2218  arg1 = -arg1;
2219  sign = -sign;
2220  }
2221 
2222  if (arg1 > 180.0)
2223  {
2224  /* cotd(360-x) = -cotd(x) */
2225  arg1 = 360.0 - arg1;
2226  sign = -sign;
2227  }
2228 
2229  if (arg1 > 90.0)
2230  {
2231  /* cotd(180-x) = -cotd(x) */
2232  arg1 = 180.0 - arg1;
2233  sign = -sign;
2234  }
2235 
2236  cot_arg1 = cosd_q1(arg1) / sind_q1(arg1);
2237  result = sign * (cot_arg1 / cot_45);
2238 
2239  /*
2240  * On some machines we get cotd(270) = minus zero, but this isn't always
2241  * true. For portability, and because the user constituency for this
2242  * function probably doesn't want minus zero, force it to plain zero.
2243  */
2244  if (result == 0.0)
2245  result = 0.0;
2246 
2247  CHECKFLOATVAL(result, true /* cotd(0) == Inf */ , true);
2248  PG_RETURN_FLOAT8(result);
2249 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
static float8 cot_45
Definition: float.c:79
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
static double sind_q1(double x)
Definition: float.c:2099
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
char sign
Definition: informix.c:693
#define ereport(elevel, rest)
Definition: elog.h:122
static double cosd_q1(double x)
Definition: float.c:2119
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ degrees()

Datum degrees ( PG_FUNCTION_ARGS  )

Definition at line 2375 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and RADIANS_PER_DEGREE.

2376 {
2377  float8 arg1 = PG_GETARG_FLOAT8(0);
2378  float8 result;
2379 
2380  result = arg1 / RADIANS_PER_DEGREE;
2381 
2382  CHECKFLOATVAL(result, isinf(arg1), arg1 == 0);
2383  PG_RETURN_FLOAT8(result);
2384 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define RADIANS_PER_DEGREE
Definition: float.c:36
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ dexp()

Datum dexp ( PG_FUNCTION_ARGS  )

Definition at line 1512 of file float.c.

References CHECKFLOATVAL, get_float8_infinity(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1513 {
1514  float8 arg1 = PG_GETARG_FLOAT8(0);
1515  float8 result;
1516 
1517  errno = 0;
1518  result = exp(arg1);
1519  if (errno == ERANGE && result != 0 && !isinf(result))
1520  result = get_float8_infinity();
1521 
1522  CHECKFLOATVAL(result, isinf(arg1), false);
1523  PG_RETURN_FLOAT8(result);
1524 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
double get_float8_infinity(void)
Definition: float.c:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ dfloor()

Datum dfloor ( PG_FUNCTION_ARGS  )

Definition at line 1369 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1370 {
1371  float8 arg1 = PG_GETARG_FLOAT8(0);
1372 
1373  PG_RETURN_FLOAT8(floor(arg1));
1374 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439

◆ dlog1()

Datum dlog1 ( PG_FUNCTION_ARGS  )

Definition at line 1531 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1532 {
1533  float8 arg1 = PG_GETARG_FLOAT8(0);
1534  float8 result;
1535 
1536  /*
1537  * Emit particular SQLSTATE error codes for ln(). This is required by the
1538  * SQL standard.
1539  */
1540  if (arg1 == 0.0)
1541  ereport(ERROR,
1542  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1543  errmsg("cannot take logarithm of zero")));
1544  if (arg1 < 0)
1545  ereport(ERROR,
1546  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1547  errmsg("cannot take logarithm of a negative number")));
1548 
1549  result = log(arg1);
1550 
1551  CHECKFLOATVAL(result, isinf(arg1), arg1 == 1);
1552  PG_RETURN_FLOAT8(result);
1553 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dlog10()

Datum dlog10 ( PG_FUNCTION_ARGS  )

Definition at line 1560 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1561 {
1562  float8 arg1 = PG_GETARG_FLOAT8(0);
1563  float8 result;
1564 
1565  /*
1566  * Emit particular SQLSTATE error codes for log(). The SQL spec doesn't
1567  * define log(), but it does define ln(), so it makes sense to emit the
1568  * same error code for an analogous error condition.
1569  */
1570  if (arg1 == 0.0)
1571  ereport(ERROR,
1572  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1573  errmsg("cannot take logarithm of zero")));
1574  if (arg1 < 0)
1575  ereport(ERROR,
1576  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1577  errmsg("cannot take logarithm of a negative number")));
1578 
1579  result = log10(arg1);
1580 
1581  CHECKFLOATVAL(result, isinf(arg1), arg1 == 1);
1582  PG_RETURN_FLOAT8(result);
1583 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dpi()

Definition at line 2391 of file float.c.

References M_PI, and PG_RETURN_FLOAT8.

2392 {
2394 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define M_PI
Definition: float.c:32

◆ dpow()

Datum dpow ( PG_FUNCTION_ARGS  )

Definition at line 1459 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_infinity(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1460 {
1461  float8 arg1 = PG_GETARG_FLOAT8(0);
1462  float8 arg2 = PG_GETARG_FLOAT8(1);
1463  float8 result;
1464 
1465  /*
1466  * The SQL spec requires that we emit a particular SQLSTATE error code for
1467  * certain error conditions. Specifically, we don't return a
1468  * divide-by-zero error code for 0 ^ -1.
1469  */
1470  if (arg1 == 0 && arg2 < 0)
1471  ereport(ERROR,
1472  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1473  errmsg("zero raised to a negative power is undefined")));
1474  if (arg1 < 0 && floor(arg2) != arg2)
1475  ereport(ERROR,
1476  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1477  errmsg("a negative number raised to a non-integer power yields a complex result")));
1478 
1479  /*
1480  * pow() sets errno only on some platforms, depending on whether it
1481  * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we try to avoid using
1482  * errno. However, some platform/CPU combinations return errno == EDOM
1483  * and result == Nan for negative arg1 and very large arg2 (they must be
1484  * using something different from our floor() test to decide it's
1485  * invalid). Other platforms (HPPA) return errno == ERANGE and a large
1486  * (HUGE_VAL) but finite result to signal overflow.
1487  */
1488  errno = 0;
1489  result = pow(arg1, arg2);
1490  if (errno == EDOM && isnan(result))
1491  {
1492  if ((fabs(arg1) > 1 && arg2 >= 0) || (fabs(arg1) < 1 && arg2 < 0))
1493  /* The sign of Inf is not significant in this case. */
1494  result = get_float8_infinity();
1495  else if (fabs(arg1) != 1)
1496  result = 0;
1497  else
1498  result = 1;
1499  }
1500  else if (errno == ERANGE && result != 0 && !isinf(result))
1501  result = get_float8_infinity();
1502 
1503  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
1504  PG_RETURN_FLOAT8(result);
1505 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
double get_float8_infinity(void)
Definition: float.c:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ drandom()

Datum drandom ( PG_FUNCTION_ARGS  )

Definition at line 2417 of file float.c.

References MAX_RANDOM_VALUE, PG_RETURN_FLOAT8, and random().

2418 {
2419  float8 result;
2420 
2421  /* result [0.0 - 1.0) */
2422  result = (double) random() / ((double) MAX_RANDOM_VALUE + 1);
2423 
2424  PG_RETURN_FLOAT8(result);
2425 }
long random(void)
Definition: random.c:22
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
#define MAX_RANDOM_VALUE

◆ dround()

Datum dround ( PG_FUNCTION_ARGS  )

Definition at line 1345 of file float.c.

References PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and rint().

1346 {
1347  float8 arg1 = PG_GETARG_FLOAT8(0);
1348 
1349  PG_RETURN_FLOAT8(rint(arg1));
1350 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
double rint(double x)
Definition: rint.c:22

◆ dsign()

Datum dsign ( PG_FUNCTION_ARGS  )

Definition at line 1382 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1383 {
1384  float8 arg1 = PG_GETARG_FLOAT8(0);
1385  float8 result;
1386 
1387  if (arg1 > 0)
1388  result = 1.0;
1389  else if (arg1 < 0)
1390  result = -1.0;
1391  else
1392  result = 0.0;
1393 
1394  PG_RETURN_FLOAT8(result);
1395 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439

◆ dsin()

Datum dsin ( PG_FUNCTION_ARGS  )

Definition at line 1767 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1768 {
1769  float8 arg1 = PG_GETARG_FLOAT8(0);
1770  float8 result;
1771 
1772  /* Per the POSIX spec, return NaN if the input is NaN */
1773  if (isnan(arg1))
1775 
1776  /* Be sure to throw an error if the input is infinite --- see dcos() */
1777  errno = 0;
1778  result = sin(arg1);
1779  if (errno != 0 || isinf(arg1))
1780  ereport(ERROR,
1781  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1782  errmsg("input is out of range")));
1783 
1784  CHECKFLOATVAL(result, false, true);
1785  PG_RETURN_FLOAT8(result);
1786 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dsind()

Datum dsind ( PG_FUNCTION_ARGS  )

Definition at line 2256 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), INIT_DEGREE_CONSTANTS, isinf(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, sign, and sind_q1().

2257 {
2258  float8 arg1 = PG_GETARG_FLOAT8(0);
2259  float8 result;
2260  int sign = 1;
2261 
2262  /*
2263  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2264  * if the input is infinite.
2265  */
2266  if (isnan(arg1))
2268 
2269  if (isinf(arg1))
2270  ereport(ERROR,
2271  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2272  errmsg("input is out of range")));
2273 
2275 
2276  /* Reduce the range of the input to [0,90] degrees */
2277  arg1 = fmod(arg1, 360.0);
2278 
2279  if (arg1 < 0.0)
2280  {
2281  /* sind(-x) = -sind(x) */
2282  arg1 = -arg1;
2283  sign = -sign;
2284  }
2285 
2286  if (arg1 > 180.0)
2287  {
2288  /* sind(360-x) = -sind(x) */
2289  arg1 = 360.0 - arg1;
2290  sign = -sign;
2291  }
2292 
2293  if (arg1 > 90.0)
2294  {
2295  /* sind(180-x) = sind(x) */
2296  arg1 = 180.0 - arg1;
2297  }
2298 
2299  result = sign * sind_q1(arg1);
2300 
2301  CHECKFLOATVAL(result, false, true);
2302  PG_RETURN_FLOAT8(result);
2303 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
static double sind_q1(double x)
Definition: float.c:2099
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
char sign
Definition: informix.c:693
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dsqrt()

Datum dsqrt ( PG_FUNCTION_ARGS  )

Definition at line 1423 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1424 {
1425  float8 arg1 = PG_GETARG_FLOAT8(0);
1426  float8 result;
1427 
1428  if (arg1 < 0)
1429  ereport(ERROR,
1430  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1431  errmsg("cannot take square root of a negative number")));
1432 
1433  result = sqrt(arg1);
1434 
1435  CHECKFLOATVAL(result, isinf(arg1), arg1 == 0);
1436  PG_RETURN_FLOAT8(result);
1437 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dtan()

Datum dtan ( PG_FUNCTION_ARGS  )

Definition at line 1793 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, get_float8_nan(), isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1794 {
1795  float8 arg1 = PG_GETARG_FLOAT8(0);
1796  float8 result;
1797 
1798  /* Per the POSIX spec, return NaN if the input is NaN */
1799  if (isnan(arg1))
1801 
1802  /* Be sure to throw an error if the input is infinite --- see dcos() */
1803  errno = 0;
1804  result = tan(arg1);
1805  if (errno != 0 || isinf(arg1))
1806  ereport(ERROR,
1807  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1808  errmsg("input is out of range")));
1809 
1810  CHECKFLOATVAL(result, true /* tan(pi/2) == Inf */ , true);
1811  PG_RETURN_FLOAT8(result);
1812 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dtand()

Datum dtand ( PG_FUNCTION_ARGS  )

Definition at line 2310 of file float.c.

References CHECKFLOATVAL, cosd_q1(), ereport, errcode(), errmsg(), ERROR, get_float8_nan(), INIT_DEGREE_CONSTANTS, isinf(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, sign, sind_q1(), and tan_45.

2311 {
2312  float8 arg1 = PG_GETARG_FLOAT8(0);
2313  float8 result;
2314  volatile float8 tan_arg1;
2315  int sign = 1;
2316 
2317  /*
2318  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2319  * if the input is infinite.
2320  */
2321  if (isnan(arg1))
2323 
2324  if (isinf(arg1))
2325  ereport(ERROR,
2326  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2327  errmsg("input is out of range")));
2328 
2330 
2331  /* Reduce the range of the input to [0,90] degrees */
2332  arg1 = fmod(arg1, 360.0);
2333 
2334  if (arg1 < 0.0)
2335  {
2336  /* tand(-x) = -tand(x) */
2337  arg1 = -arg1;
2338  sign = -sign;
2339  }
2340 
2341  if (arg1 > 180.0)
2342  {
2343  /* tand(360-x) = -tand(x) */
2344  arg1 = 360.0 - arg1;
2345  sign = -sign;
2346  }
2347 
2348  if (arg1 > 90.0)
2349  {
2350  /* tand(180-x) = -tand(x) */
2351  arg1 = 180.0 - arg1;
2352  sign = -sign;
2353  }
2354 
2355  tan_arg1 = sind_q1(arg1) / cosd_q1(arg1);
2356  result = sign * (tan_arg1 / tan_45);
2357 
2358  /*
2359  * On some machines we get tand(180) = minus zero, but this isn't always
2360  * true. For portability, and because the user constituency for this
2361  * function probably doesn't want minus zero, force it to plain zero.
2362  */
2363  if (result == 0.0)
2364  result = 0.0;
2365 
2366  CHECKFLOATVAL(result, true /* tand(90) == Inf */ , true);
2367  PG_RETURN_FLOAT8(result);
2368 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
double get_float8_nan(void)
Definition: float.c:167
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:1859
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
static double sind_q1(double x)
Definition: float.c:2099
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
char sign
Definition: informix.c:693
#define ereport(elevel, rest)
Definition: elog.h:122
static double cosd_q1(double x)
Definition: float.c:2119
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797
static float8 tan_45
Definition: float.c:78

◆ dtof()

Datum dtof ( PG_FUNCTION_ARGS  )

Definition at line 1206 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT4.

1207 {
1208  float8 num = PG_GETARG_FLOAT8(0);
1209 
1210  CHECKFLOATVAL((float4) num, isinf(num), num == 0);
1211 
1212  PG_RETURN_FLOAT4((float4) num);
1213 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
double float8
Definition: c.h:439
int isinf(double x)
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ dtoi2()

Datum dtoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1240 of file float.c.

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

1241 {
1242  float8 num = PG_GETARG_FLOAT8(0);
1243 
1244  if (num < SHRT_MIN || num > SHRT_MAX || isnan(num))
1245  ereport(ERROR,
1246  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1247  errmsg("smallint out of range")));
1248 
1249  PG_RETURN_INT16((int16) rint(num));
1250 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
signed short int16
Definition: c.h:293
#define PG_RETURN_INT16(x)
Definition: fmgr.h:316
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
double rint(double x)
Definition: rint.c:22
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dtoi4()

Datum dtoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1220 of file float.c.

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

1221 {
1222  float8 num = PG_GETARG_FLOAT8(0);
1223  int32 result;
1224 
1225  /* 'Inf' is handled by INT_MAX */
1226  if (num < INT_MIN || num > INT_MAX || isnan(num))
1227  ereport(ERROR,
1228  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1229  errmsg("integer out of range")));
1230 
1231  result = (int32) rint(num);
1232  PG_RETURN_INT32(result);
1233 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
double rint(double x)
Definition: rint.c:22
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dtrunc()

Datum dtrunc ( PG_FUNCTION_ARGS  )

Definition at line 1405 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1406 {
1407  float8 arg1 = PG_GETARG_FLOAT8(0);
1408  float8 result;
1409 
1410  if (arg1 >= 0)
1411  result = floor(arg1);
1412  else
1413  result = -floor(-arg1);
1414 
1415  PG_RETURN_FLOAT8(result);
1416 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439

◆ float48div()

Datum float48div ( PG_FUNCTION_ARGS  )

Definition at line 3307 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3308 {
3309  float4 arg1 = PG_GETARG_FLOAT4(0);
3310  float8 arg2 = PG_GETARG_FLOAT8(1);
3311  float8 result;
3312 
3313  if (arg2 == 0.0)
3314  ereport(ERROR,
3315  (errcode(ERRCODE_DIVISION_BY_ZERO),
3316  errmsg("division by zero")));
3317 
3318  result = arg1 / arg2;
3319  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
3320  PG_RETURN_FLOAT8(result);
3321 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ float48eq()

Datum float48eq ( PG_FUNCTION_ARGS  )

Definition at line 3397 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3398 {
3399  float4 arg1 = PG_GETARG_FLOAT4(0);
3400  float8 arg2 = PG_GETARG_FLOAT8(1);
3401 
3402  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) == 0);
3403 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float48ge()

Datum float48ge ( PG_FUNCTION_ARGS  )

Definition at line 3442 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3443 {
3444  float4 arg1 = PG_GETARG_FLOAT4(0);
3445  float8 arg2 = PG_GETARG_FLOAT8(1);
3446 
3447  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) >= 0);
3448 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float48gt()

Datum float48gt ( PG_FUNCTION_ARGS  )

Definition at line 3433 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3434 {
3435  float4 arg1 = PG_GETARG_FLOAT4(0);
3436  float8 arg2 = PG_GETARG_FLOAT8(1);
3437 
3438  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) > 0);
3439 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float48le()

Datum float48le ( PG_FUNCTION_ARGS  )

Definition at line 3424 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3425 {
3426  float4 arg1 = PG_GETARG_FLOAT4(0);
3427  float8 arg2 = PG_GETARG_FLOAT8(1);
3428 
3429  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) <= 0);
3430 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float48lt()

Datum float48lt ( PG_FUNCTION_ARGS  )

Definition at line 3415 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3416 {
3417  float4 arg1 = PG_GETARG_FLOAT4(0);
3418  float8 arg2 = PG_GETARG_FLOAT8(1);
3419 
3420  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) < 0);
3421 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float48mi()

Datum float48mi ( PG_FUNCTION_ARGS  )

Definition at line 3282 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3283 {
3284  float4 arg1 = PG_GETARG_FLOAT4(0);
3285  float8 arg2 = PG_GETARG_FLOAT8(1);
3286  float8 result;
3287 
3288  result = arg1 - arg2;
3289  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
3290  PG_RETURN_FLOAT8(result);
3291 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float48mul()

Datum float48mul ( PG_FUNCTION_ARGS  )

Definition at line 3294 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3295 {
3296  float4 arg1 = PG_GETARG_FLOAT4(0);
3297  float8 arg2 = PG_GETARG_FLOAT8(1);
3298  float8 result;
3299 
3300  result = arg1 * arg2;
3301  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2),
3302  arg1 == 0 || arg2 == 0);
3303  PG_RETURN_FLOAT8(result);
3304 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float48ne()

Datum float48ne ( PG_FUNCTION_ARGS  )

Definition at line 3406 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3407 {
3408  float4 arg1 = PG_GETARG_FLOAT4(0);
3409  float8 arg2 = PG_GETARG_FLOAT8(1);
3410 
3411  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) != 0);
3412 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float48pl()

Datum float48pl ( PG_FUNCTION_ARGS  )

Definition at line 3270 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3271 {
3272  float4 arg1 = PG_GETARG_FLOAT4(0);
3273  float8 arg2 = PG_GETARG_FLOAT8(1);
3274  float8 result;
3275 
3276  result = arg1 + arg2;
3277  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
3278  PG_RETURN_FLOAT8(result);
3279 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float4_accum()

Datum float4_accum ( PG_FUNCTION_ARGS  )

Definition at line 2582 of file float.c.

References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, construct_array(), Float8GetDatumFast, FLOAT8OID, isinf(), newval, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT4, and PG_RETURN_ARRAYTYPE_P.

2583 {
2584  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2585 
2586  /* do computations as float8 */
2588  float8 *transvalues;
2589  float8 N,
2590  sumX,
2591  sumX2;
2592 
2593  transvalues = check_float8_array(transarray, "float4_accum", 3);
2594  N = transvalues[0];
2595  sumX = transvalues[1];
2596  sumX2 = transvalues[2];
2597 
2598  N += 1.0;
2599  sumX += newval;
2600  CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newval), true);
2601  sumX2 += newval * newval;
2602  CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newval), true);
2603 
2604  /*
2605  * If we're invoked as an aggregate, we can cheat and modify our first
2606  * parameter in-place to reduce palloc overhead. Otherwise we construct a
2607  * new array with the updated transition data and return it.
2608  */
2609  if (AggCheckCallContext(fcinfo, NULL))
2610  {
2611  transvalues[0] = N;
2612  transvalues[1] = sumX;
2613  transvalues[2] = sumX2;
2614 
2615  PG_RETURN_ARRAYTYPE_P(transarray);
2616  }
2617  else
2618  {
2619  Datum transdatums[3];
2620  ArrayType *result;
2621 
2622  transdatums[0] = Float8GetDatumFast(N);
2623  transdatums[1] = Float8GetDatumFast(sumX);
2624  transdatums[2] = Float8GetDatumFast(sumX2);
2625 
2626  result = construct_array(transdatums, 3,
2627  FLOAT8OID,
2628  sizeof(float8), FLOAT8PASSBYVAL, 'd');
2629 
2630  PG_RETURN_ARRAYTYPE_P(result);
2631  }
2632 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:250
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
uintptr_t Datum
Definition: postgres.h:372
#define Float8GetDatumFast(X)
Definition: postgres.h:782
#define newval
#define FLOAT8OID
Definition: pg_type.h:419
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4127
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471

◆ float4_cmp_internal()

int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 939 of file float.c.

Referenced by btfloat4cmp(), btfloat4fastcmp(), float4eq(), float4ge(), float4gt(), float4larger(), float4le(), float4lt(), float4ne(), and float4smaller().

940 {
941  /*
942  * We consider all NANs to be equal and larger than any non-NAN. This is
943  * somewhat arbitrary; the important thing is to have a consistent sort
944  * order.
945  */
946  if (isnan(a))
947  {
948  if (isnan(b))
949  return 0; /* NAN = NAN */
950  else
951  return 1; /* NAN > non-NAN */
952  }
953  else if (isnan(b))
954  {
955  return -1; /* non-NAN < NAN */
956  }
957  else
958  {
959  if (a > b)
960  return 1;
961  else if (a < b)
962  return -1;
963  else
964  return 0;
965  }
966 }

◆ float4abs()

Datum float4abs ( PG_FUNCTION_ARGS  )

Definition at line 665 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

666 {
667  float4 arg1 = PG_GETARG_FLOAT4(0);
668 
669  PG_RETURN_FLOAT4((float4) fabs(arg1));
670 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ float4div()

Datum float4div ( PG_FUNCTION_ARGS  )

Definition at line 847 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

848 {
849  float4 arg1 = PG_GETARG_FLOAT4(0);
850  float4 arg2 = PG_GETARG_FLOAT4(1);
851  float4 result;
852 
853  if (arg2 == 0.0)
854  ereport(ERROR,
855  (errcode(ERRCODE_DIVISION_BY_ZERO),
856  errmsg("division by zero")));
857 
858  result = arg1 / arg2;
859 
860  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
861  PG_RETURN_FLOAT4(result);
862 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ float4eq()

Datum float4eq ( PG_FUNCTION_ARGS  )

Definition at line 969 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

970 {
971  float4 arg1 = PG_GETARG_FLOAT4(0);
972  float4 arg2 = PG_GETARG_FLOAT4(1);
973 
974  PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) == 0);
975 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float4ge()

Datum float4ge ( PG_FUNCTION_ARGS  )

Definition at line 1014 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

1015 {
1016  float4 arg1 = PG_GETARG_FLOAT4(0);
1017  float4 arg2 = PG_GETARG_FLOAT4(1);
1018 
1019  PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) >= 0);
1020 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float4gt()

Datum float4gt ( PG_FUNCTION_ARGS  )

Definition at line 1005 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

1006 {
1007  float4 arg1 = PG_GETARG_FLOAT4(0);
1008  float4 arg2 = PG_GETARG_FLOAT4(1);
1009 
1010  PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) > 0);
1011 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float4in()

Datum float4in ( PG_FUNCTION_ARGS  )

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

221 {
222  char *num = PG_GETARG_CSTRING(0);
223  char *orig_num;
224  double val;
225  char *endptr;
226 
227  /*
228  * endptr points to the first character _after_ the sequence we recognized
229  * as a valid floating point number. orig_num points to the original input
230  * string.
231  */
232  orig_num = num;
233 
234  /* skip leading whitespace */
235  while (*num != '\0' && isspace((unsigned char) *num))
236  num++;
237 
238  /*
239  * Check for an empty-string input to begin with, to avoid the vagaries of
240  * strtod() on different platforms.
241  */
242  if (*num == '\0')
243  ereport(ERROR,
244  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
245  errmsg("invalid input syntax for type %s: \"%s\"",
246  "real", orig_num)));
247 
248  errno = 0;
249  val = strtod(num, &endptr);
250 
251  /* did we not see anything that looks like a double? */
252  if (endptr == num || errno != 0)
253  {
254  int save_errno = errno;
255 
256  /*
257  * C99 requires that strtod() accept NaN, [+-]Infinity, and [+-]Inf,
258  * but not all platforms support all of these (and some accept them
259  * but set ERANGE anyway...) Therefore, we check for these inputs
260  * ourselves if strtod() fails.
261  *
262  * Note: C99 also requires hexadecimal input as well as some extended
263  * forms of NaN, but we consider these forms unportable and don't try
264  * to support them. You can use 'em if your strtod() takes 'em.
265  */
266  if (pg_strncasecmp(num, "NaN", 3) == 0)
267  {
268  val = get_float4_nan();
269  endptr = num + 3;
270  }
271  else if (pg_strncasecmp(num, "Infinity", 8) == 0)
272  {
273  val = get_float4_infinity();
274  endptr = num + 8;
275  }
276  else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
277  {
278  val = get_float4_infinity();
279  endptr = num + 9;
280  }
281  else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
282  {
283  val = -get_float4_infinity();
284  endptr = num + 9;
285  }
286  else if (pg_strncasecmp(num, "inf", 3) == 0)
287  {
288  val = get_float4_infinity();
289  endptr = num + 3;
290  }
291  else if (pg_strncasecmp(num, "+inf", 4) == 0)
292  {
293  val = get_float4_infinity();
294  endptr = num + 4;
295  }
296  else if (pg_strncasecmp(num, "-inf", 4) == 0)
297  {
298  val = -get_float4_infinity();
299  endptr = num + 4;
300  }
301  else if (save_errno == ERANGE)
302  {
303  /*
304  * Some platforms return ERANGE for denormalized numbers (those
305  * that are not zero, but are too close to zero to have full
306  * precision). We'd prefer not to throw error for that, so try to
307  * detect whether it's a "real" out-of-range condition by checking
308  * to see if the result is zero or huge.
309  */
310  if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL)
311  ereport(ERROR,
312  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
313  errmsg("\"%s\" is out of range for type real",
314  orig_num)));
315  }
316  else
317  ereport(ERROR,
318  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
319  errmsg("invalid input syntax for type %s: \"%s\"",
320  "real", orig_num)));
321  }
322 #ifdef HAVE_BUGGY_SOLARIS_STRTOD
323  else
324  {
325  /*
326  * Many versions of Solaris have a bug wherein strtod sets endptr to
327  * point one byte beyond the end of the string when given "inf" or
328  * "infinity".
329  */
330  if (endptr != num && endptr[-1] == '\0')
331  endptr--;
332  }
333 #endif /* HAVE_BUGGY_SOLARIS_STRTOD */
334 
335  /* skip trailing whitespace */
336  while (*endptr != '\0' && isspace((unsigned char) *endptr))
337  endptr++;
338 
339  /* if there is any junk left at the end of the string, bail out */
340  if (*endptr != '\0')
341  ereport(ERROR,
342  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
343  errmsg("invalid input syntax for type %s: \"%s\"",
344  "real", orig_num)));
345 
346  /*
347  * if we get here, we have a legal double, still need to check to see if
348  * it's a legal float4
349  */
350  CHECKFLOATVAL((float4) val, isinf(val), val == 0);
351 
352  PG_RETURN_FLOAT4((float4) val);
353 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
float get_float4_nan(void)
Definition: float.c:180
int errcode(int sqlerrcode)
Definition: elog.c:575
float get_float4_infinity(void)
Definition: float.c:147
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
long val
Definition: informix.c:689

◆ float4larger()

Datum float4larger ( PG_FUNCTION_ARGS  )

Definition at line 694 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

695 {
696  float4 arg1 = PG_GETARG_FLOAT4(0);
697  float4 arg2 = PG_GETARG_FLOAT4(1);
698  float4 result;
699 
700  if (float4_cmp_internal(arg1, arg2) > 0)
701  result = arg1;
702  else
703  result = arg2;
704  PG_RETURN_FLOAT4(result);
705 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ float4le()

Datum float4le ( PG_FUNCTION_ARGS  )

Definition at line 996 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

997 {
998  float4 arg1 = PG_GETARG_FLOAT4(0);
999  float4 arg2 = PG_GETARG_FLOAT4(1);
1000 
1001  PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) <= 0);
1002 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float4lt()

Datum float4lt ( PG_FUNCTION_ARGS  )

Definition at line 987 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

988 {
989  float4 arg1 = PG_GETARG_FLOAT4(0);
990  float4 arg2 = PG_GETARG_FLOAT4(1);
991 
992  PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) < 0);
993 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float4mi()

Datum float4mi ( PG_FUNCTION_ARGS  )

Definition at line 822 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

823 {
824  float4 arg1 = PG_GETARG_FLOAT4(0);
825  float4 arg2 = PG_GETARG_FLOAT4(1);
826  float4 result;
827 
828  result = arg1 - arg2;
829  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
830  PG_RETURN_FLOAT4(result);
831 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float4mul()

Datum float4mul ( PG_FUNCTION_ARGS  )

Definition at line 834 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

835 {
836  float4 arg1 = PG_GETARG_FLOAT4(0);
837  float4 arg2 = PG_GETARG_FLOAT4(1);
838  float4 result;
839 
840  result = arg1 * arg2;
841  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2),
842  arg1 == 0 || arg2 == 0);
843  PG_RETURN_FLOAT4(result);
844 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float4ne()

Datum float4ne ( PG_FUNCTION_ARGS  )

Definition at line 978 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

979 {
980  float4 arg1 = PG_GETARG_FLOAT4(0);
981  float4 arg2 = PG_GETARG_FLOAT4(1);
982 
983  PG_RETURN_BOOL(float4_cmp_internal(arg1, arg2) != 0);
984 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float4out()

Datum float4out ( PG_FUNCTION_ARGS  )

Definition at line 360 of file float.c.

References ascii(), extra_float_digits, is_infinite(), MAXFLOATWIDTH, palloc(), PG_GETARG_FLOAT4, PG_RETURN_CSTRING, and snprintf().

361 {
362  float4 num = PG_GETARG_FLOAT4(0);
363  char *ascii = (char *) palloc(MAXFLOATWIDTH + 1);
364 
365  if (isnan(num))
366  PG_RETURN_CSTRING(strcpy(ascii, "NaN"));
367 
368  switch (is_infinite(num))
369  {
370  case 1:
371  strcpy(ascii, "Infinity");
372  break;
373  case -1:
374  strcpy(ascii, "-Infinity");
375  break;
376  default:
377  {
378  int ndig = FLT_DIG + extra_float_digits;
379 
380  if (ndig < 1)
381  ndig = 1;
382 
383  snprintf(ascii, MAXFLOATWIDTH + 1, "%.*g", ndig, num);
384  }
385  }
386 
387  PG_RETURN_CSTRING(ascii);
388 }
Datum ascii(PG_FUNCTION_ARGS)
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define MAXFLOATWIDTH
Definition: float.c:48
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
int extra_float_digits
Definition: float.c:69
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
int is_infinite(double val)
Definition: float.c:200
void * palloc(Size size)
Definition: mcxt.c:835

◆ float4pl()

Datum float4pl ( PG_FUNCTION_ARGS  )

Definition at line 802 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

803 {
804  float4 arg1 = PG_GETARG_FLOAT4(0);
805  float4 arg2 = PG_GETARG_FLOAT4(1);
806  float4 result;
807 
808  result = arg1 + arg2;
809 
810  /*
811  * There isn't any way to check for underflow of addition/subtraction
812  * because numbers near the underflow value have already been rounded to
813  * the point where we can't detect that the two values were originally
814  * different, e.g. on x86, '1e-45'::float4 == '2e-45'::float4 ==
815  * 1.4013e-45.
816  */
817  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
818  PG_RETURN_FLOAT4(result);
819 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float4recv()

Datum float4recv ( PG_FUNCTION_ARGS  )

Definition at line 394 of file float.c.

References buf, PG_GETARG_POINTER, PG_RETURN_FLOAT4, and pq_getmsgfloat4().

395 {
397 
399 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static char * buf
Definition: pg_test_fsync.c:67
float4 pq_getmsgfloat4(StringInfo msg)
Definition: pqformat.c:471

◆ float4send()

Datum float4send ( PG_FUNCTION_ARGS  )

Definition at line 405 of file float.c.

References buf, PG_GETARG_FLOAT4, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendfloat4().

406 {
407  float4 num = PG_GETARG_FLOAT4(0);
409 
410  pq_begintypsend(&buf);
411  pq_sendfloat4(&buf, num);
413 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
void pq_sendfloat4(StringInfo buf, float4 f)
Definition: pqformat.c:254
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ float4smaller()

Datum float4smaller ( PG_FUNCTION_ARGS  )

Definition at line 708 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

709 {
710  float4 arg1 = PG_GETARG_FLOAT4(0);
711  float4 arg2 = PG_GETARG_FLOAT4(1);
712  float4 result;
713 
714  if (float4_cmp_internal(arg1, arg2) < 0)
715  result = arg1;
716  else
717  result = arg2;
718  PG_RETURN_FLOAT4(result);
719 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:939
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ float4um()

Datum float4um ( PG_FUNCTION_ARGS  )

Definition at line 676 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

677 {
678  float4 arg1 = PG_GETARG_FLOAT4(0);
679  float4 result;
680 
681  result = -arg1;
682  PG_RETURN_FLOAT4(result);
683 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ float4up()

Datum float4up ( PG_FUNCTION_ARGS  )

Definition at line 686 of file float.c.

References arg, PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

687 {
689 
690  PG_RETURN_FLOAT4(arg);
691 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
void * arg

◆ float84div()

Datum float84div ( PG_FUNCTION_ARGS  )

Definition at line 3370 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3371 {
3372  float8 arg1 = PG_GETARG_FLOAT8(0);
3373  float4 arg2 = PG_GETARG_FLOAT4(1);
3374  float8 result;
3375 
3376  if (arg2 == 0.0)
3377  ereport(ERROR,
3378  (errcode(ERRCODE_DIVISION_BY_ZERO),
3379  errmsg("division by zero")));
3380 
3381  result = arg1 / arg2;
3382 
3383  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
3384  PG_RETURN_FLOAT8(result);
3385 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ float84eq()

Datum float84eq ( PG_FUNCTION_ARGS  )

Definition at line 3454 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3455 {
3456  float8 arg1 = PG_GETARG_FLOAT8(0);
3457  float4 arg2 = PG_GETARG_FLOAT4(1);
3458 
3459  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) == 0);
3460 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float84ge()

Datum float84ge ( PG_FUNCTION_ARGS  )

Definition at line 3499 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3500 {
3501  float8 arg1 = PG_GETARG_FLOAT8(0);
3502  float4 arg2 = PG_GETARG_FLOAT4(1);
3503 
3504  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) >= 0);
3505 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float84gt()

Datum float84gt ( PG_FUNCTION_ARGS  )

Definition at line 3490 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3491 {
3492  float8 arg1 = PG_GETARG_FLOAT8(0);
3493  float4 arg2 = PG_GETARG_FLOAT4(1);
3494 
3495  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) > 0);
3496 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float84le()

Datum float84le ( PG_FUNCTION_ARGS  )

Definition at line 3481 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3482 {
3483  float8 arg1 = PG_GETARG_FLOAT8(0);
3484  float4 arg2 = PG_GETARG_FLOAT4(1);
3485 
3486  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) <= 0);
3487 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float84lt()

Datum float84lt ( PG_FUNCTION_ARGS  )

Definition at line 3472 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3473 {
3474  float8 arg1 = PG_GETARG_FLOAT8(0);
3475  float4 arg2 = PG_GETARG_FLOAT4(1);
3476 
3477  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) < 0);
3478 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float84mi()

Datum float84mi ( PG_FUNCTION_ARGS  )

Definition at line 3343 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3344 {
3345  float8 arg1 = PG_GETARG_FLOAT8(0);
3346  float4 arg2 = PG_GETARG_FLOAT4(1);
3347  float8 result;
3348 
3349  result = arg1 - arg2;
3350 
3351  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
3352  PG_RETURN_FLOAT8(result);
3353 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float84mul()

Datum float84mul ( PG_FUNCTION_ARGS  )

Definition at line 3356 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3357 {
3358  float8 arg1 = PG_GETARG_FLOAT8(0);
3359  float4 arg2 = PG_GETARG_FLOAT4(1);
3360  float8 result;
3361 
3362  result = arg1 * arg2;
3363 
3364  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2),
3365  arg1 == 0 || arg2 == 0);
3366  PG_RETURN_FLOAT8(result);
3367 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float84ne()

Datum float84ne ( PG_FUNCTION_ARGS  )

Definition at line 3463 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

3464 {
3465  float8 arg1 = PG_GETARG_FLOAT8(0);
3466  float4 arg2 = PG_GETARG_FLOAT4(1);
3467 
3468  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) != 0);
3469 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float84pl()

Datum float84pl ( PG_FUNCTION_ARGS  )

Definition at line 3330 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3331 {
3332  float8 arg1 = PG_GETARG_FLOAT8(0);
3333  float4 arg2 = PG_GETARG_FLOAT4(1);
3334  float8 result;
3335 
3336  result = arg1 + arg2;
3337 
3338  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
3339  PG_RETURN_FLOAT8(result);
3340 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float8_accum()

Datum float8_accum ( PG_FUNCTION_ARGS  )

Definition at line 2531 of file float.c.

References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, construct_array(), Float8GetDatumFast, FLOAT8OID, isinf(), newval, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, and PG_RETURN_ARRAYTYPE_P.

2532 {
2533  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2535  float8 *transvalues;
2536  float8 N,
2537  sumX,
2538  sumX2;
2539 
2540  transvalues = check_float8_array(transarray, "float8_accum", 3);
2541  N = transvalues[0];
2542  sumX = transvalues[1];
2543  sumX2 = transvalues[2];
2544 
2545  N += 1.0;
2546  sumX += newval;
2547  CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newval), true);
2548  sumX2 += newval * newval;
2549  CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newval), true);
2550 
2551  /*
2552  * If we're invoked as an aggregate, we can cheat and modify our first
2553  * parameter in-place to reduce palloc overhead. Otherwise we construct a
2554  * new array with the updated transition data and return it.
2555  */
2556  if (AggCheckCallContext(fcinfo, NULL))
2557  {
2558  transvalues[0] = N;
2559  transvalues[1] = sumX;
2560  transvalues[2] = sumX2;
2561 
2562  PG_RETURN_ARRAYTYPE_P(transarray);
2563  }
2564  else
2565  {
2566  Datum transdatums[3];
2567  ArrayType *result;
2568 
2569  transdatums[0] = Float8GetDatumFast(N);
2570  transdatums[1] = Float8GetDatumFast(sumX);
2571  transdatums[2] = Float8GetDatumFast(sumX2);
2572 
2573  result = construct_array(transdatums, 3,
2574  FLOAT8OID,
2575  sizeof(float8), FLOAT8PASSBYVAL, 'd');
2576 
2577  PG_RETURN_ARRAYTYPE_P(result);
2578  }
2579 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:250
uintptr_t Datum
Definition: postgres.h:372
#define Float8GetDatumFast(X)
Definition: postgres.h:782
#define newval
#define FLOAT8OID
Definition: pg_type.h:419
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4127
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471

◆ float8_avg()

Datum float8_avg ( PG_FUNCTION_ARGS  )

Definition at line 2635 of file float.c.

References check_float8_array(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2636 {
2637  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2638  float8 *transvalues;
2639  float8 N,
2640  sumX;
2641 
2642  transvalues = check_float8_array(transarray, "float8_avg", 3);
2643  N = transvalues[0];
2644  sumX = transvalues[1];
2645  /* ignore sumX2 */
2646 
2647  /* SQL defines AVG of no values to be NULL */
2648  if (N == 0.0)
2649  PG_RETURN_NULL();
2650 
2651  PG_RETURN_FLOAT8(sumX / N);
2652 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_cmp_internal()

int float8_cmp_internal ( float8  a,
float8  b 
)

Definition at line 1053 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(), float8smaller(), interval_cmp_lower(), and interval_cmp_upper().

1054 {
1055  /*
1056  * We consider all NANs to be equal and larger than any non-NAN. This is
1057  * somewhat arbitrary; the important thing is to have a consistent sort
1058  * order.
1059  */
1060  if (isnan(a))
1061  {
1062  if (isnan(b))
1063  return 0; /* NAN = NAN */
1064  else
1065  return 1; /* NAN > non-NAN */
1066  }
1067  else if (isnan(b))
1068  {
1069  return -1; /* non-NAN < NAN */
1070  }
1071  else
1072  {
1073  if (a > b)
1074  return 1;
1075  else if (a < b)
1076  return -1;
1077  else
1078  return 0;
1079  }
1080 }

◆ float8_combine()

Datum float8_combine ( PG_FUNCTION_ARGS  )

Definition at line 2495 of file float.c.

References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, elog, ERROR, isinf(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_ARRAYTYPE_P.

2496 {
2497  ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(0);
2498  ArrayType *transarray2 = PG_GETARG_ARRAYTYPE_P(1);
2499  float8 *transvalues1;
2500  float8 *transvalues2;
2501  float8 N,
2502  sumX,
2503  sumX2;
2504 
2505  if (!AggCheckCallContext(fcinfo, NULL))
2506  elog(ERROR, "aggregate function called in non-aggregate context");
2507 
2508  transvalues1 = check_float8_array(transarray1, "float8_combine", 3);
2509  N = transvalues1[0];
2510  sumX = transvalues1[1];
2511  sumX2 = transvalues1[2];
2512 
2513  transvalues2 = check_float8_array(transarray2, "float8_combine", 3);
2514 
2515  N += transvalues2[0];
2516  sumX += transvalues2[1];
2517  CHECKFLOATVAL(sumX, isinf(transvalues1[1]) || isinf(transvalues2[1]),
2518  true);
2519  sumX2 += transvalues2[2];
2520  CHECKFLOATVAL(sumX2, isinf(transvalues1[2]) || isinf(transvalues2[2]),
2521  true);
2522 
2523  transvalues1[0] = N;
2524  transvalues1[1] = sumX;
2525  transvalues1[2] = sumX2;
2526 
2527  PG_RETURN_ARRAYTYPE_P(transarray1);
2528 }
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:250
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4127
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define elog
Definition: elog.h:219

◆ float8_corr()

Datum float8_corr ( PG_FUNCTION_ARGS  )

Definition at line 3103 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3104 {
3105  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3106  float8 *transvalues;
3107  float8 N,
3108  sumX,
3109  sumX2,
3110  sumY,
3111  sumY2,
3112  sumXY,
3113  numeratorX,
3114  numeratorY,
3115  numeratorXY;
3116 
3117  transvalues = check_float8_array(transarray, "float8_corr", 6);
3118  N = transvalues[0];
3119  sumX = transvalues[1];
3120  sumX2 = transvalues[2];
3121  sumY = transvalues[3];
3122  sumY2 = transvalues[4];
3123  sumXY = transvalues[5];
3124 
3125  /* if N is 0 we should return NULL */
3126  if (N < 1.0)
3127  PG_RETURN_NULL();
3128 
3129  numeratorX = N * sumX2 - sumX * sumX;
3130  CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true);
3131  numeratorY = N * sumY2 - sumY * sumY;
3132  CHECKFLOATVAL(numeratorY, isinf(sumY2) || isinf(sumY), true);
3133  numeratorXY = N * sumXY - sumX * sumY;
3134  CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) ||
3135  isinf(sumY), true);
3136  if (numeratorX <= 0 || numeratorY <= 0)
3137  PG_RETURN_NULL();
3138 
3139  PG_RETURN_FLOAT8(numeratorXY / sqrt(numeratorX * numeratorY));
3140 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_covar_pop()

Datum float8_covar_pop ( PG_FUNCTION_ARGS  )

Definition at line 3047 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3048 {
3049  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3050  float8 *transvalues;
3051  float8 N,
3052  sumX,
3053  sumY,
3054  sumXY,
3055  numerator;
3056 
3057  transvalues = check_float8_array(transarray, "float8_covar_pop", 6);
3058  N = transvalues[0];
3059  sumX = transvalues[1];
3060  sumY = transvalues[3];
3061  sumXY = transvalues[5];
3062 
3063  /* if N is 0 we should return NULL */
3064  if (N < 1.0)
3065  PG_RETURN_NULL();
3066 
3067  numerator = N * sumXY - sumX * sumY;
3068  CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) ||
3069  isinf(sumY), true);
3070 
3071  PG_RETURN_FLOAT8(numerator / (N * N));
3072 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_covar_samp()

Datum float8_covar_samp ( PG_FUNCTION_ARGS  )

Definition at line 3075 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3076 {
3077  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3078  float8 *transvalues;
3079  float8 N,
3080  sumX,
3081  sumY,
3082  sumXY,
3083  numerator;
3084 
3085  transvalues = check_float8_array(transarray, "float8_covar_samp", 6);
3086  N = transvalues[0];
3087  sumX = transvalues[1];
3088  sumY = transvalues[3];
3089  sumXY = transvalues[5];
3090 
3091  /* if N is <= 1 we should return NULL */
3092  if (N < 2.0)
3093  PG_RETURN_NULL();
3094 
3095  numerator = N * sumXY - sumX * sumY;
3096  CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) ||
3097  isinf(sumY), true);
3098 
3099  PG_RETURN_FLOAT8(numerator / (N * (N - 1.0)));
3100 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_accum()

Datum float8_regr_accum ( PG_FUNCTION_ARGS  )

Definition at line 2787 of file float.c.

References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, construct_array(), Float8GetDatumFast, FLOAT8OID, isinf(), PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, and PG_RETURN_ARRAYTYPE_P.

2788 {
2789  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2790  float8 newvalY = PG_GETARG_FLOAT8(1);
2791  float8 newvalX = PG_GETARG_FLOAT8(2);
2792  float8 *transvalues;
2793  float8 N,
2794  sumX,
2795  sumX2,
2796  sumY,
2797  sumY2,
2798  sumXY;
2799 
2800  transvalues = check_float8_array(transarray, "float8_regr_accum", 6);
2801  N = transvalues[0];
2802  sumX = transvalues[1];
2803  sumX2 = transvalues[2];
2804  sumY = transvalues[3];
2805  sumY2 = transvalues[4];
2806  sumXY = transvalues[5];
2807 
2808  N += 1.0;
2809  sumX += newvalX;
2810  CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newvalX), true);
2811  sumX2 += newvalX * newvalX;
2812  CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newvalX), true);
2813  sumY += newvalY;
2814  CHECKFLOATVAL(sumY, isinf(transvalues[3]) || isinf(newvalY), true);
2815  sumY2 += newvalY * newvalY;
2816  CHECKFLOATVAL(sumY2, isinf(transvalues[4]) || isinf(newvalY), true);
2817  sumXY += newvalX * newvalY;
2818  CHECKFLOATVAL(sumXY, isinf(transvalues[5]) || isinf(newvalX) ||
2819  isinf(newvalY), true);
2820 
2821  /*
2822  * If we're invoked as an aggregate, we can cheat and modify our first
2823  * parameter in-place to reduce palloc overhead. Otherwise we construct a
2824  * new array with the updated transition data and return it.
2825  */
2826  if (AggCheckCallContext(fcinfo, NULL))
2827  {
2828  transvalues[0] = N;
2829  transvalues[1] = sumX;
2830  transvalues[2] = sumX2;
2831  transvalues[3] = sumY;
2832  transvalues[4] = sumY2;
2833  transvalues[5] = sumXY;
2834 
2835  PG_RETURN_ARRAYTYPE_P(transarray);
2836  }
2837  else
2838  {
2839  Datum transdatums[6];
2840  ArrayType *result;
2841 
2842  transdatums[0] = Float8GetDatumFast(N);
2843  transdatums[1] = Float8GetDatumFast(sumX);
2844  transdatums[2] = Float8GetDatumFast(sumX2);
2845  transdatums[3] = Float8GetDatumFast(sumY);
2846  transdatums[4] = Float8GetDatumFast(sumY2);
2847  transdatums[5] = Float8GetDatumFast(sumXY);
2848 
2849  result = construct_array(transdatums, 6,
2850  FLOAT8OID,
2851  sizeof(float8), FLOAT8PASSBYVAL, 'd');
2852 
2853  PG_RETURN_ARRAYTYPE_P(result);
2854  }
2855 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:250
uintptr_t Datum
Definition: postgres.h:372
#define Float8GetDatumFast(X)
Definition: postgres.h:782
#define FLOAT8OID
Definition: pg_type.h:419
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4127
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471

◆ float8_regr_avgx()

Datum float8_regr_avgx ( PG_FUNCTION_ARGS  )

Definition at line 3009 of file float.c.

References check_float8_array(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3010 {
3011  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3012  float8 *transvalues;
3013  float8 N,
3014  sumX;
3015 
3016  transvalues = check_float8_array(transarray, "float8_regr_avgx", 6);
3017  N = transvalues[0];
3018  sumX = transvalues[1];
3019 
3020  /* if N is 0 we should return NULL */
3021  if (N < 1.0)
3022  PG_RETURN_NULL();
3023 
3024  PG_RETURN_FLOAT8(sumX / N);
3025 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_avgy()

Datum float8_regr_avgy ( PG_FUNCTION_ARGS  )

Definition at line 3028 of file float.c.

References check_float8_array(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3029 {
3030  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3031  float8 *transvalues;
3032  float8 N,
3033  sumY;
3034 
3035  transvalues = check_float8_array(transarray, "float8_regr_avgy", 6);
3036  N = transvalues[0];
3037  sumY = transvalues[3];
3038 
3039  /* if N is 0 we should return NULL */
3040  if (N < 1.0)
3041  PG_RETURN_NULL();
3042 
3043  PG_RETURN_FLOAT8(sumY / N);
3044 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_combine()

Datum float8_regr_combine ( PG_FUNCTION_ARGS  )

Definition at line 2866 of file float.c.

References AggCheckCallContext(), check_float8_array(), CHECKFLOATVAL, elog, ERROR, isinf(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_ARRAYTYPE_P.

2867 {
2868  ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(0);
2869  ArrayType *transarray2 = PG_GETARG_ARRAYTYPE_P(1);
2870  float8 *transvalues1;
2871  float8 *transvalues2;
2872  float8 N,
2873  sumX,
2874  sumX2,
2875  sumY,
2876  sumY2,
2877  sumXY;
2878 
2879  if (!AggCheckCallContext(fcinfo, NULL))
2880  elog(ERROR, "aggregate function called in non-aggregate context");
2881 
2882  transvalues1 = check_float8_array(transarray1, "float8_regr_combine", 6);
2883  N = transvalues1[0];
2884  sumX = transvalues1[1];
2885  sumX2 = transvalues1[2];
2886  sumY = transvalues1[3];
2887  sumY2 = transvalues1[4];
2888  sumXY = transvalues1[5];
2889 
2890  transvalues2 = check_float8_array(transarray2, "float8_regr_combine", 6);
2891 
2892  N += transvalues2[0];
2893  sumX += transvalues2[1];
2894  CHECKFLOATVAL(sumX, isinf(transvalues1[1]) || isinf(transvalues2[1]),
2895  true);
2896  sumX2 += transvalues2[2];
2897  CHECKFLOATVAL(sumX2, isinf(transvalues1[2]) || isinf(transvalues2[2]),
2898  true);
2899  sumY += transvalues2[3];
2900  CHECKFLOATVAL(sumY, isinf(transvalues1[3]) || isinf(transvalues2[3]),
2901  true);
2902  sumY2 += transvalues2[4];
2903  CHECKFLOATVAL(sumY2, isinf(transvalues1[4]) || isinf(transvalues2[4]),
2904  true);
2905  sumXY += transvalues2[5];
2906  CHECKFLOATVAL(sumXY, isinf(transvalues1[5]) || isinf(transvalues2[5]),
2907  true);
2908 
2909  transvalues1[0] = N;
2910  transvalues1[1] = sumX;
2911  transvalues1[2] = sumX2;
2912  transvalues1[3] = sumY;
2913  transvalues1[4] = sumY2;
2914  transvalues1[5] = sumXY;
2915 
2916  PG_RETURN_ARRAYTYPE_P(transarray1);
2917 }
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:250
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4127
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define elog
Definition: elog.h:219

◆ float8_regr_intercept()

Datum float8_regr_intercept ( PG_FUNCTION_ARGS  )

Definition at line 3222 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3223 {
3224  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3225  float8 *transvalues;
3226  float8 N,
3227  sumX,
3228  sumX2,
3229  sumY,
3230  sumXY,
3231  numeratorX,
3232  numeratorXXY;
3233 
3234  transvalues = check_float8_array(transarray, "float8_regr_intercept", 6);
3235  N = transvalues[0];
3236  sumX = transvalues[1];
3237  sumX2 = transvalues[2];
3238  sumY = transvalues[3];
3239  sumXY = transvalues[5];
3240 
3241  /* if N is 0 we should return NULL */
3242  if (N < 1.0)
3243  PG_RETURN_NULL();
3244 
3245  numeratorX = N * sumX2 - sumX * sumX;
3246  CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true);
3247  numeratorXXY = sumY * sumX2 - sumX * sumXY;
3248  CHECKFLOATVAL(numeratorXXY, isinf(sumY) || isinf(sumX2) ||
3249  isinf(sumX) || isinf(sumXY), true);
3250  if (numeratorX <= 0)
3251  PG_RETURN_NULL();
3252 
3253  PG_RETURN_FLOAT8(numeratorXXY / numeratorX);
3254 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_r2()

Datum float8_regr_r2 ( PG_FUNCTION_ARGS  )

Definition at line 3143 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3144 {
3145  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3146  float8 *transvalues;
3147  float8 N,
3148  sumX,
3149  sumX2,
3150  sumY,
3151  sumY2,
3152  sumXY,
3153  numeratorX,
3154  numeratorY,
3155  numeratorXY;
3156 
3157  transvalues = check_float8_array(transarray, "float8_regr_r2", 6);
3158  N = transvalues[0];
3159  sumX = transvalues[1];
3160  sumX2 = transvalues[2];
3161  sumY = transvalues[3];
3162  sumY2 = transvalues[4];
3163  sumXY = transvalues[5];
3164 
3165  /* if N is 0 we should return NULL */
3166  if (N < 1.0)
3167  PG_RETURN_NULL();
3168 
3169  numeratorX = N * sumX2 - sumX * sumX;
3170  CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true);
3171  numeratorY = N * sumY2 - sumY * sumY;
3172  CHECKFLOATVAL(numeratorY, isinf(sumY2) || isinf(sumY), true);
3173  numeratorXY = N * sumXY - sumX * sumY;
3174  CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) ||
3175  isinf(sumY), true);
3176  if (numeratorX <= 0)
3177  PG_RETURN_NULL();
3178  /* per spec, horizontal line produces 1.0 */
3179  if (numeratorY <= 0)
3180  PG_RETURN_FLOAT8(1.0);
3181 
3182  PG_RETURN_FLOAT8((numeratorXY * numeratorXY) /
3183  (numeratorX * numeratorY));
3184 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_slope()

Datum float8_regr_slope ( PG_FUNCTION_ARGS  )

Definition at line 3187 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

3188 {
3189  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3190  float8 *transvalues;
3191  float8 N,
3192  sumX,
3193  sumX2,
3194  sumY,
3195  sumXY,
3196  numeratorX,
3197  numeratorXY;
3198 
3199  transvalues = check_float8_array(transarray, "float8_regr_slope", 6);
3200  N = transvalues[0];
3201  sumX = transvalues[1];
3202  sumX2 = transvalues[2];
3203  sumY = transvalues[3];
3204  sumXY = transvalues[5];
3205 
3206  /* if N is 0 we should return NULL */
3207  if (N < 1.0)
3208  PG_RETURN_NULL();
3209 
3210  numeratorX = N * sumX2 - sumX * sumX;
3211  CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true);
3212  numeratorXY = N * sumXY - sumX * sumY;
3213  CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) ||
3214  isinf(sumY), true);
3215  if (numeratorX <= 0)
3216  PG_RETURN_NULL();
3217 
3218  PG_RETURN_FLOAT8(numeratorXY / numeratorX);
3219 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_sxx()

Datum float8_regr_sxx ( PG_FUNCTION_ARGS  )

Definition at line 2921 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2922 {
2923  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2924  float8 *transvalues;
2925  float8 N,
2926  sumX,
2927  sumX2,
2928  numerator;
2929 
2930  transvalues = check_float8_array(transarray, "float8_regr_sxx", 6);
2931  N = transvalues[0];
2932  sumX = transvalues[1];
2933  sumX2 = transvalues[2];
2934 
2935  /* if N is 0 we should return NULL */
2936  if (N < 1.0)
2937  PG_RETURN_NULL();
2938 
2939  numerator = N * sumX2 - sumX * sumX;
2940  CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true);
2941 
2942  /* Watch out for roundoff error producing a negative numerator */
2943  if (numerator <= 0.0)
2944  PG_RETURN_FLOAT8(0.0);
2945 
2946  PG_RETURN_FLOAT8(numerator / N);
2947 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_sxy()

Datum float8_regr_sxy ( PG_FUNCTION_ARGS  )

Definition at line 2979 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2980 {
2981  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2982  float8 *transvalues;
2983  float8 N,
2984  sumX,
2985  sumY,
2986  sumXY,
2987  numerator;
2988 
2989  transvalues = check_float8_array(transarray, "float8_regr_sxy", 6);
2990  N = transvalues[0];
2991  sumX = transvalues[1];
2992  sumY = transvalues[3];
2993  sumXY = transvalues[5];
2994 
2995  /* if N is 0 we should return NULL */
2996  if (N < 1.0)
2997  PG_RETURN_NULL();
2998 
2999  numerator = N * sumXY - sumX * sumY;
3000  CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) ||
3001  isinf(sumY), true);
3002 
3003  /* A negative result is valid here */
3004 
3005  PG_RETURN_FLOAT8(numerator / N);
3006 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_regr_syy()

Datum float8_regr_syy ( PG_FUNCTION_ARGS  )

Definition at line 2950 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2951 {
2952  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2953  float8 *transvalues;
2954  float8 N,
2955  sumY,
2956  sumY2,
2957  numerator;
2958 
2959  transvalues = check_float8_array(transarray, "float8_regr_syy", 6);
2960  N = transvalues[0];
2961  sumY = transvalues[3];
2962  sumY2 = transvalues[4];
2963 
2964  /* if N is 0 we should return NULL */
2965  if (N < 1.0)
2966  PG_RETURN_NULL();
2967 
2968  numerator = N * sumY2 - sumY * sumY;
2969  CHECKFLOATVAL(numerator, isinf(sumY2) || isinf(sumY), true);
2970 
2971  /* Watch out for roundoff error producing a negative numerator */
2972  if (numerator <= 0.0)
2973  PG_RETURN_FLOAT8(0.0);
2974 
2975  PG_RETURN_FLOAT8(numerator / N);
2976 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_stddev_pop()

Datum float8_stddev_pop ( PG_FUNCTION_ARGS  )

Definition at line 2713 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2714 {
2715  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2716  float8 *transvalues;
2717  float8 N,
2718  sumX,
2719  sumX2,
2720  numerator;
2721 
2722  transvalues = check_float8_array(transarray, "float8_stddev_pop", 3);
2723  N = transvalues[0];
2724  sumX = transvalues[1];
2725  sumX2 = transvalues[2];
2726 
2727  /* Population stddev is undefined when N is 0, so return NULL */
2728  if (N == 0.0)
2729  PG_RETURN_NULL();
2730 
2731  numerator = N * sumX2 - sumX * sumX;
2732  CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true);
2733 
2734  /* Watch out for roundoff error producing a negative numerator */
2735  if (numerator <= 0.0)
2736  PG_RETURN_FLOAT8(0.0);
2737 
2738  PG_RETURN_FLOAT8(sqrt(numerator / (N * N)));
2739 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_stddev_samp()

Datum float8_stddev_samp ( PG_FUNCTION_ARGS  )

Definition at line 2742 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2743 {
2744  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2745  float8 *transvalues;
2746  float8 N,
2747  sumX,
2748  sumX2,
2749  numerator;
2750 
2751  transvalues = check_float8_array(transarray, "float8_stddev_samp", 3);
2752  N = transvalues[0];
2753  sumX = transvalues[1];
2754  sumX2 = transvalues[2];
2755 
2756  /* Sample stddev is undefined when N is 0 or 1, so return NULL */
2757  if (N <= 1.0)
2758  PG_RETURN_NULL();
2759 
2760  numerator = N * sumX2 - sumX * sumX;
2761  CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true);
2762 
2763  /* Watch out for roundoff error producing a negative numerator */
2764  if (numerator <= 0.0)
2765  PG_RETURN_FLOAT8(0.0);
2766 
2767  PG_RETURN_FLOAT8(sqrt(numerator / (N * (N - 1.0))));
2768 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_var_pop()

Datum float8_var_pop ( PG_FUNCTION_ARGS  )

Definition at line 2655 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2656 {
2657  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2658  float8 *transvalues;
2659  float8 N,
2660  sumX,
2661  sumX2,
2662  numerator;
2663 
2664  transvalues = check_float8_array(transarray, "float8_var_pop", 3);
2665  N = transvalues[0];
2666  sumX = transvalues[1];
2667  sumX2 = transvalues[2];
2668 
2669  /* Population variance is undefined when N is 0, so return NULL */
2670  if (N == 0.0)
2671  PG_RETURN_NULL();
2672 
2673  numerator = N * sumX2 - sumX * sumX;
2674  CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true);
2675 
2676  /* Watch out for roundoff error producing a negative numerator */
2677  if (numerator <= 0.0)
2678  PG_RETURN_FLOAT8(0.0);
2679 
2680  PG_RETURN_FLOAT8(numerator / (N * N));
2681 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8_var_samp()

Datum float8_var_samp ( PG_FUNCTION_ARGS  )

Definition at line 2684 of file float.c.

References check_float8_array(), CHECKFLOATVAL, isinf(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

2685 {
2686  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2687  float8 *transvalues;
2688  float8 N,
2689  sumX,
2690  sumX2,
2691  numerator;
2692 
2693  transvalues = check_float8_array(transarray, "float8_var_samp", 3);
2694  N = transvalues[0];
2695  sumX = transvalues[1];
2696  sumX2 = transvalues[2];
2697 
2698  /* Sample variance is undefined when N is 0 or 1, so return NULL */
2699  if (N <= 1.0)
2700  PG_RETURN_NULL();
2701 
2702  numerator = N * sumX2 - sumX * sumX;
2703  CHECKFLOATVAL(numerator, isinf(sumX2) || isinf(sumX), true);
2704 
2705  /* Watch out for roundoff error producing a negative numerator */
2706  if (numerator <= 0.0)
2707  PG_RETURN_FLOAT8(0.0);
2708 
2709  PG_RETURN_FLOAT8(numerator / (N * (N - 1.0)));
2710 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2471
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ float8abs()

Datum float8abs ( PG_FUNCTION_ARGS  )

Definition at line 731 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

732 {
733  float8 arg1 = PG_GETARG_FLOAT8(0);
734 
735  PG_RETURN_FLOAT8(fabs(arg1));
736 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439

◆ float8div()

Datum float8div ( PG_FUNCTION_ARGS  )

Definition at line 911 of file float.c.

References CHECKFLOATVAL, ereport, errcode(), errmsg(), ERROR, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

912 {
913  float8 arg1 = PG_GETARG_FLOAT8(0);
914  float8 arg2 = PG_GETARG_FLOAT8(1);
915  float8 result;
916 
917  if (arg2 == 0.0)
918  ereport(ERROR,
919  (errcode(ERRCODE_DIVISION_BY_ZERO),
920  errmsg("division by zero")));
921 
922  result = arg1 / arg2;
923 
924  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
925  PG_RETURN_FLOAT8(result);
926 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ float8eq()

Datum float8eq ( PG_FUNCTION_ARGS  )

Definition at line 1083 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

1084 {
1085  float8 arg1 = PG_GETARG_FLOAT8(0);
1086  float8 arg2 = PG_GETARG_FLOAT8(1);
1087 
1088  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) == 0);
1089 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float8ge()

Datum float8ge ( PG_FUNCTION_ARGS  )

Definition at line 1128 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

1129 {
1130  float8 arg1 = PG_GETARG_FLOAT8(0);
1131  float8 arg2 = PG_GETARG_FLOAT8(1);
1132 
1133  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) >= 0);
1134 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float8gt()

Datum float8gt ( PG_FUNCTION_ARGS  )

Definition at line 1119 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

1120 {
1121  float8 arg1 = PG_GETARG_FLOAT8(0);
1122  float8 arg2 = PG_GETARG_FLOAT8(1);
1123 
1124  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) > 0);
1125 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float8in()

Datum float8in ( PG_FUNCTION_ARGS  )

Definition at line 419 of file float.c.

References float8in_internal(), PG_GETARG_CSTRING, and PG_RETURN_FLOAT8.

Referenced by numeric_float8().

420 {
421  char *num = PG_GETARG_CSTRING(0);
422 
423  PG_RETURN_FLOAT8(float8in_internal(num, NULL, "double precision", num));
424 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string)
Definition: float.c:445
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242

◆ float8in_internal()

double float8in_internal ( char *  num,
char **  endptr_p,
const char *  type_name,
const char *  orig_string 
)

Definition at line 445 of file float.c.

References ereport, errcode(), errmsg(), ERROR, get_float8_infinity(), get_float8_nan(), pg_strncasecmp(), pstrdup(), and val.

Referenced by float8in(), pair_decode(), and single_decode().

447 {
448  double val;
449  char *endptr;
450 
451  /* skip leading whitespace */
452  while (*num != '\0' && isspace((unsigned char) *num))
453  num++;
454 
455  /*
456  * Check for an empty-string input to begin with, to avoid the vagaries of
457  * strtod() on different platforms.
458  */
459  if (*num == '\0')
460  ereport(ERROR,
461  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
462  errmsg("invalid input syntax for type %s: \"%s\"",
463  type_name, orig_string)));
464 
465  errno = 0;
466  val = strtod(num, &endptr);
467 
468  /* did we not see anything that looks like a double? */
469  if (endptr == num || errno != 0)
470  {
471  int save_errno = errno;
472 
473  /*
474  * C99 requires that strtod() accept NaN, [+-]Infinity, and [+-]Inf,
475  * but not all platforms support all of these (and some accept them
476  * but set ERANGE anyway...) Therefore, we check for these inputs
477  * ourselves if strtod() fails.
478  *
479  * Note: C99 also requires hexadecimal input as well as some extended
480  * forms of NaN, but we consider these forms unportable and don't try
481  * to support them. You can use 'em if your strtod() takes 'em.
482  */
483  if (pg_strncasecmp(num, "NaN", 3) == 0)
484  {
485  val = get_float8_nan();
486  endptr = num + 3;
487  }
488  else if (pg_strncasecmp(num, "Infinity", 8) == 0)
489  {
490  val = get_float8_infinity();
491  endptr = num + 8;
492  }
493  else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
494  {
495  val = get_float8_infinity();
496  endptr = num + 9;
497  }
498  else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
499  {
500  val = -get_float8_infinity();
501  endptr = num + 9;
502  }
503  else if (pg_strncasecmp(num, "inf", 3) == 0)
504  {
505  val = get_float8_infinity();
506  endptr = num + 3;
507  }
508  else if (pg_strncasecmp(num, "+inf", 4) == 0)
509  {
510  val = get_float8_infinity();
511  endptr = num + 4;
512  }
513  else if (pg_strncasecmp(num, "-inf", 4) == 0)
514  {
515  val = -get_float8_infinity();
516  endptr = num + 4;
517  }
518  else if (save_errno == ERANGE)
519  {
520  /*
521  * Some platforms return ERANGE for denormalized numbers (those
522  * that are not zero, but are too close to zero to have full
523  * precision). We'd prefer not to throw error for that, so try to
524  * detect whether it's a "real" out-of-range condition by checking
525  * to see if the result is zero or huge.
526  *
527  * On error, we intentionally complain about double precision not
528  * the given type name, and we print only the part of the string
529  * that is the current number.
530  */
531  if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL)
532  {
533  char *errnumber = pstrdup(num);
534 
535  errnumber[endptr - num] = '\0';
536  ereport(ERROR,
537  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
538  errmsg("\"%s\" is out of range for type double precision",
539  errnumber)));
540  }
541  }
542  else
543  ereport(ERROR,
544  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
545  errmsg("invalid input syntax for type %s: \"%s\"",
546  type_name, orig_string)));
547  }
548 #ifdef HAVE_BUGGY_SOLARIS_STRTOD
549  else
550  {
551  /*
552  * Many versions of Solaris have a bug wherein strtod sets endptr to
553  * point one byte beyond the end of the string when given "inf" or
554  * "infinity".
555  */
556  if (endptr != num && endptr[-1] == '\0')
557  endptr--;
558  }
559 #endif /* HAVE_BUGGY_SOLARIS_STRTOD */
560 
561  /* skip trailing whitespace */
562  while (*endptr != '\0' && isspace((unsigned char) *endptr))
563  endptr++;
564 
565  /* report stopping point if wanted, else complain if not end of string */
566  if (endptr_p)
567  *endptr_p = endptr;
568  else if (*endptr != '\0')
569  ereport(ERROR,
570  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
571  errmsg("invalid input syntax for type %s: \"%s\"",
572  type_name, orig_string)));
573 
574  return val;
575 }
double get_float8_nan(void)
Definition: float.c:167
char * pstrdup(const char *in)
Definition: mcxt.c:1063
int errcode(int sqlerrcode)
Definition: elog.c:575
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
double get_float8_infinity(void)
Definition: float.c:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
long val
Definition: informix.c:689

◆ float8larger()

Datum float8larger ( PG_FUNCTION_ARGS  )

Definition at line 761 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

762 {
763  float8 arg1 = PG_GETARG_FLOAT8(0);
764  float8 arg2 = PG_GETARG_FLOAT8(1);
765  float8 result;
766 
767  if (float8_cmp_internal(arg1, arg2) > 0)
768  result = arg1;
769  else
770  result = arg2;
771  PG_RETURN_FLOAT8(result);
772 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439

◆ float8le()

Datum float8le ( PG_FUNCTION_ARGS  )

Definition at line 1110 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

1111 {
1112  float8 arg1 = PG_GETARG_FLOAT8(0);
1113  float8 arg2 = PG_GETARG_FLOAT8(1);
1114 
1115  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) <= 0);
1116 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float8lt()

Datum float8lt ( PG_FUNCTION_ARGS  )

Definition at line 1101 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

1102 {
1103  float8 arg1 = PG_GETARG_FLOAT8(0);
1104  float8 arg2 = PG_GETARG_FLOAT8(1);
1105 
1106  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) < 0);
1107 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float8mi()

Datum float8mi ( PG_FUNCTION_ARGS  )

Definition at line 884 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

885 {
886  float8 arg1 = PG_GETARG_FLOAT8(0);
887  float8 arg2 = PG_GETARG_FLOAT8(1);
888  float8 result;
889 
890  result = arg1 - arg2;
891 
892  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
893  PG_RETURN_FLOAT8(result);
894 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float8mul()

Datum float8mul ( PG_FUNCTION_ARGS  )

Definition at line 897 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

898 {
899  float8 arg1 = PG_GETARG_FLOAT8(0);
900  float8 arg2 = PG_GETARG_FLOAT8(1);
901  float8 result;
902 
903  result = arg1 * arg2;
904 
905  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2),
906  arg1 == 0 || arg2 == 0);
907  PG_RETURN_FLOAT8(result);
908 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float8ne()

Datum float8ne ( PG_FUNCTION_ARGS  )

Definition at line 1092 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

1093 {
1094  float8 arg1 = PG_GETARG_FLOAT8(0);
1095  float8 arg2 = PG_GETARG_FLOAT8(1);
1096 
1097  PG_RETURN_BOOL(float8_cmp_internal(arg1, arg2) != 0);
1098 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ float8out()

Datum float8out ( PG_FUNCTION_ARGS  )

Definition at line 582 of file float.c.

References float8out_internal(), PG_GETARG_FLOAT8, and PG_RETURN_CSTRING.

583 {
584  float8 num = PG_GETARG_FLOAT8(0);
585 
587 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
char * float8out_internal(double num)
Definition: float.c:597
double float8
Definition: c.h:439
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322

◆ float8out_internal()

char* float8out_internal ( double  num)

Definition at line 597 of file float.c.

References ascii(), extra_float_digits, is_infinite(), MAXDOUBLEWIDTH, palloc(), and snprintf().

Referenced by cube_out(), float8out(), line_out(), pair_encode(), and single_encode().

598 {
599  char *ascii = (char *) palloc(MAXDOUBLEWIDTH + 1);
600 
601  if (isnan(num))
602  return strcpy(ascii, "NaN");
603 
604  switch (is_infinite(num))
605  {
606  case 1:
607  strcpy(ascii, "Infinity");
608  break;
609  case -1:
610  strcpy(ascii, "-Infinity");
611  break;
612  default:
613  {
614  int ndig = DBL_DIG + extra_float_digits;
615 
616  if (ndig < 1)
617  ndig = 1;
618 
619  snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num);
620  }
621  }
622 
623  return ascii;
624 }
#define MAXDOUBLEWIDTH
Definition: float.c:49
Datum ascii(PG_FUNCTION_ARGS)
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
int extra_float_digits
Definition: float.c:69
int is_infinite(double val)
Definition: float.c:200
void * palloc(Size size)
Definition: mcxt.c:835

◆ float8pl()

Datum float8pl ( PG_FUNCTION_ARGS  )

Definition at line 871 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

872 {
873  float8 arg1 = PG_GETARG_FLOAT8(0);
874  float8 arg2 = PG_GETARG_FLOAT8(1);
875  float8 result;
876 
877  result = arg1 + arg2;
878 
879  CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true);
880  PG_RETURN_FLOAT8(result);
881 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ float8recv()

Datum float8recv ( PG_FUNCTION_ARGS  )

Definition at line 630 of file float.c.

References buf, PG_GETARG_POINTER, PG_RETURN_FLOAT8, and pq_getmsgfloat8().

631 {
633 
635 }
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static char * buf
Definition: pg_test_fsync.c:67
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490

◆ float8send()

Datum float8send ( PG_FUNCTION_ARGS  )

Definition at line 641 of file float.c.

References buf, PG_GETARG_FLOAT8, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendfloat8().

642 {
643  float8 num = PG_GETARG_FLOAT8(0);
645 
646  pq_begintypsend(&buf);
647  pq_sendfloat8(&buf, num);
649 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:278
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
double float8
Definition: c.h:439
static char * buf
Definition: pg_test_fsync.c:67

◆ float8smaller()

Datum float8smaller ( PG_FUNCTION_ARGS  )

Definition at line 775 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

776 {
777  float8 arg1 = PG_GETARG_FLOAT8(0);
778  float8 arg2 = PG_GETARG_FLOAT8(1);
779  float8 result;
780 
781  if (float8_cmp_internal(arg1, arg2) < 0)
782  result = arg1;
783  else
784  result = arg2;
785  PG_RETURN_FLOAT8(result);
786 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:1053
double float8
Definition: c.h:439

◆ float8um()

Datum float8um ( PG_FUNCTION_ARGS  )

Definition at line 743 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

744 {
745  float8 arg1 = PG_GETARG_FLOAT8(0);
746  float8 result;
747 
748  result = -arg1;
749  PG_RETURN_FLOAT8(result);
750 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439

◆ float8up()

Datum float8up ( PG_FUNCTION_ARGS  )

Definition at line 753 of file float.c.

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

754 {
756 
757  PG_RETURN_FLOAT8(arg);
758 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
void * arg

◆ ftod()

Datum ftod ( PG_FUNCTION_ARGS  )

Definition at line 1194 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT8.

1195 {
1196  float4 num = PG_GETARG_FLOAT4(0);
1197 
1198  PG_RETURN_FLOAT8((float8) num);
1199 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:438

◆ ftoi2()

Datum ftoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1298 of file float.c.

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

1299 {
1300  float4 num = PG_GETARG_FLOAT4(0);
1301 
1302  if (num < SHRT_MIN || num > SHRT_MAX || isnan(num))
1303  ereport(ERROR,
1304  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1305  errmsg("smallint out of range")));
1306 
1307  PG_RETURN_INT16((int16) rint(num));
1308 }
signed short int16
Definition: c.h:293
#define PG_RETURN_INT16(x)
Definition: fmgr.h:316
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
double rint(double x)
Definition: rint.c:22
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:438
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ ftoi4()

Datum ftoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1281 of file float.c.

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

1282 {
1283  float4 num = PG_GETARG_FLOAT4(0);
1284 
1285  if (num < INT_MIN || num > INT_MAX || isnan(num))
1286  ereport(ERROR,
1287  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1288  errmsg("integer out of range")));
1289 
1290  PG_RETURN_INT32((int32) rint(num));
1291 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#define ERROR
Definition: elog.h:43
double rint(double x)
Definition: rint.c:22
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
float float4
Definition: c.h:438
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ get_float4_infinity()

float get_float4_infinity ( void  )

Definition at line 147 of file float.c.

Referenced by float4in(), gistpenalty(), leftmostvalue_float4(), and range_gist_penalty().

148 {
149 #ifdef INFINITY
150  /* C99 standard way */
151  return (float) INFINITY;
152 #else
153 #if (_MSC_VER >= 1800)
154 #pragma warning(default:4756)
155 #endif
156 
157  /*
158  * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
159  * largest normal double. We assume forcing an overflow will get us a
160  * true infinity.
161  */
162  return (float) (HUGE_VAL * HUGE_VAL);
163 #endif
164 }

◆ get_float4_nan()

float get_float4_nan ( void  )

Definition at line 180 of file float.c.

Referenced by float4in(), and numeric_float4().

181 {
182 #ifdef NAN
183  /* C99 standard way */
184  return (float) NAN;
185 #else
186  /* Assume we can get a NAN via zero divide */
187  return (float) (0.0 / 0.0);
188 #endif
189 }

◆ get_float8_infinity()

double get_float8_infinity ( void  )

Definition at line 122 of file float.c.

Referenced by compute_range_stats(), dexp(), dpow(), float8in_internal(), gbt_ts_dist(), get_distance(), gistindex_keytest(), initRectBox(), leftmostvalue_float8(), NonFiniteTimestampTzPart(), pg_hypot(), and size_box().

123 {
124 #ifdef INFINITY
125  /* C99 standard way */
126  return (double) INFINITY;
127 #else
128 
129  /*
130  * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
131  * largest normal double. We assume forcing an overflow will get us a
132  * true infinity.
133  */
134  return (double) (HUGE_VAL * HUGE_VAL);
135 #endif
136 }

◆ get_float8_nan()

double get_float8_nan ( void  )

Definition at line 167 of file float.c.

Referenced by dacos(), dacosd(), dasin(), dasind(), datan(), datan2(), datan2d(), datand(), dcos(), dcosd(), dcot(), dcotd(), dsin(), dsind(), dtan(), dtand(), float8in_internal(), numeric_float8(), numeric_float8_no_overflow(), and pg_hypot().

168 {
169  /* (double) NAN doesn't work on some NetBSD/MIPS releases */
170 #if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__))
171  /* C99 standard way */
172  return (double) NAN;
173 #else
174  /* Assume we can get a NAN via zero divide */
175  return (double) (0.0 / 0.0);
176 #endif
177 }

◆ i2tod()

Datum i2tod ( PG_FUNCTION_ARGS  )

Definition at line 1269 of file float.c.

References PG_GETARG_INT16, and PG_RETURN_FLOAT8.

1270 {
1271  int16 num = PG_GETARG_INT16(0);
1272 
1273  PG_RETURN_FLOAT8((float8) num);
1274 }
signed short int16
Definition: c.h:293
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236

◆ i2tof()

Datum i2tof ( PG_FUNCTION_ARGS  )

Definition at line 1327 of file float.c.

References PG_GETARG_INT16, and PG_RETURN_FLOAT4.

1328 {
1329  int16 num = PG_GETARG_INT16(0);
1330 
1331  PG_RETURN_FLOAT4((float4) num);
1332 }
signed short int16
Definition: c.h:293
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
float float4
Definition: c.h:438
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236

◆ i4tod()

Datum i4tod ( PG_FUNCTION_ARGS  )

Definition at line 1257 of file float.c.

References PG_GETARG_INT32, and PG_RETURN_FLOAT8.

1258 {
1259  int32 num = PG_GETARG_INT32(0);
1260 
1261  PG_RETURN_FLOAT8((float8) num);
1262 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
signed int int32
Definition: c.h:294
double float8
Definition: c.h:439

◆ i4tof()

Datum i4tof ( PG_FUNCTION_ARGS  )

Definition at line 1315 of file float.c.

References PG_GETARG_INT32, and PG_RETURN_FLOAT4.

1316 {
1317  int32 num = PG_GETARG_INT32(0);
1318 
1319  PG_RETURN_FLOAT4((float4) num);
1320 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
signed int int32
Definition: c.h:294
float float4
Definition: c.h:438

◆ init_degree_constants()

static void init_degree_constants ( void  )
static

Definition at line 1847 of file float.c.

References acos_0_5, asin_0_5, atan_1_0, cosd_q1(), cot_45, degree_c_forty_five, degree_c_one, degree_c_one_half, degree_c_sixty, degree_c_thirty, degree_consts_set, one_minus_cos_60, RADIANS_PER_DEGREE, sin_30, sind_q1(), and tan_45.

1848 {
1851  asin_0_5 = asin(degree_c_one_half);
1852  acos_0_5 = acos(degree_c_one_half);
1853  atan_1_0 = atan(degree_c_one);
1856  degree_consts_set = true;
1857 }
float8 degree_c_sixty
Definition: float.c:89
static float8 cot_45
Definition: float.c:79
float8 degree_c_one
Definition: float.c:91
float8 degree_c_one_half
Definition: float.c:90
static bool degree_consts_set
Definition: float.c:72
static double sind_q1(double x)
Definition: float.c:2099
static float8 acos_0_5
Definition: float.c:76
float8 degree_c_thirty
Definition: float.c:87
static float8 atan_1_0
Definition: float.c:77
#define RADIANS_PER_DEGREE
Definition: float.c:36
float8 degree_c_forty_five
Definition: float.c:88
static float8 sin_30
Definition: float.c:73
static float8 one_minus_cos_60
Definition: float.c:74
static double cosd_q1(double x)
Definition: float.c:2119
static float8 asin_0_5
Definition: float.c:75
static float8 tan_45
Definition: float.c:78

◆ is_infinite()

int is_infinite ( double  val)

Definition at line 200 of file float.c.

References isinf().

Referenced by calc_length_hist_frac(), float4_to_char(), float4out(), float8_to_char(), float8out_internal(), and get_len_position().

201 {
202  int inf = isinf(val);
203 
204  if (inf == 0)
205  return 0;
206  else if (val > 0)
207  return 1;
208  else
209  return -1;
210 }
int isinf(double x)
long val
Definition: informix.c:689

◆ radians()

Datum radians ( PG_FUNCTION_ARGS  )

Definition at line 2401 of file float.c.

References CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and RADIANS_PER_DEGREE.

2402 {
2403  float8 arg1 = PG_GETARG_FLOAT8(0);
2404  float8 result;
2405 
2406  result = arg1 * RADIANS_PER_DEGREE;
2407 
2408  CHECKFLOATVAL(result, isinf(arg1), arg1 == 0);
2409  PG_RETURN_FLOAT8(result);
2410 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:439
int isinf(double x)
#define RADIANS_PER_DEGREE
Definition: float.c:36
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
Definition: float.c:54

◆ setseed()

Datum setseed ( PG_FUNCTION_ARGS  )

Definition at line 2432 of file float.c.

References elog, ERROR, MAX_RANDOM_VALUE, PG_GETARG_FLOAT8, PG_RETURN_VOID, and srandom().

Referenced by assign_random_seed().

2433 {
2434  float8 seed = PG_GETARG_FLOAT8(0);
2435  int iseed;
2436 
2437  if (seed < -1 || seed > 1)
2438  elog(ERROR, "setseed parameter %f out of range [-1,1]", seed);
2439 
2440  iseed = (int) (seed * MAX_RANDOM_VALUE);
2441  srandom((unsigned int) iseed);
2442 
2443  PG_RETURN_VOID();
2444 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
#define MAX_RANDOM_VALUE
#define PG_RETURN_VOID()
Definition: fmgr.h:309
void srandom(unsigned int seed)
Definition: srandom.c:22
#define elog
Definition: elog.h:219

◆ sind_0_to_30()

static double sind_0_to_30 ( double  x)
static

Definition at line 2072 of file float.c.

References RADIANS_PER_DEGREE, and sin_30.

Referenced by cosd_q1(), and sind_q1().

2073 {
2074  volatile float8 sin_x = sin(x * RADIANS_PER_DEGREE);
2075 
2076  return (sin_x / sin_30) / 2.0;
2077 }
double float8
Definition: c.h:439
#define RADIANS_PER_DEGREE
Definition: float.c:36
static float8 sin_30
Definition: float.c:73

◆ sind_q1()

static double sind_q1 ( double  x)
static

Definition at line 2099 of file float.c.

References cosd_0_to_60(), and sind_0_to_30().

Referenced by dcotd(), dsind(), dtand(), and init_degree_constants().

2100 {
2101  /*
2102  * Stitch together the sine and cosine functions for the ranges [0, 30]
2103  * and (30, 90]. These guarantee to return exact answers at their
2104  * endpoints, so the overall result is a continuous monotonic function
2105  * that gives exact results when x = 0, 30 and 90 degrees.
2106  */
2107  if (x <= 30.0)
2108  return sind_0_to_30(x);
2109  else
2110  return cosd_0_to_60(90.0 - x);
2111 }
static double cosd_0_to_60(double x)
Definition: float.c:2086
static double sind_0_to_30(double x)
Definition: float.c:2072

◆ width_bucket_float8()

Datum width_bucket_float8 ( PG_FUNCTION_ARGS  )

Definition at line 3522 of file float.c.

References ereport, errcode(), errmsg(), ERROR, isinf(), pg_add_s32_overflow(), PG_GETARG_FLOAT8, PG_GETARG_INT32, and PG_RETURN_INT32.

3523 {
3524  float8 operand = PG_GETARG_FLOAT8(0);
3525  float8 bound1 = PG_GETARG_FLOAT8(1);
3526  float8 bound2 = PG_GETARG_FLOAT8(2);
3527  int32 count = PG_GETARG_INT32(3);
3528  int32 result;
3529 
3530  if (count <= 0.0)
3531  ereport(ERROR,
3532  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),
3533  errmsg("count must be greater than zero")));
3534 
3535  if (isnan(operand) || isnan(bound1) || isnan(bound2))
3536  ereport(ERROR,
3537  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),
3538  errmsg("operand, lower bound, and upper bound cannot be NaN")));
3539 
3540  /* Note that we allow "operand" to be infinite */
3541  if (isinf(bound1) || isinf(bound2))
3542  ereport(ERROR,
3543  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),
3544  errmsg("lower and upper bounds must be finite")));
3545 
3546  if (bound1 < bound2)
3547  {
3548  if (operand < bound1)
3549  result = 0;
3550  else if (operand >= bound2)
3551  {
3552  if (pg_add_s32_overflow(count, 1, &result))
3553  ereport(ERROR,
3554  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
3555  errmsg("integer out of range")));
3556  }
3557  else
3558  result = ((float8) count * (operand - bound1) / (bound2 - bound1)) + 1;
3559  }
3560  else if (bound1 > bound2)
3561  {
3562  if (operand > bound1)
3563  result = 0;
3564  else if (operand <= bound2)
3565  {
3566  if (pg_add_s32_overflow(count, 1, &result))
3567  ereport(ERROR,
3568  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
3569  errmsg("integer out of range")));
3570  }
3571  else
3572  result = ((float8) count * (bound1 - operand) / (bound1 - bound2)) + 1;
3573  }
3574  else
3575  {
3576  ereport(ERROR,
3577  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),
3578  errmsg("lower bound cannot equal upper bound")));
3579  result = 0; /* keep the compiler quiet */
3580  }
3581 
3582  PG_RETURN_INT32(result);
3583 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:294
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:439
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:122
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:89
int errmsg(const char *fmt,...)
Definition: elog.c:797

Variable Documentation

◆ acos_0_5

float8 acos_0_5 = 0
static

Definition at line 76 of file float.c.

Referenced by acosd_q1(), asind_q1(), and init_degree_constants().

◆ asin_0_5

float8 asin_0_5 = 0
static

Definition at line 75 of file float.c.

Referenced by acosd_q1(), asind_q1(), and init_degree_constants().

◆ atan_1_0

float8 atan_1_0 = 0
static

Definition at line 77 of file float.c.

Referenced by datan2d(), datand(), and init_degree_constants().

◆ cot_45

float8 cot_45 = 0
static

Definition at line 79 of file float.c.

Referenced by dcotd(), and init_degree_constants().

◆ degree_c_forty_five

float8 degree_c_forty_five = 45.0

Definition at line 88 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_one

float8 degree_c_one = 1.0

Definition at line 91 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_one_half

float8 degree_c_one_half = 0.5

Definition at line 90 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_sixty

float8 degree_c_sixty = 60.0

Definition at line 89 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_thirty

float8 degree_c_thirty = 30.0

Definition at line 87 of file float.c.

Referenced by init_degree_constants().

◆ degree_consts_set

bool degree_consts_set = false
static

Definition at line 72 of file float.c.

Referenced by init_degree_constants().

◆ extra_float_digits

int extra_float_digits = 0

Definition at line 69 of file float.c.

Referenced by float4out(), float8out_internal(), and set_transmission_modes().

◆ one_minus_cos_60

float8 one_minus_cos_60 = 0
static

Definition at line 74 of file float.c.

Referenced by cosd_0_to_60(), and init_degree_constants().

◆ sin_30

float8 sin_30 = 0
static

Definition at line 73 of file float.c.

Referenced by init_degree_constants(), and sind_0_to_30().

◆ tan_45

float8 tan_45 = 0
static

Definition at line 78 of file float.c.

Referenced by dtand(), and init_degree_constants().