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 "common/shortest_dec.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "utils/array.h"
#include "utils/fmgrprotos.h"
#include "utils/sortsupport.h"
#include "utils/timestamp.h"
Include dependency graph for float.c:

Go to the source code of this file.

Macros

#define RETURN_ERROR(throw_error, have_error)
 
#define INIT_DEGREE_CONSTANTS()
 

Functions

static double sind_q1 (double x)
 
static double cosd_q1 (double x)
 
static void init_degree_constants (void)
 
pg_noinline void float_overflow_error (void)
 
pg_noinline void float_underflow_error (void)
 
pg_noinline void float_zero_divide_error (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_opt_error (char *num, char **endptr_p, const char *type_name, const char *orig_string, bool *have_error)
 
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 in_range_float8_float8 (PG_FUNCTION_ARGS)
 
Datum in_range_float4_float8 (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 dsinh (PG_FUNCTION_ARGS)
 
Datum dcosh (PG_FUNCTION_ARGS)
 
Datum dtanh (PG_FUNCTION_ARGS)
 
Datum dasinh (PG_FUNCTION_ARGS)
 
Datum dacosh (PG_FUNCTION_ARGS)
 
Datum datanh (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 = 1
 
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
 
static bool drandom_seed_set = false
 
static unsigned short drandom_seed [3] = {0, 0, 0}
 

Macro Definition Documentation

◆ INIT_DEGREE_CONSTANTS

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

Definition at line 2059 of file float.c.

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

◆ RETURN_ERROR

#define RETURN_ERROR (   throw_error,
  have_error 
)
Value:
do { \
if (have_error) { \
*have_error = true; \
return 0.0; \
} else { \
throw_error; \
} \
} while (0)

Definition at line 359 of file float.c.

Referenced by float8in_internal_opt_error().

Function Documentation

◆ acosd_q1()

static double acosd_q1 ( double  x)
static

Definition at line 2109 of file float.c.

References acos_0_5, and asin_0_5.

Referenced by dacosd().

2110 {
2111  /*
2112  * Stitch together inverse sine and cosine functions for the ranges [0,
2113  * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
2114  * exactly 60 for x=0.5, so the result is a continuous monotonic function
2115  * over the full range.
2116  */
2117  if (x <= 0.5)
2118  {
2119  volatile float8 asin_x = asin(x);
2120 
2121  return 90.0 - (asin_x / asin_0_5) * 30.0;
2122  }
2123  else
2124  {
2125  volatile float8 acos_x = acos(x);
2126 
2127  return (acos_x / acos_0_5) * 60.0;
2128  }
2129 }
static float8 acos_0_5
Definition: float.c:49
double float8
Definition: c.h:498
static float8 asin_0_5
Definition: float.c:48

◆ asind_q1()

static double asind_q1 ( double  x)
static

Definition at line 2076 of file float.c.

References acos_0_5, and asin_0_5.

Referenced by dacosd(), and dasind().

2077 {
2078  /*
2079  * Stitch together inverse sine and cosine functions for the ranges [0,
2080  * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
2081  * exactly 30 for x=0.5, so the result is a continuous monotonic function
2082  * over the full range.
2083  */
2084  if (x <= 0.5)
2085  {
2086  volatile float8 asin_x = asin(x);
2087 
2088  return (asin_x / asin_0_5) * 30.0;
2089  }
2090  else
2091  {
2092  volatile float8 acos_x = acos(x);
2093 
2094  return 90.0 - (acos_x / acos_0_5) * 60.0;
2095  }
2096 }
static float8 acos_0_5
Definition: float.c:49
double float8
Definition: c.h:498
static float8 asin_0_5
Definition: float.c:48

◆ btfloat48cmp()

Datum btfloat48cmp ( PG_FUNCTION_ARGS  )

Definition at line 1029 of file float.c.

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

1030 {
1031  float4 arg1 = PG_GETARG_FLOAT4(0);
1032  float8 arg2 = PG_GETARG_FLOAT8(1);
1033 
1034  /* widen float4 to float8 and then compare */
1035  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1036 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:938
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ btfloat4cmp()

Datum btfloat4cmp ( PG_FUNCTION_ARGS  )

Definition at line 908 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_INT32.

Referenced by leftmostvalue_float4().

909 {
910  float4 arg1 = PG_GETARG_FLOAT4(0);
911  float4 arg2 = PG_GETARG_FLOAT4(1);
912 
914 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:844
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ btfloat4fastcmp()

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

Definition at line 917 of file float.c.

References DatumGetFloat4(), and float4_cmp_internal().

Referenced by btfloat4sortsupport().

918 {
919  float4 arg1 = DatumGetFloat4(x);
920  float4 arg2 = DatumGetFloat4(y);
921 
922  return float4_cmp_internal(arg1, arg2);
923 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:844
static float4 DatumGetFloat4(Datum X)
Definition: postgres.h:664
float float4
Definition: c.h:497

◆ btfloat4sortsupport()

Datum btfloat4sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 926 of file float.c.

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

927 {
929 
930  ssup->comparator = btfloat4fastcmp;
931  PG_RETURN_VOID();
932 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
#define PG_RETURN_VOID()
Definition: fmgr.h:348
static int btfloat4fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: float.c:917

◆ btfloat84cmp()

Datum btfloat84cmp ( PG_FUNCTION_ARGS  )

Definition at line 1039 of file float.c.

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

1040 {
1041  float8 arg1 = PG_GETARG_FLOAT8(0);
1042  float4 arg2 = PG_GETARG_FLOAT4(1);
1043 
1044  /* widen float4 to float8 and then compare */
1045  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1046 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:938
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ btfloat8cmp()

Datum btfloat8cmp ( PG_FUNCTION_ARGS  )

Definition at line 1002 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_INT32.

Referenced by leftmostvalue_float8().

1003 {
1004  float8 arg1 = PG_GETARG_FLOAT8(0);
1005  float8 arg2 = PG_GETARG_FLOAT8(1);
1006 
1007  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1008 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:938
double float8
Definition: c.h:498

◆ btfloat8fastcmp()

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

Definition at line 1011 of file float.c.

References DatumGetFloat8, and float8_cmp_internal().

Referenced by btfloat8sortsupport().

1012 {
1013  float8 arg1 = DatumGetFloat8(x);
1014  float8 arg2 = DatumGetFloat8(y);
1015 
1016  return float8_cmp_internal(arg1, arg2);
1017 }
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:938
double float8
Definition: c.h:498
#define DatumGetFloat8(X)
Definition: postgres.h:714

◆ btfloat8sortsupport()

Datum btfloat8sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 1020 of file float.c.

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

1021 {
1023 
1024  ssup->comparator = btfloat8fastcmp;
1025  PG_RETURN_VOID();
1026 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static int btfloat8fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: float.c:1011
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
#define PG_RETURN_VOID()
Definition: fmgr.h:348

◆ check_float8_array()

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

Definition at line 2886 of file float.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, elog, and ERROR.

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().

2887 {
2888  /*
2889  * We expect the input to be an N-element float array; verify that. We
2890  * don't need to use deconstruct_array() since the array data is just
2891  * going to look like a C array of N float8 values.
2892  */
2893  if (ARR_NDIM(transarray) != 1 ||
2894  ARR_DIMS(transarray)[0] != n ||
2895  ARR_HASNULL(transarray) ||
2896  ARR_ELEMTYPE(transarray) != FLOAT8OID)
2897  elog(ERROR, "%s: expected %d-element float8 array", caller, n);
2898  return (float8 *) ARR_DATA_PTR(transarray);
2899 }
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ARR_DIMS(a)
Definition: array.h:282
#define ARR_DATA_PTR(a)
Definition: array.h:310
#define ARR_HASNULL(a)
Definition: array.h:279
#define ARR_NDIM(a)
Definition: array.h:278
#define elog(elevel,...)
Definition: elog.h:214
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ cosd_0_to_60()

static double cosd_0_to_60 ( double  x)
static

Definition at line 2294 of file float.c.

References one_minus_cos_60, and RADIANS_PER_DEGREE.

Referenced by cosd_q1(), and sind_q1().

2295 {
2296  volatile float8 one_minus_cos_x = 1.0 - cos(x * RADIANS_PER_DEGREE);
2297 
2298  return 1.0 - (one_minus_cos_x / one_minus_cos_60) / 2.0;
2299 }
#define RADIANS_PER_DEGREE
Definition: float.h:26
double float8
Definition: c.h:498
static float8 one_minus_cos_60
Definition: float.c:47

◆ cosd_q1()

static double cosd_q1 ( double  x)
static

Definition at line 2327 of file float.c.

References cosd_0_to_60(), and sind_0_to_30().

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

2328 {
2329  /*
2330  * Stitch together the sine and cosine functions for the ranges [0, 60]
2331  * and (60, 90]. These guarantee to return exact answers at their
2332  * endpoints, so the overall result is a continuous monotonic function
2333  * that gives exact results when x = 0, 60 and 90 degrees.
2334  */
2335  if (x <= 60.0)
2336  return cosd_0_to_60(x);
2337  else
2338  return sind_0_to_30(90.0 - x);
2339 }
static double cosd_0_to_60(double x)
Definition: float.c:2294
static double sind_0_to_30(double x)
Definition: float.c:2280

◆ dacos()

Datum dacos ( PG_FUNCTION_ARGS  )

Definition at line 1783 of file float.c.

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

1784 {
1785  float8 arg1 = PG_GETARG_FLOAT8(0);
1786  float8 result;
1787 
1788  /* Per the POSIX spec, return NaN if the input is NaN */
1789  if (isnan(arg1))
1791 
1792  /*
1793  * The principal branch of the inverse cosine function maps values in the
1794  * range [-1, 1] to values in the range [0, Pi], so we should reject any
1795  * inputs outside that range and the result will always be finite.
1796  */
1797  if (arg1 < -1.0 || arg1 > 1.0)
1798  ereport(ERROR,
1799  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1800  errmsg("input is out of range")));
1801 
1802  result = acos(arg1);
1803  if (unlikely(isinf(result)))
1805 
1806  PG_RETURN_FLOAT8(result);
1807 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dacosd()

Datum dacosd ( PG_FUNCTION_ARGS  )

Definition at line 2136 of file float.c.

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

2137 {
2138  float8 arg1 = PG_GETARG_FLOAT8(0);
2139  float8 result;
2140 
2141  /* Per the POSIX spec, return NaN if the input is NaN */
2142  if (isnan(arg1))
2144 
2146 
2147  /*
2148  * The principal branch of the inverse cosine function maps values in the
2149  * range [-1, 1] to values in the range [0, 180], so we should reject any
2150  * inputs outside that range and the result will always be finite.
2151  */
2152  if (arg1 < -1.0 || arg1 > 1.0)
2153  ereport(ERROR,
2154  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2155  errmsg("input is out of range")));
2156 
2157  if (arg1 >= 0.0)
2158  result = acosd_q1(arg1);
2159  else
2160  result = 90.0 + asind_q1(-arg1);
2161 
2162  if (unlikely(isinf(result)))
2164 
2165  PG_RETURN_FLOAT8(result);
2166 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
static double asind_q1(double x)
Definition: float.c:2076
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static double acosd_q1(double x)
Definition: float.c:2109
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dacosh()

Datum dacosh ( PG_FUNCTION_ARGS  )

Definition at line 2717 of file float.c.

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

2718 {
2719  float8 arg1 = PG_GETARG_FLOAT8(0);
2720  float8 result;
2721 
2722  /*
2723  * acosh is only defined for inputs >= 1.0. By checking this ourselves,
2724  * we need not worry about checking for an EDOM error, which is a good
2725  * thing because some implementations will report that for NaN. Otherwise,
2726  * no error is possible.
2727  */
2728  if (arg1 < 1.0)
2729  ereport(ERROR,
2730  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2731  errmsg("input is out of range")));
2732 
2733  result = acosh(arg1);
2734 
2735  PG_RETURN_FLOAT8(result);
2736 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ dasin()

Datum dasin ( PG_FUNCTION_ARGS  )

Definition at line 1814 of file float.c.

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

1815 {
1816  float8 arg1 = PG_GETARG_FLOAT8(0);
1817  float8 result;
1818 
1819  /* Per the POSIX spec, return NaN if the input is NaN */
1820  if (isnan(arg1))
1822 
1823  /*
1824  * The principal branch of the inverse sine function maps values in the
1825  * range [-1, 1] to values in the range [-Pi/2, Pi/2], so we should reject
1826  * any inputs outside that range and the result will always be finite.
1827  */
1828  if (arg1 < -1.0 || arg1 > 1.0)
1829  ereport(ERROR,
1830  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1831  errmsg("input is out of range")));
1832 
1833  result = asin(arg1);
1834  if (unlikely(isinf(result)))
1836 
1837  PG_RETURN_FLOAT8(result);
1838 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dasind()

Datum dasind ( PG_FUNCTION_ARGS  )

Definition at line 2173 of file float.c.

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

2174 {
2175  float8 arg1 = PG_GETARG_FLOAT8(0);
2176  float8 result;
2177 
2178  /* Per the POSIX spec, return NaN if the input is NaN */
2179  if (isnan(arg1))
2181 
2183 
2184  /*
2185  * The principal branch of the inverse sine function maps values in the
2186  * range [-1, 1] to values in the range [-90, 90], so we should reject any
2187  * inputs outside that range and the result will always be finite.
2188  */
2189  if (arg1 < -1.0 || arg1 > 1.0)
2190  ereport(ERROR,
2191  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2192  errmsg("input is out of range")));
2193 
2194  if (arg1 >= 0.0)
2195  result = asind_q1(arg1);
2196  else
2197  result = -asind_q1(-arg1);
2198 
2199  if (unlikely(isinf(result)))
2201 
2202  PG_RETURN_FLOAT8(result);
2203 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
static double asind_q1(double x)
Definition: float.c:2076
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dasinh()

Datum dasinh ( PG_FUNCTION_ARGS  )

Definition at line 2700 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

2701 {
2702  float8 arg1 = PG_GETARG_FLOAT8(0);
2703  float8 result;
2704 
2705  /*
2706  * For asinh, we don't need an errno check because it never overflows.
2707  */
2708  result = asinh(arg1);
2709 
2710  PG_RETURN_FLOAT8(result);
2711 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ datan()

Datum datan ( PG_FUNCTION_ARGS  )

Definition at line 1845 of file float.c.

References float_overflow_error(), get_float8_nan(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1846 {
1847  float8 arg1 = PG_GETARG_FLOAT8(0);
1848  float8 result;
1849 
1850  /* Per the POSIX spec, return NaN if the input is NaN */
1851  if (isnan(arg1))
1853 
1854  /*
1855  * The principal branch of the inverse tangent function maps all inputs to
1856  * values in the range [-Pi/2, Pi/2], so the result should always be
1857  * finite, even if the input is infinite.
1858  */
1859  result = atan(arg1);
1860  if (unlikely(isinf(result)))
1862 
1863  PG_RETURN_FLOAT8(result);
1864 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ datan2()

Datum datan2 ( PG_FUNCTION_ARGS  )

Definition at line 1871 of file float.c.

References float_overflow_error(), get_float8_nan(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1872 {
1873  float8 arg1 = PG_GETARG_FLOAT8(0);
1874  float8 arg2 = PG_GETARG_FLOAT8(1);
1875  float8 result;
1876 
1877  /* Per the POSIX spec, return NaN if either input is NaN */
1878  if (isnan(arg1) || isnan(arg2))
1880 
1881  /*
1882  * atan2 maps all inputs to values in the range [-Pi, Pi], so the result
1883  * should always be finite, even if the inputs are infinite.
1884  */
1885  result = atan2(arg1, arg2);
1886  if (unlikely(isinf(result)))
1888 
1889  PG_RETURN_FLOAT8(result);
1890 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ datan2d()

Datum datan2d ( PG_FUNCTION_ARGS  )

Definition at line 2242 of file float.c.

References atan_1_0, float_overflow_error(), get_float8_nan(), INIT_DEGREE_CONSTANTS, PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

2243 {
2244  float8 arg1 = PG_GETARG_FLOAT8(0);
2245  float8 arg2 = PG_GETARG_FLOAT8(1);
2246  float8 result;
2247  volatile float8 atan2_arg1_arg2;
2248 
2249  /* Per the POSIX spec, return NaN if either input is NaN */
2250  if (isnan(arg1) || isnan(arg2))
2252 
2254 
2255  /*
2256  * atan2d maps all inputs to values in the range [-180, 180], so the
2257  * result should always be finite, even if the inputs are infinite.
2258  *
2259  * Note: this coding assumes that atan(1.0) is a suitable scaling constant
2260  * to get an exact result from atan2(). This might well fail on us at
2261  * some point, requiring us to decide exactly what inputs we think we're
2262  * going to guarantee an exact result for.
2263  */
2264  atan2_arg1_arg2 = atan2(arg1, arg2);
2265  result = (atan2_arg1_arg2 / atan_1_0) * 45.0;
2266 
2267  if (unlikely(isinf(result)))
2269 
2270  PG_RETURN_FLOAT8(result);
2271 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
static float8 atan_1_0
Definition: float.c:50
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ datand()

Datum datand ( PG_FUNCTION_ARGS  )

Definition at line 2210 of file float.c.

References atan_1_0, float_overflow_error(), get_float8_nan(), INIT_DEGREE_CONSTANTS, PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

2211 {
2212  float8 arg1 = PG_GETARG_FLOAT8(0);
2213  float8 result;
2214  volatile float8 atan_arg1;
2215 
2216  /* Per the POSIX spec, return NaN if the input is NaN */
2217  if (isnan(arg1))
2219 
2221 
2222  /*
2223  * The principal branch of the inverse tangent function maps all inputs to
2224  * values in the range [-90, 90], so the result should always be finite,
2225  * even if the input is infinite. Additionally, we take care to ensure
2226  * than when arg1 is 1, the result is exactly 45.
2227  */
2228  atan_arg1 = atan(arg1);
2229  result = (atan_arg1 / atan_1_0) * 45.0;
2230 
2231  if (unlikely(isinf(result)))
2233 
2234  PG_RETURN_FLOAT8(result);
2235 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
static float8 atan_1_0
Definition: float.c:50
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ datanh()

Datum datanh ( PG_FUNCTION_ARGS  )

Definition at line 2742 of file float.c.

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

2743 {
2744  float8 arg1 = PG_GETARG_FLOAT8(0);
2745  float8 result;
2746 
2747  /*
2748  * atanh is only defined for inputs between -1 and 1. By checking this
2749  * ourselves, we need not worry about checking for an EDOM error, which is
2750  * a good thing because some implementations will report that for NaN.
2751  */
2752  if (arg1 < -1.0 || arg1 > 1.0)
2753  ereport(ERROR,
2754  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2755  errmsg("input is out of range")));
2756 
2757  /*
2758  * Also handle the infinity cases ourselves; this is helpful because old
2759  * glibc versions may produce the wrong errno for this. All other inputs
2760  * cannot produce an error.
2761  */
2762  if (arg1 == -1.0)
2763  result = -get_float8_infinity();
2764  else if (arg1 == 1.0)
2765  result = get_float8_infinity();
2766  else
2767  result = atanh(arg1);
2768 
2769  PG_RETURN_FLOAT8(result);
2770 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static float8 get_float8_infinity(void)
Definition: float.h:93
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ dcbrt()

Datum dcbrt ( PG_FUNCTION_ARGS  )

Definition at line 1498 of file float.c.

References float_overflow_error(), float_underflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1499 {
1500  float8 arg1 = PG_GETARG_FLOAT8(0);
1501  float8 result;
1502 
1503  result = cbrt(arg1);
1504  if (unlikely(isinf(result)) && !isinf(arg1))
1506  if (unlikely(result == 0.0) && arg1 != 0.0)
1508 
1509  PG_RETURN_FLOAT8(result);
1510 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:498
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ dceil()

Datum dceil ( PG_FUNCTION_ARGS  )

Definition at line 1408 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1409 {
1410  float8 arg1 = PG_GETARG_FLOAT8(0);
1411 
1412  PG_RETURN_FLOAT8(ceil(arg1));
1413 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ dcos()

Datum dcos ( PG_FUNCTION_ARGS  )

Definition at line 1897 of file float.c.

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

1898 {
1899  float8 arg1 = PG_GETARG_FLOAT8(0);
1900  float8 result;
1901 
1902  /* Per the POSIX spec, return NaN if the input is NaN */
1903  if (isnan(arg1))
1905 
1906  /*
1907  * cos() is periodic and so theoretically can work for all finite inputs,
1908  * but some implementations may choose to throw error if the input is so
1909  * large that there are no significant digits in the result. So we should
1910  * check for errors. POSIX allows an error to be reported either via
1911  * errno or via fetestexcept(), but currently we only support checking
1912  * errno. (fetestexcept() is rumored to report underflow unreasonably
1913  * early on some platforms, so it's not clear that believing it would be a
1914  * net improvement anyway.)
1915  *
1916  * For infinite inputs, POSIX specifies that the trigonometric functions
1917  * should return a domain error; but we won't notice that unless the
1918  * platform reports via errno, so also explicitly test for infinite
1919  * inputs.
1920  */
1921  errno = 0;
1922  result = cos(arg1);
1923  if (errno != 0 || isinf(arg1))
1924  ereport(ERROR,
1925  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1926  errmsg("input is out of range")));
1927  if (unlikely(isinf(result)))
1929 
1930  PG_RETURN_FLOAT8(result);
1931 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dcosd()

Datum dcosd ( PG_FUNCTION_ARGS  )

Definition at line 2346 of file float.c.

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

2347 {
2348  float8 arg1 = PG_GETARG_FLOAT8(0);
2349  float8 result;
2350  int sign = 1;
2351 
2352  /*
2353  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2354  * if the input is infinite.
2355  */
2356  if (isnan(arg1))
2358 
2359  if (isinf(arg1))
2360  ereport(ERROR,
2361  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2362  errmsg("input is out of range")));
2363 
2365 
2366  /* Reduce the range of the input to [0,90] degrees */
2367  arg1 = fmod(arg1, 360.0);
2368 
2369  if (arg1 < 0.0)
2370  {
2371  /* cosd(-x) = cosd(x) */
2372  arg1 = -arg1;
2373  }
2374 
2375  if (arg1 > 180.0)
2376  {
2377  /* cosd(360-x) = cosd(x) */
2378  arg1 = 360.0 - arg1;
2379  }
2380 
2381  if (arg1 > 90.0)
2382  {
2383  /* cosd(180-x) = -cosd(x) */
2384  arg1 = 180.0 - arg1;
2385  sign = -sign;
2386  }
2387 
2388  result = sign * cosd_q1(arg1);
2389 
2390  if (unlikely(isinf(result)))
2392 
2393  PG_RETURN_FLOAT8(result);
2394 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
char sign
Definition: informix.c:668
static double cosd_q1(double x)
Definition: float.c:2327
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dcosh()

Datum dcosh ( PG_FUNCTION_ARGS  )

Definition at line 2655 of file float.c.

References float_underflow_error(), get_float8_infinity(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

2656 {
2657  float8 arg1 = PG_GETARG_FLOAT8(0);
2658  float8 result;
2659 
2660  errno = 0;
2661  result = cosh(arg1);
2662 
2663  /*
2664  * if an ERANGE error occurs, it means there is an overflow. As cosh is
2665  * always positive, it always means the result is positive infinity.
2666  */
2667  if (errno == ERANGE)
2668  result = get_float8_infinity();
2669 
2670  if (unlikely(result == 0.0))
2672 
2673  PG_RETURN_FLOAT8(result);
2674 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static float8 get_float8_infinity(void)
Definition: float.h:93
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:498
#define unlikely(x)
Definition: c.h:206

◆ dcot()

Datum dcot ( PG_FUNCTION_ARGS  )

Definition at line 1938 of file float.c.

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

1939 {
1940  float8 arg1 = PG_GETARG_FLOAT8(0);
1941  float8 result;
1942 
1943  /* Per the POSIX spec, return NaN if the input is NaN */
1944  if (isnan(arg1))
1946 
1947  /* Be sure to throw an error if the input is infinite --- see dcos() */
1948  errno = 0;
1949  result = tan(arg1);
1950  if (errno != 0 || isinf(arg1))
1951  ereport(ERROR,
1952  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1953  errmsg("input is out of range")));
1954 
1955  result = 1.0 / result;
1956  /* Not checking for overflow because cot(0) == Inf */
1957 
1958  PG_RETURN_FLOAT8(result);
1959 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ dcotd()

Datum dcotd ( PG_FUNCTION_ARGS  )

Definition at line 2401 of file float.c.

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

2402 {
2403  float8 arg1 = PG_GETARG_FLOAT8(0);
2404  float8 result;
2405  volatile float8 cot_arg1;
2406  int sign = 1;
2407 
2408  /*
2409  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2410  * if the input is infinite.
2411  */
2412  if (isnan(arg1))
2414 
2415  if (isinf(arg1))
2416  ereport(ERROR,
2417  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2418  errmsg("input is out of range")));
2419 
2421 
2422  /* Reduce the range of the input to [0,90] degrees */
2423  arg1 = fmod(arg1, 360.0);
2424 
2425  if (arg1 < 0.0)
2426  {
2427  /* cotd(-x) = -cotd(x) */
2428  arg1 = -arg1;
2429  sign = -sign;
2430  }
2431 
2432  if (arg1 > 180.0)
2433  {
2434  /* cotd(360-x) = -cotd(x) */
2435  arg1 = 360.0 - arg1;
2436  sign = -sign;
2437  }
2438 
2439  if (arg1 > 90.0)
2440  {
2441  /* cotd(180-x) = -cotd(x) */
2442  arg1 = 180.0 - arg1;
2443  sign = -sign;
2444  }
2445 
2446  cot_arg1 = cosd_q1(arg1) / sind_q1(arg1);
2447  result = sign * (cot_arg1 / cot_45);
2448 
2449  /*
2450  * On some machines we get cotd(270) = minus zero, but this isn't always
2451  * true. For portability, and because the user constituency for this
2452  * function probably doesn't want minus zero, force it to plain zero.
2453  */
2454  if (result == 0.0)
2455  result = 0.0;
2456 
2457  /* Not checking for overflow because cotd(0) == Inf */
2458 
2459  PG_RETURN_FLOAT8(result);
2460 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static float8 cot_45
Definition: float.c:52
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
static double sind_q1(double x)
Definition: float.c:2307
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
char sign
Definition: informix.c:668
static double cosd_q1(double x)
Definition: float.c:2327
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ degrees()

Datum degrees ( PG_FUNCTION_ARGS  )

Definition at line 2589 of file float.c.

References float8_div(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and RADIANS_PER_DEGREE.

2590 {
2591  float8 arg1 = PG_GETARG_FLOAT8(0);
2592 
2594 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define RADIANS_PER_DEGREE
Definition: float.h:26
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ dexp()

Datum dexp ( PG_FUNCTION_ARGS  )

Definition at line 1672 of file float.c.

References float_overflow_error(), float_underflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1673 {
1674  float8 arg1 = PG_GETARG_FLOAT8(0);
1675  float8 result;
1676 
1677  /*
1678  * Handle NaN and Inf cases explicitly. This avoids needing to assume
1679  * that the platform's exp() conforms to POSIX for these cases, and it
1680  * removes some edge cases for the overflow checks below.
1681  */
1682  if (isnan(arg1))
1683  result = arg1;
1684  else if (isinf(arg1))
1685  {
1686  /* Per POSIX, exp(-Inf) is 0 */
1687  result = (arg1 > 0.0) ? arg1 : 0;
1688  }
1689  else
1690  {
1691  /*
1692  * On some platforms, exp() will not set errno but just return Inf or
1693  * zero to report overflow/underflow; therefore, test both cases.
1694  */
1695  errno = 0;
1696  result = exp(arg1);
1697  if (unlikely(errno == ERANGE))
1698  {
1699  if (result != 0.0)
1701  else
1703  }
1704  else if (unlikely(isinf(result)))
1706  else if (unlikely(result == 0.0))
1708  }
1709 
1710  PG_RETURN_FLOAT8(result);
1711 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:498
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ dfloor()

Datum dfloor ( PG_FUNCTION_ARGS  )

Definition at line 1420 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1421 {
1422  float8 arg1 = PG_GETARG_FLOAT8(0);
1423 
1424  PG_RETURN_FLOAT8(floor(arg1));
1425 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ dlog1()

Datum dlog1 ( PG_FUNCTION_ARGS  )

Definition at line 1718 of file float.c.

References ereport, errcode(), errmsg(), ERROR, float_overflow_error(), float_underflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1719 {
1720  float8 arg1 = PG_GETARG_FLOAT8(0);
1721  float8 result;
1722 
1723  /*
1724  * Emit particular SQLSTATE error codes for ln(). This is required by the
1725  * SQL standard.
1726  */
1727  if (arg1 == 0.0)
1728  ereport(ERROR,
1729  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1730  errmsg("cannot take logarithm of zero")));
1731  if (arg1 < 0)
1732  ereport(ERROR,
1733  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1734  errmsg("cannot take logarithm of a negative number")));
1735 
1736  result = log(arg1);
1737  if (unlikely(isinf(result)) && !isinf(arg1))
1739  if (unlikely(result == 0.0) && arg1 != 1.0)
1741 
1742  PG_RETURN_FLOAT8(result);
1743 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
pg_noinline void float_underflow_error(void)
Definition: float.c:92
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dlog10()

Datum dlog10 ( PG_FUNCTION_ARGS  )

Definition at line 1750 of file float.c.

References ereport, errcode(), errmsg(), ERROR, float_overflow_error(), float_underflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1751 {
1752  float8 arg1 = PG_GETARG_FLOAT8(0);
1753  float8 result;
1754 
1755  /*
1756  * Emit particular SQLSTATE error codes for log(). The SQL spec doesn't
1757  * define log(), but it does define ln(), so it makes sense to emit the
1758  * same error code for an analogous error condition.
1759  */
1760  if (arg1 == 0.0)
1761  ereport(ERROR,
1762  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1763  errmsg("cannot take logarithm of zero")));
1764  if (arg1 < 0)
1765  ereport(ERROR,
1766  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1767  errmsg("cannot take logarithm of a negative number")));
1768 
1769  result = log10(arg1);
1770  if (unlikely(isinf(result)) && !isinf(arg1))
1772  if (unlikely(result == 0.0) && arg1 != 1.0)
1774 
1775  PG_RETURN_FLOAT8(result);
1776 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
pg_noinline void float_underflow_error(void)
Definition: float.c:92
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dpi()

Definition at line 2601 of file float.c.

References M_PI, and PG_RETURN_FLOAT8.

2602 {
2604 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define M_PI
Definition: earthdistance.c:10

◆ dpow()

Datum dpow ( PG_FUNCTION_ARGS  )

Definition at line 1517 of file float.c.

References ereport, errcode(), errmsg(), ERROR, float_overflow_error(), float_underflow_error(), get_float8_nan(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1518 {
1519  float8 arg1 = PG_GETARG_FLOAT8(0);
1520  float8 arg2 = PG_GETARG_FLOAT8(1);
1521  float8 result;
1522 
1523  /*
1524  * The POSIX spec says that NaN ^ 0 = 1, and 1 ^ NaN = 1, while all other
1525  * cases with NaN inputs yield NaN (with no error). Many older platforms
1526  * get one or more of these cases wrong, so deal with them via explicit
1527  * logic rather than trusting pow(3).
1528  */
1529  if (isnan(arg1))
1530  {
1531  if (isnan(arg2) || arg2 != 0.0)
1533  PG_RETURN_FLOAT8(1.0);
1534  }
1535  if (isnan(arg2))
1536  {
1537  if (arg1 != 1.0)
1539  PG_RETURN_FLOAT8(1.0);
1540  }
1541 
1542  /*
1543  * The SQL spec requires that we emit a particular SQLSTATE error code for
1544  * certain error conditions. Specifically, we don't return a
1545  * divide-by-zero error code for 0 ^ -1.
1546  */
1547  if (arg1 == 0 && arg2 < 0)
1548  ereport(ERROR,
1549  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1550  errmsg("zero raised to a negative power is undefined")));
1551  if (arg1 < 0 && floor(arg2) != arg2)
1552  ereport(ERROR,
1553  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1554  errmsg("a negative number raised to a non-integer power yields a complex result")));
1555 
1556  /*
1557  * We don't trust the platform's pow() to handle infinity cases per POSIX
1558  * spec either, so deal with those explicitly too. It's easier to handle
1559  * infinite y first, so that it doesn't matter if x is also infinite.
1560  */
1561  if (isinf(arg2))
1562  {
1563  float8 absx = fabs(arg1);
1564 
1565  if (absx == 1.0)
1566  result = 1.0;
1567  else if (arg2 > 0.0) /* y = +Inf */
1568  {
1569  if (absx > 1.0)
1570  result = arg2;
1571  else
1572  result = 0.0;
1573  }
1574  else /* y = -Inf */
1575  {
1576  if (absx > 1.0)
1577  result = 0.0;
1578  else
1579  result = -arg2;
1580  }
1581  }
1582  else if (isinf(arg1))
1583  {
1584  if (arg2 == 0.0)
1585  result = 1.0;
1586  else if (arg1 > 0.0) /* x = +Inf */
1587  {
1588  if (arg2 > 0.0)
1589  result = arg1;
1590  else
1591  result = 0.0;
1592  }
1593  else /* x = -Inf */
1594  {
1595  /*
1596  * Per POSIX, the sign of the result depends on whether y is an
1597  * odd integer. Since x < 0, we already know from the previous
1598  * domain check that y is an integer. It is odd if y/2 is not
1599  * also an integer.
1600  */
1601  float8 halfy = arg2 / 2; /* should be computed exactly */
1602  bool yisoddinteger = (floor(halfy) != halfy);
1603 
1604  if (arg2 > 0.0)
1605  result = yisoddinteger ? arg1 : -arg1;
1606  else
1607  result = yisoddinteger ? -0.0 : 0.0;
1608  }
1609  }
1610  else
1611  {
1612  /*
1613  * pow() sets errno on only some platforms, depending on whether it
1614  * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we must check both
1615  * errno and invalid output values. (We can't rely on just the
1616  * latter, either; some old platforms return a large-but-finite
1617  * HUGE_VAL when reporting overflow.)
1618  */
1619  errno = 0;
1620  result = pow(arg1, arg2);
1621  if (errno == EDOM || isnan(result))
1622  {
1623  /*
1624  * We handled all possible domain errors above, so this should be
1625  * impossible. However, old glibc versions on x86 have a bug that
1626  * causes them to fail this way for abs(y) greater than 2^63:
1627  *
1628  * https://sourceware.org/bugzilla/show_bug.cgi?id=3866
1629  *
1630  * Hence, if we get here, assume y is finite but large (large
1631  * enough to be certainly even). The result should be 0 if x == 0,
1632  * 1.0 if abs(x) == 1.0, otherwise an overflow or underflow error.
1633  */
1634  if (arg1 == 0.0)
1635  result = 0.0; /* we already verified y is positive */
1636  else
1637  {
1638  float8 absx = fabs(arg1);
1639 
1640  if (absx == 1.0)
1641  result = 1.0;
1642  else if (arg2 >= 0.0 ? (absx > 1.0) : (absx < 1.0))
1644  else
1646  }
1647  }
1648  else if (errno == ERANGE)
1649  {
1650  if (result != 0.0)
1652  else
1654  }
1655  else
1656  {
1657  if (unlikely(isinf(result)))
1659  if (unlikely(result == 0.0) && arg1 != 0.0)
1661  }
1662  }
1663 
1664  PG_RETURN_FLOAT8(result);
1665 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
pg_noinline void float_underflow_error(void)
Definition: float.c:92
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ drandom()

Datum drandom ( PG_FUNCTION_ARGS  )

Definition at line 2777 of file float.c.

References drandom_seed, drandom_seed_set, GetCurrentTimestamp(), MyProcPid, now(), pg_erand48(), PG_RETURN_FLOAT8, pg_strong_random(), and unlikely.

2778 {
2779  float8 result;
2780 
2781  /* Initialize random seed, if not done yet in this process */
2782  if (unlikely(!drandom_seed_set))
2783  {
2784  /*
2785  * If possible, initialize the seed using high-quality random bits.
2786  * Should that fail for some reason, we fall back on a lower-quality
2787  * seed based on current time and PID.
2788  */
2790  {
2792  uint64 iseed;
2793 
2794  /* Mix the PID with the most predictable bits of the timestamp */
2795  iseed = (uint64) now ^ ((uint64) MyProcPid << 32);
2796  drandom_seed[0] = (unsigned short) iseed;
2797  drandom_seed[1] = (unsigned short) (iseed >> 16);
2798  drandom_seed[2] = (unsigned short) (iseed >> 32);
2799  }
2800  drandom_seed_set = true;
2801  }
2802 
2803  /* pg_erand48 produces desired result range [0.0 - 1.0) */
2804  result = pg_erand48(drandom_seed);
2805 
2806  PG_RETURN_FLOAT8(result);
2807 }
int MyProcPid
Definition: globals.c:40
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1574
int64 TimestampTz
Definition: timestamp.h:39
static unsigned short drandom_seed[3]
Definition: float.c:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
static bool drandom_seed_set
Definition: float.c:67
double float8
Definition: c.h:498
double pg_erand48(unsigned short xseed[3])
Definition: erand48.c:88
bool pg_strong_random(void *buf, size_t len)
#define unlikely(x)
Definition: c.h:206
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1538

◆ dround()

Datum dround ( PG_FUNCTION_ARGS  )

Definition at line 1396 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1397 {
1398  float8 arg1 = PG_GETARG_FLOAT8(0);
1399 
1400  PG_RETURN_FLOAT8(rint(arg1));
1401 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ dsign()

Datum dsign ( PG_FUNCTION_ARGS  )

Definition at line 1433 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1434 {
1435  float8 arg1 = PG_GETARG_FLOAT8(0);
1436  float8 result;
1437 
1438  if (arg1 > 0)
1439  result = 1.0;
1440  else if (arg1 < 0)
1441  result = -1.0;
1442  else
1443  result = 0.0;
1444 
1445  PG_RETURN_FLOAT8(result);
1446 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ dsin()

Datum dsin ( PG_FUNCTION_ARGS  )

Definition at line 1966 of file float.c.

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

1967 {
1968  float8 arg1 = PG_GETARG_FLOAT8(0);
1969  float8 result;
1970 
1971  /* Per the POSIX spec, return NaN if the input is NaN */
1972  if (isnan(arg1))
1974 
1975  /* Be sure to throw an error if the input is infinite --- see dcos() */
1976  errno = 0;
1977  result = sin(arg1);
1978  if (errno != 0 || isinf(arg1))
1979  ereport(ERROR,
1980  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1981  errmsg("input is out of range")));
1982  if (unlikely(isinf(result)))
1984 
1985  PG_RETURN_FLOAT8(result);
1986 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dsind()

Datum dsind ( PG_FUNCTION_ARGS  )

Definition at line 2467 of file float.c.

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

2468 {
2469  float8 arg1 = PG_GETARG_FLOAT8(0);
2470  float8 result;
2471  int sign = 1;
2472 
2473  /*
2474  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2475  * if the input is infinite.
2476  */
2477  if (isnan(arg1))
2479 
2480  if (isinf(arg1))
2481  ereport(ERROR,
2482  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2483  errmsg("input is out of range")));
2484 
2486 
2487  /* Reduce the range of the input to [0,90] degrees */
2488  arg1 = fmod(arg1, 360.0);
2489 
2490  if (arg1 < 0.0)
2491  {
2492  /* sind(-x) = -sind(x) */
2493  arg1 = -arg1;
2494  sign = -sign;
2495  }
2496 
2497  if (arg1 > 180.0)
2498  {
2499  /* sind(360-x) = -sind(x) */
2500  arg1 = 360.0 - arg1;
2501  sign = -sign;
2502  }
2503 
2504  if (arg1 > 90.0)
2505  {
2506  /* sind(180-x) = sind(x) */
2507  arg1 = 180.0 - arg1;
2508  }
2509 
2510  result = sign * sind_q1(arg1);
2511 
2512  if (unlikely(isinf(result)))
2514 
2515  PG_RETURN_FLOAT8(result);
2516 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
static double sind_q1(double x)
Definition: float.c:2307
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
char sign
Definition: informix.c:668
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dsinh()

Datum dsinh ( PG_FUNCTION_ARGS  )

Definition at line 2626 of file float.c.

References get_float8_infinity(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

2627 {
2628  float8 arg1 = PG_GETARG_FLOAT8(0);
2629  float8 result;
2630 
2631  errno = 0;
2632  result = sinh(arg1);
2633 
2634  /*
2635  * if an ERANGE error occurs, it means there is an overflow. For sinh,
2636  * the result should be either -infinity or infinity, depending on the
2637  * sign of arg1.
2638  */
2639  if (errno == ERANGE)
2640  {
2641  if (arg1 < 0)
2642  result = -get_float8_infinity();
2643  else
2644  result = get_float8_infinity();
2645  }
2646 
2647  PG_RETURN_FLOAT8(result);
2648 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static float8 get_float8_infinity(void)
Definition: float.h:93
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ dsqrt()

Datum dsqrt ( PG_FUNCTION_ARGS  )

Definition at line 1474 of file float.c.

References ereport, errcode(), errmsg(), ERROR, float_overflow_error(), float_underflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

1475 {
1476  float8 arg1 = PG_GETARG_FLOAT8(0);
1477  float8 result;
1478 
1479  if (arg1 < 0)
1480  ereport(ERROR,
1481  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1482  errmsg("cannot take square root of a negative number")));
1483 
1484  result = sqrt(arg1);
1485  if (unlikely(isinf(result)) && !isinf(arg1))
1487  if (unlikely(result == 0.0) && arg1 != 0.0)
1489 
1490  PG_RETURN_FLOAT8(result);
1491 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
pg_noinline void float_underflow_error(void)
Definition: float.c:92
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ereport(elevel,...)
Definition: elog.h:144
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dtan()

Datum dtan ( PG_FUNCTION_ARGS  )

Definition at line 1993 of file float.c.

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

1994 {
1995  float8 arg1 = PG_GETARG_FLOAT8(0);
1996  float8 result;
1997 
1998  /* Per the POSIX spec, return NaN if the input is NaN */
1999  if (isnan(arg1))
2001 
2002  /* Be sure to throw an error if the input is infinite --- see dcos() */
2003  errno = 0;
2004  result = tan(arg1);
2005  if (errno != 0 || isinf(arg1))
2006  ereport(ERROR,
2007  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2008  errmsg("input is out of range")));
2009  /* Not checking for overflow because tan(pi/2) == Inf */
2010 
2011  PG_RETURN_FLOAT8(result);
2012 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ dtand()

Datum dtand ( PG_FUNCTION_ARGS  )

Definition at line 2523 of file float.c.

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

2524 {
2525  float8 arg1 = PG_GETARG_FLOAT8(0);
2526  float8 result;
2527  volatile float8 tan_arg1;
2528  int sign = 1;
2529 
2530  /*
2531  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2532  * if the input is infinite.
2533  */
2534  if (isnan(arg1))
2536 
2537  if (isinf(arg1))
2538  ereport(ERROR,
2539  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2540  errmsg("input is out of range")));
2541 
2543 
2544  /* Reduce the range of the input to [0,90] degrees */
2545  arg1 = fmod(arg1, 360.0);
2546 
2547  if (arg1 < 0.0)
2548  {
2549  /* tand(-x) = -tand(x) */
2550  arg1 = -arg1;
2551  sign = -sign;
2552  }
2553 
2554  if (arg1 > 180.0)
2555  {
2556  /* tand(360-x) = -tand(x) */
2557  arg1 = 360.0 - arg1;
2558  sign = -sign;
2559  }
2560 
2561  if (arg1 > 90.0)
2562  {
2563  /* tand(180-x) = -tand(x) */
2564  arg1 = 180.0 - arg1;
2565  sign = -sign;
2566  }
2567 
2568  tan_arg1 = sind_q1(arg1) / cosd_q1(arg1);
2569  result = sign * (tan_arg1 / tan_45);
2570 
2571  /*
2572  * On some machines we get tand(180) = minus zero, but this isn't always
2573  * true. For portability, and because the user constituency for this
2574  * function probably doesn't want minus zero, force it to plain zero.
2575  */
2576  if (result == 0.0)
2577  result = 0.0;
2578 
2579  /* Not checking for overflow because tand(90) == Inf */
2580 
2581  PG_RETURN_FLOAT8(result);
2582 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2059
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
static double sind_q1(double x)
Definition: float.c:2307
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
char sign
Definition: informix.c:668
static double cosd_q1(double x)
Definition: float.c:2327
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
static float8 tan_45
Definition: float.c:51

◆ dtanh()

Datum dtanh ( PG_FUNCTION_ARGS  )

Definition at line 2680 of file float.c.

References float_overflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

2681 {
2682  float8 arg1 = PG_GETARG_FLOAT8(0);
2683  float8 result;
2684 
2685  /*
2686  * For tanh, we don't need an errno check because it never overflows.
2687  */
2688  result = tanh(arg1);
2689 
2690  if (unlikely(isinf(result)))
2692 
2693  PG_RETURN_FLOAT8(result);
2694 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ dtof()

Datum dtof ( PG_FUNCTION_ARGS  )

Definition at line 1223 of file float.c.

References float_overflow_error(), float_underflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT4, and unlikely.

1224 {
1225  float8 num = PG_GETARG_FLOAT8(0);
1226  float4 result;
1227 
1228  result = (float4) num;
1229  if (unlikely(isinf(result)) && !isinf(num))
1231  if (unlikely(result == 0.0f) && num != 0.0)
1233 
1234  PG_RETURN_FLOAT4(result);
1235 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:498
float float4
Definition: c.h:497
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ dtoi2()

Datum dtoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1267 of file float.c.

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

1268 {
1269  float8 num = PG_GETARG_FLOAT8(0);
1270 
1271  /*
1272  * Get rid of any fractional part in the input. This is so we don't fail
1273  * on just-out-of-range values that would round into range. Note
1274  * assumption that rint() will pass through a NaN or Inf unchanged.
1275  */
1276  num = rint(num);
1277 
1278  /* Range check */
1279  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT16(num)))
1280  ereport(ERROR,
1281  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1282  errmsg("smallint out of range")));
1283 
1284  PG_RETURN_INT16((int16) num);
1285 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
signed short int16
Definition: c.h:361
#define PG_RETURN_INT16(x)
Definition: fmgr.h:355
int errcode(int sqlerrcode)
Definition: elog.c:610
#define FLOAT8_FITS_IN_INT16(num)
Definition: c.h:1073
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dtoi4()

Datum dtoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1242 of file float.c.

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

1243 {
1244  float8 num = PG_GETARG_FLOAT8(0);
1245 
1246  /*
1247  * Get rid of any fractional part in the input. This is so we don't fail
1248  * on just-out-of-range values that would round into range. Note
1249  * assumption that rint() will pass through a NaN or Inf unchanged.
1250  */
1251  num = rint(num);
1252 
1253  /* Range check */
1254  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT32(num)))
1255  ereport(ERROR,
1256  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1257  errmsg("integer out of range")));
1258 
1259  PG_RETURN_INT32((int32) num);
1260 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:362
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define ereport(elevel,...)
Definition: elog.h:144
#define FLOAT8_FITS_IN_INT32(num)
Definition: c.h:1075
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ dtrunc()

Datum dtrunc ( PG_FUNCTION_ARGS  )

Definition at line 1456 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1457 {
1458  float8 arg1 = PG_GETARG_FLOAT8(0);
1459  float8 result;
1460 
1461  if (arg1 >= 0)
1462  result = floor(arg1);
1463  else
1464  result = -floor(-arg1);
1465 
1466  PG_RETURN_FLOAT8(result);
1467 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ float48div()

Datum float48div ( PG_FUNCTION_ARGS  )

Definition at line 3858 of file float.c.

References float8_div(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3859 {
3860  float4 arg1 = PG_GETARG_FLOAT4(0);
3861  float8 arg2 = PG_GETARG_FLOAT8(1);
3862 
3863  PG_RETURN_FLOAT8(float8_div((float8) arg1, arg2));
3864 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ float48eq()

Datum float48eq ( PG_FUNCTION_ARGS  )

Definition at line 3918 of file float.c.

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

3919 {
3920  float4 arg1 = PG_GETARG_FLOAT4(0);
3921  float8 arg2 = PG_GETARG_FLOAT8(1);
3922 
3923  PG_RETURN_BOOL(float8_eq((float8) arg1, arg2));
3924 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:267

◆ float48ge()

Datum float48ge ( PG_FUNCTION_ARGS  )

Definition at line 3963 of file float.c.

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

3964 {
3965  float4 arg1 = PG_GETARG_FLOAT4(0);
3966  float8 arg2 = PG_GETARG_FLOAT8(1);
3967 
3968  PG_RETURN_BOOL(float8_ge((float8) arg1, arg2));
3969 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
static bool float8_ge(const float8 val1, const float8 val2)
Definition: float.h:327
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float48gt()

Datum float48gt ( PG_FUNCTION_ARGS  )

Definition at line 3954 of file float.c.

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

3955 {
3956  float4 arg1 = PG_GETARG_FLOAT4(0);
3957  float8 arg2 = PG_GETARG_FLOAT8(1);
3958 
3959  PG_RETURN_BOOL(float8_gt((float8) arg1, arg2));
3960 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float48le()

Datum float48le ( PG_FUNCTION_ARGS  )

Definition at line 3945 of file float.c.

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

3946 {
3947  float4 arg1 = PG_GETARG_FLOAT4(0);
3948  float8 arg2 = PG_GETARG_FLOAT8(1);
3949 
3950  PG_RETURN_BOOL(float8_le((float8) arg1, arg2));
3951 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static bool float8_le(const float8 val1, const float8 val2)
Definition: float.h:303
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float48lt()

Datum float48lt ( PG_FUNCTION_ARGS  )

Definition at line 3936 of file float.c.

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

3937 {
3938  float4 arg1 = PG_GETARG_FLOAT4(0);
3939  float8 arg2 = PG_GETARG_FLOAT8(1);
3940 
3941  PG_RETURN_BOOL(float8_lt((float8) arg1, arg2));
3942 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float48mi()

Datum float48mi ( PG_FUNCTION_ARGS  )

Definition at line 3840 of file float.c.

References float8_mi(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3841 {
3842  float4 arg1 = PG_GETARG_FLOAT4(0);
3843  float8 arg2 = PG_GETARG_FLOAT8(1);
3844 
3845  PG_RETURN_FLOAT8(float8_mi((float8) arg1, arg2));
3846 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float48mul()

Datum float48mul ( PG_FUNCTION_ARGS  )

Definition at line 3849 of file float.c.

References float8_mul(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3850 {
3851  float4 arg1 = PG_GETARG_FLOAT4(0);
3852  float8 arg2 = PG_GETARG_FLOAT8(1);
3853 
3854  PG_RETURN_FLOAT8(float8_mul((float8) arg1, arg2));
3855 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float48ne()

Datum float48ne ( PG_FUNCTION_ARGS  )

Definition at line 3927 of file float.c.

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

3928 {
3929  float4 arg1 = PG_GETARG_FLOAT4(0);
3930  float8 arg2 = PG_GETARG_FLOAT8(1);
3931 
3932  PG_RETURN_BOOL(float8_ne((float8) arg1, arg2));
3933 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static bool float8_ne(const float8 val1, const float8 val2)
Definition: float.h:279
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float48pl()

Datum float48pl ( PG_FUNCTION_ARGS  )

Definition at line 3831 of file float.c.

References float8_pl(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3832 {
3833  float4 arg1 = PG_GETARG_FLOAT4(0);
3834  float8 arg2 = PG_GETARG_FLOAT8(1);
3835 
3836  PG_RETURN_FLOAT8(float8_pl((float8) arg1, arg2));
3837 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float4_accum()

Datum float4_accum ( PG_FUNCTION_ARGS  )

Definition at line 3087 of file float.c.

References AggCheckCallContext(), check_float8_array(), construct_array(), Float8GetDatumFast, FLOAT8PASSBYVAL, float_overflow_error(), get_float8_nan(), newval, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT4, and PG_RETURN_ARRAYTYPE_P.

3088 {
3089  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3090 
3091  /* do computations as float8 */
3093  float8 *transvalues;
3094  float8 N,
3095  Sx,
3096  Sxx,
3097  tmp;
3098 
3099  transvalues = check_float8_array(transarray, "float4_accum", 3);
3100  N = transvalues[0];
3101  Sx = transvalues[1];
3102  Sxx = transvalues[2];
3103 
3104  /*
3105  * Use the Youngs-Cramer algorithm to incorporate the new value into the
3106  * transition values.
3107  */
3108  N += 1.0;
3109  Sx += newval;
3110  if (transvalues[0] > 0.0)
3111  {
3112  tmp = newval * N - Sx;
3113  Sxx += tmp * tmp / (N * transvalues[0]);
3114 
3115  /*
3116  * Overflow check. We only report an overflow error when finite
3117  * inputs lead to infinite results. Note also that Sxx should be NaN
3118  * if any of the inputs are infinite, so we intentionally prevent Sxx
3119  * from becoming infinite.
3120  */
3121  if (isinf(Sx) || isinf(Sxx))
3122  {
3123  if (!isinf(transvalues[1]) && !isinf(newval))
3125 
3126  Sxx = get_float8_nan();
3127  }
3128  }
3129  else
3130  {
3131  /*
3132  * At the first input, we normally can leave Sxx as 0. However, if
3133  * the first input is Inf or NaN, we'd better force Sxx to NaN;
3134  * otherwise we will falsely report variance zero when there are no
3135  * more inputs.
3136  */
3137  if (isnan(newval) || isinf(newval))
3138  Sxx = get_float8_nan();
3139  }
3140 
3141  /*
3142  * If we're invoked as an aggregate, we can cheat and modify our first
3143  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3144  * new array with the updated transition data and return it.
3145  */
3146  if (AggCheckCallContext(fcinfo, NULL))
3147  {
3148  transvalues[0] = N;
3149  transvalues[1] = Sx;
3150  transvalues[2] = Sxx;
3151 
3152  PG_RETURN_ARRAYTYPE_P(transarray);
3153  }
3154  else
3155  {
3156  Datum transdatums[3];
3157  ArrayType *result;
3158 
3159  transdatums[0] = Float8GetDatumFast(N);
3160  transdatums[1] = Float8GetDatumFast(Sx);
3161  transdatums[2] = Float8GetDatumFast(Sxx);
3162 
3163  result = construct_array(transdatums, 3,
3164  FLOAT8OID,
3165  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3166 
3167  PG_RETURN_ARRAYTYPE_P(result);
3168  }
3169 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:253
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
uintptr_t Datum
Definition: postgres.h:367
#define Float8GetDatumFast(X)
Definition: postgres.h:761
#define FLOAT8PASSBYVAL
Definition: c.h:503
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define newval
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4774
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886

◆ float4_cmp_internal()

int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 844 of file float.c.

References float4_gt(), and float4_lt().

Referenced by btfloat4cmp(), and btfloat4fastcmp().

845 {
846  if (float4_gt(a, b))
847  return 1;
848  if (float4_lt(a, b))
849  return -1;
850  return 0;
851 }
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:309
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:285

◆ float4abs()

Datum float4abs ( PG_FUNCTION_ARGS  )

Definition at line 619 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

620 {
621  float4 arg1 = PG_GETARG_FLOAT4(0);
622 
623  PG_RETURN_FLOAT4((float4) fabs(arg1));
624 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float4div()

Datum float4div ( PG_FUNCTION_ARGS  )

Definition at line 783 of file float.c.

References float4_div(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

784 {
785  float4 arg1 = PG_GETARG_FLOAT4(0);
786  float4 arg2 = PG_GETARG_FLOAT4(1);
787 
788  PG_RETURN_FLOAT4(float4_div(arg1, arg2));
789 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
static float4 float4_div(const float4 val1, const float4 val2)
Definition: float.h:221
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float4eq()

Datum float4eq ( PG_FUNCTION_ARGS  )

Definition at line 854 of file float.c.

References float4_eq(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

855 {
856  float4 arg1 = PG_GETARG_FLOAT4(0);
857  float4 arg2 = PG_GETARG_FLOAT4(1);
858 
859  PG_RETURN_BOOL(float4_eq(arg1, arg2));
860 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float4_eq(const float4 val1, const float4 val2)
Definition: float.h:261

◆ float4ge()

Datum float4ge ( PG_FUNCTION_ARGS  )

Definition at line 899 of file float.c.

References float4_ge(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

900 {
901  float4 arg1 = PG_GETARG_FLOAT4(0);
902  float4 arg2 = PG_GETARG_FLOAT4(1);
903 
904  PG_RETURN_BOOL(float4_ge(arg1, arg2));
905 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float4_ge(const float4 val1, const float4 val2)
Definition: float.h:321

◆ float4gt()

Datum float4gt ( PG_FUNCTION_ARGS  )

Definition at line 890 of file float.c.

References float4_gt(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

891 {
892  float4 arg1 = PG_GETARG_FLOAT4(0);
893  float4 arg2 = PG_GETARG_FLOAT4(1);
894 
895  PG_RETURN_BOOL(float4_gt(arg1, arg2));
896 }
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:309
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float4in()

Datum float4in ( PG_FUNCTION_ARGS  )

Definition at line 162 of file float.c.

References ereport, errcode(), errmsg(), ERROR, get_float4_infinity(), get_float4_nan(), PG_GETARG_CSTRING, PG_RETURN_FLOAT4, pg_strncasecmp(), strtof(), and val.

Referenced by numeric_float4().

163 {
164  char *num = PG_GETARG_CSTRING(0);
165  char *orig_num;
166  float val;
167  char *endptr;
168 
169  /*
170  * endptr points to the first character _after_ the sequence we recognized
171  * as a valid floating point number. orig_num points to the original input
172  * string.
173  */
174  orig_num = num;
175 
176  /* skip leading whitespace */
177  while (*num != '\0' && isspace((unsigned char) *num))
178  num++;
179 
180  /*
181  * Check for an empty-string input to begin with, to avoid the vagaries of
182  * strtod() on different platforms.
183  */
184  if (*num == '\0')
185  ereport(ERROR,
186  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
187  errmsg("invalid input syntax for type %s: \"%s\"",
188  "real", orig_num)));
189 
190  errno = 0;
191  val = strtof(num, &endptr);
192 
193  /* did we not see anything that looks like a double? */
194  if (endptr == num || errno != 0)
195  {
196  int save_errno = errno;
197 
198  /*
199  * C99 requires that strtof() accept NaN, [+-]Infinity, and [+-]Inf,
200  * but not all platforms support all of these (and some accept them
201  * but set ERANGE anyway...) Therefore, we check for these inputs
202  * ourselves if strtof() fails.
203  *
204  * Note: C99 also requires hexadecimal input as well as some extended
205  * forms of NaN, but we consider these forms unportable and don't try
206  * to support them. You can use 'em if your strtof() takes 'em.
207  */
208  if (pg_strncasecmp(num, "NaN", 3) == 0)
209  {
210  val = get_float4_nan();
211  endptr = num + 3;
212  }
213  else if (pg_strncasecmp(num, "Infinity", 8) == 0)
214  {
215  val = get_float4_infinity();
216  endptr = num + 8;
217  }
218  else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
219  {
220  val = get_float4_infinity();
221  endptr = num + 9;
222  }
223  else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
224  {
225  val = -get_float4_infinity();
226  endptr = num + 9;
227  }
228  else if (pg_strncasecmp(num, "inf", 3) == 0)
229  {
230  val = get_float4_infinity();
231  endptr = num + 3;
232  }
233  else if (pg_strncasecmp(num, "+inf", 4) == 0)
234  {
235  val = get_float4_infinity();
236  endptr = num + 4;
237  }
238  else if (pg_strncasecmp(num, "-inf", 4) == 0)
239  {
240  val = -get_float4_infinity();
241  endptr = num + 4;
242  }
243  else if (save_errno == ERANGE)
244  {
245  /*
246  * Some platforms return ERANGE for denormalized numbers (those
247  * that are not zero, but are too close to zero to have full
248  * precision). We'd prefer not to throw error for that, so try to
249  * detect whether it's a "real" out-of-range condition by checking
250  * to see if the result is zero or huge.
251  *
252  * Use isinf() rather than HUGE_VALF on VS2013 because it
253  * generates a spurious overflow warning for -HUGE_VALF. Also use
254  * isinf() if HUGE_VALF is missing.
255  */
256  if (val == 0.0 ||
257 #if !defined(HUGE_VALF) || (defined(_MSC_VER) && (_MSC_VER < 1900))
258  isinf(val)
259 #else
260  (val >= HUGE_VALF || val <= -HUGE_VALF)
261 #endif
262  )
263  ereport(ERROR,
264  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
265  errmsg("\"%s\" is out of range for type real",
266  orig_num)));
267  }
268  else
269  ereport(ERROR,
270  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
271  errmsg("invalid input syntax for type %s: \"%s\"",
272  "real", orig_num)));
273  }
274 #ifdef HAVE_BUGGY_SOLARIS_STRTOD
275  else
276  {
277  /*
278  * Many versions of Solaris have a bug wherein strtod sets endptr to
279  * point one byte beyond the end of the string when given "inf" or
280  * "infinity".
281  */
282  if (endptr != num && endptr[-1] == '\0')
283  endptr--;
284  }
285 #endif /* HAVE_BUGGY_SOLARIS_STRTOD */
286 
287  /* skip trailing whitespace */
288  while (*endptr != '\0' && isspace((unsigned char) *endptr))
289  endptr++;
290 
291  /* if there is any junk left at the end of the string, bail out */
292  if (*endptr != '\0')
293  ereport(ERROR,
294  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
295  errmsg("invalid input syntax for type %s: \"%s\"",
296  "real", orig_num)));
297 
298  PG_RETURN_FLOAT4(val);
299 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
int errcode(int sqlerrcode)
Definition: elog.c:610
float strtof(const char *nptr, char **endptr)
Definition: strtof.c:28
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
static float4 get_float4_nan(void)
Definition: float.h:110
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
long val
Definition: informix.c:664
static float4 get_float4_infinity(void)
Definition: float.h:73

◆ float4larger()

Datum float4larger ( PG_FUNCTION_ARGS  )

Definition at line 648 of file float.c.

References float4_gt(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

649 {
650  float4 arg1 = PG_GETARG_FLOAT4(0);
651  float4 arg2 = PG_GETARG_FLOAT4(1);
652  float4 result;
653 
654  if (float4_gt(arg1, arg2))
655  result = arg1;
656  else
657  result = arg2;
658  PG_RETURN_FLOAT4(result);
659 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:309
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float4le()

Datum float4le ( PG_FUNCTION_ARGS  )

Definition at line 881 of file float.c.

References float4_le(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

882 {
883  float4 arg1 = PG_GETARG_FLOAT4(0);
884  float4 arg2 = PG_GETARG_FLOAT4(1);
885 
886  PG_RETURN_BOOL(float4_le(arg1, arg2));
887 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float4_le(const float4 val1, const float4 val2)
Definition: float.h:297

◆ float4lt()

Datum float4lt ( PG_FUNCTION_ARGS  )

Definition at line 872 of file float.c.

References float4_lt(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

873 {
874  float4 arg1 = PG_GETARG_FLOAT4(0);
875  float4 arg2 = PG_GETARG_FLOAT4(1);
876 
877  PG_RETURN_BOOL(float4_lt(arg1, arg2));
878 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:285

◆ float4mi()

Datum float4mi ( PG_FUNCTION_ARGS  )

Definition at line 765 of file float.c.

References float4_mi(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

766 {
767  float4 arg1 = PG_GETARG_FLOAT4(0);
768  float4 arg2 = PG_GETARG_FLOAT4(1);
769 
770  PG_RETURN_FLOAT4(float4_mi(arg1, arg2));
771 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
static float4 float4_mi(const float4 val1, const float4 val2)
Definition: float.h:169
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float4mul()

Datum float4mul ( PG_FUNCTION_ARGS  )

Definition at line 774 of file float.c.

References float4_mul(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

775 {
776  float4 arg1 = PG_GETARG_FLOAT4(0);
777  float4 arg2 = PG_GETARG_FLOAT4(1);
778 
779  PG_RETURN_FLOAT4(float4_mul(arg1, arg2));
780 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
static float4 float4_mul(const float4 val1, const float4 val2)
Definition: float.h:193

◆ float4ne()

Datum float4ne ( PG_FUNCTION_ARGS  )

Definition at line 863 of file float.c.

References float4_ne(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

864 {
865  float4 arg1 = PG_GETARG_FLOAT4(0);
866  float4 arg2 = PG_GETARG_FLOAT4(1);
867 
868  PG_RETURN_BOOL(float4_ne(arg1, arg2));
869 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float4_ne(const float4 val1, const float4 val2)
Definition: float.h:273

◆ float4out()

Datum float4out ( PG_FUNCTION_ARGS  )

Definition at line 306 of file float.c.

References ascii(), extra_float_digits, float_to_shortest_decimal_buf(), palloc(), PG_GETARG_FLOAT4, PG_RETURN_CSTRING, and pg_strfromd().

307 {
308  float4 num = PG_GETARG_FLOAT4(0);
309  char *ascii = (char *) palloc(32);
310  int ndig = FLT_DIG + extra_float_digits;
311 
312  if (extra_float_digits > 0)
313  {
314  float_to_shortest_decimal_buf(num, ascii);
315  PG_RETURN_CSTRING(ascii);
316  }
317 
318  (void) pg_strfromd(ascii, 32, ndig, num);
319  PG_RETURN_CSTRING(ascii);
320 }
Datum ascii(PG_FUNCTION_ARGS)
int float_to_shortest_decimal_buf(float f, char *result)
Definition: f2s.c:780
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
int pg_strfromd(char *str, size_t count, int precision, double value)
Definition: snprintf.c:1263
float float4
Definition: c.h:497
int extra_float_digits
Definition: float.c:42
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:949

◆ float4pl()

Datum float4pl ( PG_FUNCTION_ARGS  )

Definition at line 756 of file float.c.

References float4_pl(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

757 {
758  float4 arg1 = PG_GETARG_FLOAT4(0);
759  float4 arg2 = PG_GETARG_FLOAT4(1);
760 
761  PG_RETURN_FLOAT4(float4_pl(arg1, arg2));
762 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
static float4 float4_pl(const float4 val1, const float4 val2)
Definition: float.h:145

◆ float4recv()

Datum float4recv ( PG_FUNCTION_ARGS  )

Definition at line 326 of file float.c.

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

327 {
329 
331 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
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 337 of file float.c.

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

338 {
339  float4 num = PG_GETARG_FLOAT4(0);
341 
342  pq_begintypsend(&buf);
343  pq_sendfloat4(&buf, num);
345 }
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:369
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:280
float float4
Definition: c.h:497

◆ float4smaller()

Datum float4smaller ( PG_FUNCTION_ARGS  )

Definition at line 662 of file float.c.

References float4_lt(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

663 {
664  float4 arg1 = PG_GETARG_FLOAT4(0);
665  float4 arg2 = PG_GETARG_FLOAT4(1);
666  float4 result;
667 
668  if (float4_lt(arg1, arg2))
669  result = arg1;
670  else
671  result = arg2;
672  PG_RETURN_FLOAT4(result);
673 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:285

◆ float4um()

Datum float4um ( PG_FUNCTION_ARGS  )

Definition at line 630 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

631 {
632  float4 arg1 = PG_GETARG_FLOAT4(0);
633  float4 result;
634 
635  result = -arg1;
636  PG_RETURN_FLOAT4(result);
637 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float4up()

Datum float4up ( PG_FUNCTION_ARGS  )

Definition at line 640 of file float.c.

References arg, PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

641 {
643 
644  PG_RETURN_FLOAT4(arg);
645 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
void * arg

◆ float84div()

Datum float84div ( PG_FUNCTION_ARGS  )

Definition at line 3900 of file float.c.

References float8_div(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3901 {
3902  float8 arg1 = PG_GETARG_FLOAT8(0);
3903  float4 arg2 = PG_GETARG_FLOAT4(1);
3904 
3905  PG_RETURN_FLOAT8(float8_div(arg1, (float8) arg2));
3906 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ float84eq()

Datum float84eq ( PG_FUNCTION_ARGS  )

Definition at line 3975 of file float.c.

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

3976 {
3977  float8 arg1 = PG_GETARG_FLOAT8(0);
3978  float4 arg2 = PG_GETARG_FLOAT4(1);
3979 
3980  PG_RETURN_BOOL(float8_eq(arg1, (float8) arg2));
3981 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:267

◆ float84ge()

Datum float84ge ( PG_FUNCTION_ARGS  )

Definition at line 4020 of file float.c.

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

4021 {
4022  float8 arg1 = PG_GETARG_FLOAT8(0);
4023  float4 arg2 = PG_GETARG_FLOAT4(1);
4024 
4025  PG_RETURN_BOOL(float8_ge(arg1, (float8) arg2));
4026 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
static bool float8_ge(const float8 val1, const float8 val2)
Definition: float.h:327
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float84gt()

Datum float84gt ( PG_FUNCTION_ARGS  )

Definition at line 4011 of file float.c.

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

4012 {
4013  float8 arg1 = PG_GETARG_FLOAT8(0);
4014  float4 arg2 = PG_GETARG_FLOAT4(1);
4015 
4016  PG_RETURN_BOOL(float8_gt(arg1, (float8) arg2));
4017 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float84le()

Datum float84le ( PG_FUNCTION_ARGS  )

Definition at line 4002 of file float.c.

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

4003 {
4004  float8 arg1 = PG_GETARG_FLOAT8(0);
4005  float4 arg2 = PG_GETARG_FLOAT4(1);
4006 
4007  PG_RETURN_BOOL(float8_le(arg1, (float8) arg2));
4008 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static bool float8_le(const float8 val1, const float8 val2)
Definition: float.h:303
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float84lt()

Datum float84lt ( PG_FUNCTION_ARGS  )

Definition at line 3993 of file float.c.

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

3994 {
3995  float8 arg1 = PG_GETARG_FLOAT8(0);
3996  float4 arg2 = PG_GETARG_FLOAT4(1);
3997 
3998  PG_RETURN_BOOL(float8_lt(arg1, (float8) arg2));
3999 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float84mi()

Datum float84mi ( PG_FUNCTION_ARGS  )

Definition at line 3882 of file float.c.

References float8_mi(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3883 {
3884  float8 arg1 = PG_GETARG_FLOAT8(0);
3885  float4 arg2 = PG_GETARG_FLOAT4(1);
3886 
3887  PG_RETURN_FLOAT8(float8_mi(arg1, (float8) arg2));
3888 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float84mul()

Datum float84mul ( PG_FUNCTION_ARGS  )

Definition at line 3891 of file float.c.

References float8_mul(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3892 {
3893  float8 arg1 = PG_GETARG_FLOAT8(0);
3894  float4 arg2 = PG_GETARG_FLOAT4(1);
3895 
3896  PG_RETURN_FLOAT8(float8_mul(arg1, (float8) arg2));
3897 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float84ne()

Datum float84ne ( PG_FUNCTION_ARGS  )

Definition at line 3984 of file float.c.

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

3985 {
3986  float8 arg1 = PG_GETARG_FLOAT8(0);
3987  float4 arg2 = PG_GETARG_FLOAT4(1);
3988 
3989  PG_RETURN_BOOL(float8_ne(arg1, (float8) arg2));
3990 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static bool float8_ne(const float8 val1, const float8 val2)
Definition: float.h:279
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float84pl()

Datum float84pl ( PG_FUNCTION_ARGS  )

Definition at line 3873 of file float.c.

References float8_pl(), PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

3874 {
3875  float8 arg1 = PG_GETARG_FLOAT8(0);
3876  float4 arg2 = PG_GETARG_FLOAT4(1);
3877 
3878  PG_RETURN_FLOAT8(float8_pl(arg1, (float8) arg2));
3879 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ float8_accum()

Datum float8_accum ( PG_FUNCTION_ARGS  )

Definition at line 3004 of file float.c.

References AggCheckCallContext(), check_float8_array(), construct_array(), Float8GetDatumFast, FLOAT8PASSBYVAL, float_overflow_error(), get_float8_nan(), newval, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, and PG_RETURN_ARRAYTYPE_P.

3005 {
3006  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3008  float8 *transvalues;
3009  float8 N,
3010  Sx,
3011  Sxx,
3012  tmp;
3013 
3014  transvalues = check_float8_array(transarray, "float8_accum", 3);
3015  N = transvalues[0];
3016  Sx = transvalues[1];
3017  Sxx = transvalues[2];
3018 
3019  /*
3020  * Use the Youngs-Cramer algorithm to incorporate the new value into the
3021  * transition values.
3022  */
3023  N += 1.0;
3024  Sx += newval;
3025  if (transvalues[0] > 0.0)
3026  {
3027  tmp = newval * N - Sx;
3028  Sxx += tmp * tmp / (N * transvalues[0]);
3029 
3030  /*
3031  * Overflow check. We only report an overflow error when finite
3032  * inputs lead to infinite results. Note also that Sxx should be NaN
3033  * if any of the inputs are infinite, so we intentionally prevent Sxx
3034  * from becoming infinite.
3035  */
3036  if (isinf(Sx) || isinf(Sxx))
3037  {
3038  if (!isinf(transvalues[1]) && !isinf(newval))
3040 
3041  Sxx = get_float8_nan();
3042  }
3043  }
3044  else
3045  {
3046  /*
3047  * At the first input, we normally can leave Sxx as 0. However, if
3048  * the first input is Inf or NaN, we'd better force Sxx to NaN;
3049  * otherwise we will falsely report variance zero when there are no
3050  * more inputs.
3051  */
3052  if (isnan(newval) || isinf(newval))
3053  Sxx = get_float8_nan();
3054  }
3055 
3056  /*
3057  * If we're invoked as an aggregate, we can cheat and modify our first
3058  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3059  * new array with the updated transition data and return it.
3060  */
3061  if (AggCheckCallContext(fcinfo, NULL))
3062  {
3063  transvalues[0] = N;
3064  transvalues[1] = Sx;
3065  transvalues[2] = Sxx;
3066 
3067  PG_RETURN_ARRAYTYPE_P(transarray);
3068  }
3069  else
3070  {
3071  Datum transdatums[3];
3072  ArrayType *result;
3073 
3074  transdatums[0] = Float8GetDatumFast(N);
3075  transdatums[1] = Float8GetDatumFast(Sx);
3076  transdatums[2] = Float8GetDatumFast(Sxx);
3077 
3078  result = construct_array(transdatums, 3,
3079  FLOAT8OID,
3080  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3081 
3082  PG_RETURN_ARRAYTYPE_P(result);
3083  }
3084 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:253
uintptr_t Datum
Definition: postgres.h:367
#define Float8GetDatumFast(X)
Definition: postgres.h:761
#define FLOAT8PASSBYVAL
Definition: c.h:503
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define newval
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4774
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886

◆ float8_avg()

Datum float8_avg ( PG_FUNCTION_ARGS  )

Definition at line 3172 of file float.c.

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

3173 {
3174  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3175  float8 *transvalues;
3176  float8 N,
3177  Sx;
3178 
3179  transvalues = check_float8_array(transarray, "float8_avg", 3);
3180  N = transvalues[0];
3181  Sx = transvalues[1];
3182  /* ignore Sxx */
3183 
3184  /* SQL defines AVG of no values to be NULL */
3185  if (N == 0.0)
3186  PG_RETURN_NULL();
3187 
3188  PG_RETURN_FLOAT8(Sx / N);
3189 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_cmp_internal()

int float8_cmp_internal ( float8  a,
float8  b 
)

Definition at line 938 of file float.c.

References float8_gt(), and float8_lt().

Referenced by btfloat48cmp(), btfloat84cmp(), btfloat8cmp(), btfloat8fastcmp(), common_entry_cmp(), interval_cmp_lower(), interval_cmp_upper(), and pairingheap_GISTSearchItem_cmp().

939 {
940  if (float8_gt(a, b))
941  return 1;
942  if (float8_lt(a, b))
943  return -1;
944  return 0;
945 }
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float8_combine()

Datum float8_combine ( PG_FUNCTION_ARGS  )

Definition at line 2910 of file float.c.

References AggCheckCallContext(), check_float8_array(), construct_array(), float8_pl(), Float8GetDatumFast, FLOAT8PASSBYVAL, float_overflow_error(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_ARRAYTYPE_P, and unlikely.

2911 {
2912  ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(0);
2913  ArrayType *transarray2 = PG_GETARG_ARRAYTYPE_P(1);
2914  float8 *transvalues1;
2915  float8 *transvalues2;
2916  float8 N1,
2917  Sx1,
2918  Sxx1,
2919  N2,
2920  Sx2,
2921  Sxx2,
2922  tmp,
2923  N,
2924  Sx,
2925  Sxx;
2926 
2927  transvalues1 = check_float8_array(transarray1, "float8_combine", 3);
2928  transvalues2 = check_float8_array(transarray2, "float8_combine", 3);
2929 
2930  N1 = transvalues1[0];
2931  Sx1 = transvalues1[1];
2932  Sxx1 = transvalues1[2];
2933 
2934  N2 = transvalues2[0];
2935  Sx2 = transvalues2[1];
2936  Sxx2 = transvalues2[2];
2937 
2938  /*--------------------
2939  * The transition values combine using a generalization of the
2940  * Youngs-Cramer algorithm as follows:
2941  *
2942  * N = N1 + N2
2943  * Sx = Sx1 + Sx2
2944  * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N;
2945  *
2946  * It's worth handling the special cases N1 = 0 and N2 = 0 separately
2947  * since those cases are trivial, and we then don't need to worry about
2948  * division-by-zero errors in the general case.
2949  *--------------------
2950  */
2951  if (N1 == 0.0)
2952  {
2953  N = N2;
2954  Sx = Sx2;
2955  Sxx = Sxx2;
2956  }
2957  else if (N2 == 0.0)
2958  {
2959  N = N1;
2960  Sx = Sx1;
2961  Sxx = Sxx1;
2962  }
2963  else
2964  {
2965  N = N1 + N2;
2966  Sx = float8_pl(Sx1, Sx2);
2967  tmp = Sx1 / N1 - Sx2 / N2;
2968  Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp * tmp / N;
2969  if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))
2971  }
2972 
2973  /*
2974  * If we're invoked as an aggregate, we can cheat and modify our first
2975  * parameter in-place to reduce palloc overhead. Otherwise we construct a
2976  * new array with the updated transition data and return it.
2977  */
2978  if (AggCheckCallContext(fcinfo, NULL))
2979  {
2980  transvalues1[0] = N;
2981  transvalues1[1] = Sx;
2982  transvalues1[2] = Sxx;
2983 
2984  PG_RETURN_ARRAYTYPE_P(transarray1);
2985  }
2986  else
2987  {
2988  Datum transdatums[3];
2989  ArrayType *result;
2990 
2991  transdatums[0] = Float8GetDatumFast(N);
2992  transdatums[1] = Float8GetDatumFast(Sx);
2993  transdatums[2] = Float8GetDatumFast(Sxx);
2994 
2995  result = construct_array(transdatums, 3,
2996  FLOAT8OID,
2997  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
2998 
2999  PG_RETURN_ARRAYTYPE_P(result);
3000  }
3001 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:253
uintptr_t Datum
Definition: postgres.h:367
#define Float8GetDatumFast(X)
Definition: postgres.h:761
#define FLOAT8PASSBYVAL
Definition: c.h:503
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4774
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define unlikely(x)
Definition: c.h:206

◆ float8_corr()

Datum float8_corr ( PG_FUNCTION_ARGS  )

Definition at line 3698 of file float.c.

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

3699 {
3700  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3701  float8 *transvalues;
3702  float8 N,
3703  Sxx,
3704  Syy,
3705  Sxy;
3706 
3707  transvalues = check_float8_array(transarray, "float8_corr", 6);
3708  N = transvalues[0];
3709  Sxx = transvalues[2];
3710  Syy = transvalues[4];
3711  Sxy = transvalues[5];
3712 
3713  /* if N is 0 we should return NULL */
3714  if (N < 1.0)
3715  PG_RETURN_NULL();
3716 
3717  /* Note that Sxx and Syy are guaranteed to be non-negative */
3718 
3719  /* per spec, return NULL for horizontal and vertical lines */
3720  if (Sxx == 0 || Syy == 0)
3721  PG_RETURN_NULL();
3722 
3723  PG_RETURN_FLOAT8(Sxy / sqrt(Sxx * Syy));
3724 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_covar_pop()

Datum float8_covar_pop ( PG_FUNCTION_ARGS  )

Definition at line 3660 of file float.c.

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

3661 {
3662  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3663  float8 *transvalues;
3664  float8 N,
3665  Sxy;
3666 
3667  transvalues = check_float8_array(transarray, "float8_covar_pop", 6);
3668  N = transvalues[0];
3669  Sxy = transvalues[5];
3670 
3671  /* if N is 0 we should return NULL */
3672  if (N < 1.0)
3673  PG_RETURN_NULL();
3674 
3675  PG_RETURN_FLOAT8(Sxy / N);
3676 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_covar_samp()

Datum float8_covar_samp ( PG_FUNCTION_ARGS  )

Definition at line 3679 of file float.c.

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

3680 {
3681  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3682  float8 *transvalues;
3683  float8 N,
3684  Sxy;
3685 
3686  transvalues = check_float8_array(transarray, "float8_covar_samp", 6);
3687  N = transvalues[0];
3688  Sxy = transvalues[5];
3689 
3690  /* if N is <= 1 we should return NULL */
3691  if (N < 2.0)
3692  PG_RETURN_NULL();
3693 
3694  PG_RETURN_FLOAT8(Sxy / (N - 1.0));
3695 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_accum()

Datum float8_regr_accum ( PG_FUNCTION_ARGS  )

Definition at line 3301 of file float.c.

References AggCheckCallContext(), check_float8_array(), construct_array(), Float8GetDatumFast, FLOAT8PASSBYVAL, float_overflow_error(), get_float8_nan(), PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, PG_RETURN_ARRAYTYPE_P, and scale.

3302 {
3303  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3304  float8 newvalY = PG_GETARG_FLOAT8(1);
3305  float8 newvalX = PG_GETARG_FLOAT8(2);
3306  float8 *transvalues;
3307  float8 N,
3308  Sx,
3309  Sxx,
3310  Sy,
3311  Syy,
3312  Sxy,
3313  tmpX,
3314  tmpY,
3315  scale;
3316 
3317  transvalues = check_float8_array(transarray, "float8_regr_accum", 6);
3318  N = transvalues[0];
3319  Sx = transvalues[1];
3320  Sxx = transvalues[2];
3321  Sy = transvalues[3];
3322  Syy = transvalues[4];
3323  Sxy = transvalues[5];
3324 
3325  /*
3326  * Use the Youngs-Cramer algorithm to incorporate the new values into the
3327  * transition values.
3328  */
3329  N += 1.0;
3330  Sx += newvalX;
3331  Sy += newvalY;
3332  if (transvalues[0] > 0.0)
3333  {
3334  tmpX = newvalX * N - Sx;
3335  tmpY = newvalY * N - Sy;
3336  scale = 1.0 / (N * transvalues[0]);
3337  Sxx += tmpX * tmpX * scale;
3338  Syy += tmpY * tmpY * scale;
3339  Sxy += tmpX * tmpY * scale;
3340 
3341  /*
3342  * Overflow check. We only report an overflow error when finite
3343  * inputs lead to infinite results. Note also that Sxx, Syy and Sxy
3344  * should be NaN if any of the relevant inputs are infinite, so we
3345  * intentionally prevent them from becoming infinite.
3346  */
3347  if (isinf(Sx) || isinf(Sxx) || isinf(Sy) || isinf(Syy) || isinf(Sxy))
3348  {
3349  if (((isinf(Sx) || isinf(Sxx)) &&
3350  !isinf(transvalues[1]) && !isinf(newvalX)) ||
3351  ((isinf(Sy) || isinf(Syy)) &&
3352  !isinf(transvalues[3]) && !isinf(newvalY)) ||
3353  (isinf(Sxy) &&
3354  !isinf(transvalues[1]) && !isinf(newvalX) &&
3355  !isinf(transvalues[3]) && !isinf(newvalY)))
3357 
3358  if (isinf(Sxx))
3359  Sxx = get_float8_nan();
3360  if (isinf(Syy))
3361  Syy = get_float8_nan();
3362  if (isinf(Sxy))
3363  Sxy = get_float8_nan();
3364  }
3365  }
3366  else
3367  {
3368  /*
3369  * At the first input, we normally can leave Sxx et al as 0. However,
3370  * if the first input is Inf or NaN, we'd better force the dependent
3371  * sums to NaN; otherwise we will falsely report variance zero when
3372  * there are no more inputs.
3373  */
3374  if (isnan(newvalX) || isinf(newvalX))
3375  Sxx = Sxy = get_float8_nan();
3376  if (isnan(newvalY) || isinf(newvalY))
3377  Syy = Sxy = get_float8_nan();
3378  }
3379 
3380  /*
3381  * If we're invoked as an aggregate, we can cheat and modify our first
3382  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3383  * new array with the updated transition data and return it.
3384  */
3385  if (AggCheckCallContext(fcinfo, NULL))
3386  {
3387  transvalues[0] = N;
3388  transvalues[1] = Sx;
3389  transvalues[2] = Sxx;
3390  transvalues[3] = Sy;
3391  transvalues[4] = Syy;
3392  transvalues[5] = Sxy;
3393 
3394  PG_RETURN_ARRAYTYPE_P(transarray);
3395  }
3396  else
3397  {
3398  Datum transdatums[6];
3399  ArrayType *result;
3400 
3401  transdatums[0] = Float8GetDatumFast(N);
3402  transdatums[1] = Float8GetDatumFast(Sx);
3403  transdatums[2] = Float8GetDatumFast(Sxx);
3404  transdatums[3] = Float8GetDatumFast(Sy);
3405  transdatums[4] = Float8GetDatumFast(Syy);
3406  transdatums[5] = Float8GetDatumFast(Sxy);
3407 
3408  result = construct_array(transdatums, 6,
3409  FLOAT8OID,
3410  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3411 
3412  PG_RETURN_ARRAYTYPE_P(result);
3413  }
3414 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
int scale
Definition: pgbench.c:153
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 get_float8_nan(void)
Definition: float.h:122
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:253
uintptr_t Datum
Definition: postgres.h:367
#define Float8GetDatumFast(X)
Definition: postgres.h:761
#define FLOAT8PASSBYVAL
Definition: c.h:503
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4774
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886

◆ float8_regr_avgx()

Datum float8_regr_avgx ( PG_FUNCTION_ARGS  )

Definition at line 3622 of file float.c.

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

3623 {
3624  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3625  float8 *transvalues;
3626  float8 N,
3627  Sx;
3628 
3629  transvalues = check_float8_array(transarray, "float8_regr_avgx", 6);
3630  N = transvalues[0];
3631  Sx = transvalues[1];
3632 
3633  /* if N is 0 we should return NULL */
3634  if (N < 1.0)
3635  PG_RETURN_NULL();
3636 
3637  PG_RETURN_FLOAT8(Sx / N);
3638 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_avgy()

Datum float8_regr_avgy ( PG_FUNCTION_ARGS  )

Definition at line 3641 of file float.c.

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

3642 {
3643  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3644  float8 *transvalues;
3645  float8 N,
3646  Sy;
3647 
3648  transvalues = check_float8_array(transarray, "float8_regr_avgy", 6);
3649  N = transvalues[0];
3650  Sy = transvalues[3];
3651 
3652  /* if N is 0 we should return NULL */
3653  if (N < 1.0)
3654  PG_RETURN_NULL();
3655 
3656  PG_RETURN_FLOAT8(Sy / N);
3657 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_combine()

Datum float8_regr_combine ( PG_FUNCTION_ARGS  )

Definition at line 3425 of file float.c.

References AggCheckCallContext(), check_float8_array(), construct_array(), float8_pl(), Float8GetDatumFast, FLOAT8PASSBYVAL, float_overflow_error(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_ARRAYTYPE_P, and unlikely.

3426 {
3427  ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(0);
3428  ArrayType *transarray2 = PG_GETARG_ARRAYTYPE_P(1);
3429  float8 *transvalues1;
3430  float8 *transvalues2;
3431  float8 N1,
3432  Sx1,
3433  Sxx1,
3434  Sy1,
3435  Syy1,
3436  Sxy1,
3437  N2,
3438  Sx2,
3439  Sxx2,
3440  Sy2,
3441  Syy2,
3442  Sxy2,
3443  tmp1,
3444  tmp2,
3445  N,
3446  Sx,
3447  Sxx,
3448  Sy,
3449  Syy,
3450  Sxy;
3451 
3452  transvalues1 = check_float8_array(transarray1, "float8_regr_combine", 6);
3453  transvalues2 = check_float8_array(transarray2, "float8_regr_combine", 6);
3454 
3455  N1 = transvalues1[0];
3456  Sx1 = transvalues1[1];
3457  Sxx1 = transvalues1[2];
3458  Sy1 = transvalues1[3];
3459  Syy1 = transvalues1[4];
3460  Sxy1 = transvalues1[5];
3461 
3462  N2 = transvalues2[0];
3463  Sx2 = transvalues2[1];
3464  Sxx2 = transvalues2[2];
3465  Sy2 = transvalues2[3];
3466  Syy2 = transvalues2[4];
3467  Sxy2 = transvalues2[5];
3468 
3469  /*--------------------
3470  * The transition values combine using a generalization of the
3471  * Youngs-Cramer algorithm as follows:
3472  *
3473  * N = N1 + N2
3474  * Sx = Sx1 + Sx2
3475  * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N
3476  * Sy = Sy1 + Sy2
3477  * Syy = Syy1 + Syy2 + N1 * N2 * (Sy1/N1 - Sy2/N2)^2 / N
3478  * Sxy = Sxy1 + Sxy2 + N1 * N2 * (Sx1/N1 - Sx2/N2) * (Sy1/N1 - Sy2/N2) / N
3479  *
3480  * It's worth handling the special cases N1 = 0 and N2 = 0 separately
3481  * since those cases are trivial, and we then don't need to worry about
3482  * division-by-zero errors in the general case.
3483  *--------------------
3484  */
3485  if (N1 == 0.0)
3486  {
3487  N = N2;
3488  Sx = Sx2;
3489  Sxx = Sxx2;
3490  Sy = Sy2;
3491  Syy = Syy2;
3492  Sxy = Sxy2;
3493  }
3494  else if (N2 == 0.0)
3495  {
3496  N = N1;
3497  Sx = Sx1;
3498  Sxx = Sxx1;
3499  Sy = Sy1;
3500  Syy = Syy1;
3501  Sxy = Sxy1;
3502  }
3503  else
3504  {
3505  N = N1 + N2;
3506  Sx = float8_pl(Sx1, Sx2);
3507  tmp1 = Sx1 / N1 - Sx2 / N2;
3508  Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp1 * tmp1 / N;
3509  if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))
3511  Sy = float8_pl(Sy1, Sy2);
3512  tmp2 = Sy1 / N1 - Sy2 / N2;
3513  Syy = Syy1 + Syy2 + N1 * N2 * tmp2 * tmp2 / N;
3514  if (unlikely(isinf(Syy)) && !isinf(Syy1) && !isinf(Syy2))
3516  Sxy = Sxy1 + Sxy2 + N1 * N2 * tmp1 * tmp2 / N;
3517  if (unlikely(isinf(Sxy)) && !isinf(Sxy1) && !isinf(Sxy2))
3519  }
3520 
3521  /*
3522  * If we're invoked as an aggregate, we can cheat and modify our first
3523  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3524  * new array with the updated transition data and return it.
3525  */
3526  if (AggCheckCallContext(fcinfo, NULL))
3527  {
3528  transvalues1[0] = N;
3529  transvalues1[1] = Sx;
3530  transvalues1[2] = Sxx;
3531  transvalues1[3] = Sy;
3532  transvalues1[4] = Syy;
3533  transvalues1[5] = Sxy;
3534 
3535  PG_RETURN_ARRAYTYPE_P(transarray1);
3536  }
3537  else
3538  {
3539  Datum transdatums[6];
3540  ArrayType *result;
3541 
3542  transdatums[0] = Float8GetDatumFast(N);
3543  transdatums[1] = Float8GetDatumFast(Sx);
3544  transdatums[2] = Float8GetDatumFast(Sxx);
3545  transdatums[3] = Float8GetDatumFast(Sy);
3546  transdatums[4] = Float8GetDatumFast(Syy);
3547  transdatums[5] = Float8GetDatumFast(Sxy);
3548 
3549  result = construct_array(transdatums, 6,
3550  FLOAT8OID,
3551  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3552 
3553  PG_RETURN_ARRAYTYPE_P(result);
3554  }
3555 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:253
uintptr_t Datum
Definition: postgres.h:367
#define Float8GetDatumFast(X)
Definition: postgres.h:761
#define FLOAT8PASSBYVAL
Definition: c.h:503
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4774
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define unlikely(x)
Definition: c.h:206

◆ float8_regr_intercept()

Datum float8_regr_intercept ( PG_FUNCTION_ARGS  )

Definition at line 3787 of file float.c.

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

3788 {
3789  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3790  float8 *transvalues;
3791  float8 N,
3792  Sx,
3793  Sxx,
3794  Sy,
3795  Sxy;
3796 
3797  transvalues = check_float8_array(transarray, "float8_regr_intercept", 6);
3798  N = transvalues[0];
3799  Sx = transvalues[1];
3800  Sxx = transvalues[2];
3801  Sy = transvalues[3];
3802  Sxy = transvalues[5];
3803 
3804  /* if N is 0 we should return NULL */
3805  if (N < 1.0)
3806  PG_RETURN_NULL();
3807 
3808  /* Note that Sxx is guaranteed to be non-negative */
3809 
3810  /* per spec, return NULL for a vertical line */
3811  if (Sxx == 0)
3812  PG_RETURN_NULL();
3813 
3814  PG_RETURN_FLOAT8((Sy - Sx * Sxy / Sxx) / N);
3815 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_r2()

Datum float8_regr_r2 ( PG_FUNCTION_ARGS  )

Definition at line 3727 of file float.c.

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

3728 {
3729  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3730  float8 *transvalues;
3731  float8 N,
3732  Sxx,
3733  Syy,
3734  Sxy;
3735 
3736  transvalues = check_float8_array(transarray, "float8_regr_r2", 6);
3737  N = transvalues[0];
3738  Sxx = transvalues[2];
3739  Syy = transvalues[4];
3740  Sxy = transvalues[5];
3741 
3742  /* if N is 0 we should return NULL */
3743  if (N < 1.0)
3744  PG_RETURN_NULL();
3745 
3746  /* Note that Sxx and Syy are guaranteed to be non-negative */
3747 
3748  /* per spec, return NULL for a vertical line */
3749  if (Sxx == 0)
3750  PG_RETURN_NULL();
3751 
3752  /* per spec, return 1.0 for a horizontal line */
3753  if (Syy == 0)
3754  PG_RETURN_FLOAT8(1.0);
3755 
3756  PG_RETURN_FLOAT8((Sxy * Sxy) / (Sxx * Syy));
3757 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_slope()

Datum float8_regr_slope ( PG_FUNCTION_ARGS  )

Definition at line 3760 of file float.c.

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

3761 {
3762  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3763  float8 *transvalues;
3764  float8 N,
3765  Sxx,
3766  Sxy;
3767 
3768  transvalues = check_float8_array(transarray, "float8_regr_slope", 6);
3769  N = transvalues[0];
3770  Sxx = transvalues[2];
3771  Sxy = transvalues[5];
3772 
3773  /* if N is 0 we should return NULL */
3774  if (N < 1.0)
3775  PG_RETURN_NULL();
3776 
3777  /* Note that Sxx is guaranteed to be non-negative */
3778 
3779  /* per spec, return NULL for a vertical line */
3780  if (Sxx == 0)
3781  PG_RETURN_NULL();
3782 
3783  PG_RETURN_FLOAT8(Sxy / Sxx);
3784 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_sxx()

Datum float8_regr_sxx ( PG_FUNCTION_ARGS  )

Definition at line 3559 of file float.c.

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

3560 {
3561  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3562  float8 *transvalues;
3563  float8 N,
3564  Sxx;
3565 
3566  transvalues = check_float8_array(transarray, "float8_regr_sxx", 6);
3567  N = transvalues[0];
3568  Sxx = transvalues[2];
3569 
3570  /* if N is 0 we should return NULL */
3571  if (N < 1.0)
3572  PG_RETURN_NULL();
3573 
3574  /* Note that Sxx is guaranteed to be non-negative */
3575 
3576  PG_RETURN_FLOAT8(Sxx);
3577 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_sxy()

Datum float8_regr_sxy ( PG_FUNCTION_ARGS  )

Definition at line 3601 of file float.c.

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

3602 {
3603  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3604  float8 *transvalues;
3605  float8 N,
3606  Sxy;
3607 
3608  transvalues = check_float8_array(transarray, "float8_regr_sxy", 6);
3609  N = transvalues[0];
3610  Sxy = transvalues[5];
3611 
3612  /* if N is 0 we should return NULL */
3613  if (N < 1.0)
3614  PG_RETURN_NULL();
3615 
3616  /* A negative result is valid here */
3617 
3618  PG_RETURN_FLOAT8(Sxy);
3619 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_regr_syy()

Datum float8_regr_syy ( PG_FUNCTION_ARGS  )

Definition at line 3580 of file float.c.

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

3581 {
3582  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3583  float8 *transvalues;
3584  float8 N,
3585  Syy;
3586 
3587  transvalues = check_float8_array(transarray, "float8_regr_syy", 6);
3588  N = transvalues[0];
3589  Syy = transvalues[4];
3590 
3591  /* if N is 0 we should return NULL */
3592  if (N < 1.0)
3593  PG_RETURN_NULL();
3594 
3595  /* Note that Syy is guaranteed to be non-negative */
3596 
3597  PG_RETURN_FLOAT8(Syy);
3598 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_stddev_pop()

Datum float8_stddev_pop ( PG_FUNCTION_ARGS  )

Definition at line 3236 of file float.c.

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

3237 {
3238  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3239  float8 *transvalues;
3240  float8 N,
3241  Sxx;
3242 
3243  transvalues = check_float8_array(transarray, "float8_stddev_pop", 3);
3244  N = transvalues[0];
3245  /* ignore Sx */
3246  Sxx = transvalues[2];
3247 
3248  /* Population stddev is undefined when N is 0, so return NULL */
3249  if (N == 0.0)
3250  PG_RETURN_NULL();
3251 
3252  /* Note that Sxx is guaranteed to be non-negative */
3253 
3254  PG_RETURN_FLOAT8(sqrt(Sxx / N));
3255 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_stddev_samp()

Datum float8_stddev_samp ( PG_FUNCTION_ARGS  )

Definition at line 3258 of file float.c.

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

3259 {
3260  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3261  float8 *transvalues;
3262  float8 N,
3263  Sxx;
3264 
3265  transvalues = check_float8_array(transarray, "float8_stddev_samp", 3);
3266  N = transvalues[0];
3267  /* ignore Sx */
3268  Sxx = transvalues[2];
3269 
3270  /* Sample stddev is undefined when N is 0 or 1, so return NULL */
3271  if (N <= 1.0)
3272  PG_RETURN_NULL();
3273 
3274  /* Note that Sxx is guaranteed to be non-negative */
3275 
3276  PG_RETURN_FLOAT8(sqrt(Sxx / (N - 1.0)));
3277 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_var_pop()

Datum float8_var_pop ( PG_FUNCTION_ARGS  )

Definition at line 3192 of file float.c.

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

3193 {
3194  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3195  float8 *transvalues;
3196  float8 N,
3197  Sxx;
3198 
3199  transvalues = check_float8_array(transarray, "float8_var_pop", 3);
3200  N = transvalues[0];
3201  /* ignore Sx */
3202  Sxx = transvalues[2];
3203 
3204  /* Population variance is undefined when N is 0, so return NULL */
3205  if (N == 0.0)
3206  PG_RETURN_NULL();
3207 
3208  /* Note that Sxx is guaranteed to be non-negative */
3209 
3210  PG_RETURN_FLOAT8(Sxx / N);
3211 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8_var_samp()

Datum float8_var_samp ( PG_FUNCTION_ARGS  )

Definition at line 3214 of file float.c.

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

3215 {
3216  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3217  float8 *transvalues;
3218  float8 N,
3219  Sxx;
3220 
3221  transvalues = check_float8_array(transarray, "float8_var_samp", 3);
3222  N = transvalues[0];
3223  /* ignore Sx */
3224  Sxx = transvalues[2];
3225 
3226  /* Sample variance is undefined when N is 0 or 1, so return NULL */
3227  if (N <= 1.0)
3228  PG_RETURN_NULL();
3229 
3230  /* Note that Sxx is guaranteed to be non-negative */
3231 
3232  PG_RETURN_FLOAT8(Sxx / (N - 1.0));
3233 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:498
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2886
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ float8abs()

Datum float8abs ( PG_FUNCTION_ARGS  )

Definition at line 685 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

686 {
687  float8 arg1 = PG_GETARG_FLOAT8(0);
688 
689  PG_RETURN_FLOAT8(fabs(arg1));
690 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ float8div()

Datum float8div ( PG_FUNCTION_ARGS  )

Definition at line 825 of file float.c.

References float8_div(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

826 {
827  float8 arg1 = PG_GETARG_FLOAT8(0);
828  float8 arg2 = PG_GETARG_FLOAT8(1);
829 
830  PG_RETURN_FLOAT8(float8_div(arg1, arg2));
831 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ float8eq()

Datum float8eq ( PG_FUNCTION_ARGS  )

Definition at line 948 of file float.c.

References float8_eq(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

949 {
950  float8 arg1 = PG_GETARG_FLOAT8(0);
951  float8 arg2 = PG_GETARG_FLOAT8(1);
952 
953  PG_RETURN_BOOL(float8_eq(arg1, arg2));
954 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:267

◆ float8ge()

Datum float8ge ( PG_FUNCTION_ARGS  )

Definition at line 993 of file float.c.

References float8_ge(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

994 {
995  float8 arg1 = PG_GETARG_FLOAT8(0);
996  float8 arg2 = PG_GETARG_FLOAT8(1);
997 
998  PG_RETURN_BOOL(float8_ge(arg1, arg2));
999 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
static bool float8_ge(const float8 val1, const float8 val2)
Definition: float.h:327
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float8gt()

Datum float8gt ( PG_FUNCTION_ARGS  )

Definition at line 984 of file float.c.

References float8_gt(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

985 {
986  float8 arg1 = PG_GETARG_FLOAT8(0);
987  float8 arg2 = PG_GETARG_FLOAT8(1);
988 
989  PG_RETURN_BOOL(float8_gt(arg1, arg2));
990 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float8in()

Datum float8in ( PG_FUNCTION_ARGS  )

Definition at line 351 of file float.c.

References float8in_internal(), PG_GETARG_CSTRING, and PG_RETURN_FLOAT8.

Referenced by numeric_float8().

352 {
353  char *num = PG_GETARG_CSTRING(0);
354 
355  PG_RETURN_FLOAT8(float8in_internal(num, NULL, "double precision", num));
356 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string)
Definition: float.c:537
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

◆ float8in_internal()

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

Definition at line 537 of file float.c.

References float8in_internal_opt_error().

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

539 {
540  return float8in_internal_opt_error(num, endptr_p, type_name,
541  orig_string, NULL);
542 }
double float8in_internal_opt_error(char *num, char **endptr_p, const char *type_name, const char *orig_string, bool *have_error)
Definition: float.c:391

◆ float8in_internal_opt_error()

double float8in_internal_opt_error ( char *  num,
char **  endptr_p,
const char *  type_name,
const char *  orig_string,
bool have_error 
)

Definition at line 391 of file float.c.

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

Referenced by executeItemOptUnwrapTarget(), and float8in_internal().

394 {
395  double val;
396  char *endptr;
397 
398  if (have_error)
399  *have_error = false;
400 
401  /* skip leading whitespace */
402  while (*num != '\0' && isspace((unsigned char) *num))
403  num++;
404 
405  /*
406  * Check for an empty-string input to begin with, to avoid the vagaries of
407  * strtod() on different platforms.
408  */
409  if (*num == '\0')
411  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
412  errmsg("invalid input syntax for type %s: \"%s\"",
413  type_name, orig_string))),
414  have_error);
415 
416  errno = 0;
417  val = strtod(num, &endptr);
418 
419  /* did we not see anything that looks like a double? */
420  if (endptr == num || errno != 0)
421  {
422  int save_errno = errno;
423 
424  /*
425  * C99 requires that strtod() accept NaN, [+-]Infinity, and [+-]Inf,
426  * but not all platforms support all of these (and some accept them
427  * but set ERANGE anyway...) Therefore, we check for these inputs
428  * ourselves if strtod() fails.
429  *
430  * Note: C99 also requires hexadecimal input as well as some extended
431  * forms of NaN, but we consider these forms unportable and don't try
432  * to support them. You can use 'em if your strtod() takes 'em.
433  */
434  if (pg_strncasecmp(num, "NaN", 3) == 0)
435  {
436  val = get_float8_nan();
437  endptr = num + 3;
438  }
439  else if (pg_strncasecmp(num, "Infinity", 8) == 0)
440  {
441  val = get_float8_infinity();
442  endptr = num + 8;
443  }
444  else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
445  {
446  val = get_float8_infinity();
447  endptr = num + 9;
448  }
449  else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
450  {
451  val = -get_float8_infinity();
452  endptr = num + 9;
453  }
454  else if (pg_strncasecmp(num, "inf", 3) == 0)
455  {
456  val = get_float8_infinity();
457  endptr = num + 3;
458  }
459  else if (pg_strncasecmp(num, "+inf", 4) == 0)
460  {
461  val = get_float8_infinity();
462  endptr = num + 4;
463  }
464  else if (pg_strncasecmp(num, "-inf", 4) == 0)
465  {
466  val = -get_float8_infinity();
467  endptr = num + 4;
468  }
469  else if (save_errno == ERANGE)
470  {
471  /*
472  * Some platforms return ERANGE for denormalized numbers (those
473  * that are not zero, but are too close to zero to have full
474  * precision). We'd prefer not to throw error for that, so try to
475  * detect whether it's a "real" out-of-range condition by checking
476  * to see if the result is zero or huge.
477  *
478  * On error, we intentionally complain about double precision not
479  * the given type name, and we print only the part of the string
480  * that is the current number.
481  */
482  if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL)
483  {
484  char *errnumber = pstrdup(num);
485 
486  errnumber[endptr - num] = '\0';
488  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
489  errmsg("\"%s\" is out of range for type double precision",
490  errnumber))),
491  have_error);
492  }
493  }
494  else
496  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
497  errmsg("invalid input syntax for type "
498  "%s: \"%s\"",
499  type_name, orig_string))),
500  have_error);
501  }
502 #ifdef HAVE_BUGGY_SOLARIS_STRTOD
503  else
504  {
505  /*
506  * Many versions of Solaris have a bug wherein strtod sets endptr to
507  * point one byte beyond the end of the string when given "inf" or
508  * "infinity".
509  */
510  if (endptr != num && endptr[-1] == '\0')
511  endptr--;
512  }
513 #endif /* HAVE_BUGGY_SOLARIS_STRTOD */
514 
515  /* skip trailing whitespace */
516  while (*endptr != '\0' && isspace((unsigned char) *endptr))
517  endptr++;
518 
519  /* report stopping point if wanted, else complain if not end of string */
520  if (endptr_p)
521  *endptr_p = endptr;
522  else if (*endptr != '\0')
524  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
525  errmsg("invalid input syntax for type "
526  "%s: \"%s\"",
527  type_name, orig_string))),
528  have_error);
529 
530  return val;
531 }
static float8 get_float8_infinity(void)
Definition: float.h:93
char * pstrdup(const char *in)
Definition: mcxt.c:1186
int errcode(int sqlerrcode)
Definition: elog.c:610
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:144
#define RETURN_ERROR(throw_error, have_error)
Definition: float.c:359
int errmsg(const char *fmt,...)
Definition: elog.c:824
long val
Definition: informix.c:664

◆ float8larger()

Datum float8larger ( PG_FUNCTION_ARGS  )

Definition at line 715 of file float.c.

References float8_gt(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

716 {
717  float8 arg1 = PG_GETARG_FLOAT8(0);
718  float8 arg2 = PG_GETARG_FLOAT8(1);
719  float8 result;
720 
721  if (float8_gt(arg1, arg2))
722  result = arg1;
723  else
724  result = arg2;
725  PG_RETURN_FLOAT8(result);
726 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float8le()

Datum float8le ( PG_FUNCTION_ARGS  )

Definition at line 975 of file float.c.

References float8_le(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

976 {
977  float8 arg1 = PG_GETARG_FLOAT8(0);
978  float8 arg2 = PG_GETARG_FLOAT8(1);
979 
980  PG_RETURN_BOOL(float8_le(arg1, arg2));
981 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static bool float8_le(const float8 val1, const float8 val2)
Definition: float.h:303
double float8
Definition: c.h:498
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float8lt()

Datum float8lt ( PG_FUNCTION_ARGS  )

Definition at line 966 of file float.c.

References float8_lt(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

967 {
968  float8 arg1 = PG_GETARG_FLOAT8(0);
969  float8 arg2 = PG_GETARG_FLOAT8(1);
970 
971  PG_RETURN_BOOL(float8_lt(arg1, arg2));
972 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
double float8
Definition: c.h:498
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float8mi()

Datum float8mi ( PG_FUNCTION_ARGS  )

Definition at line 807 of file float.c.

References float8_mi(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

808 {
809  float8 arg1 = PG_GETARG_FLOAT8(0);
810  float8 arg2 = PG_GETARG_FLOAT8(1);
811 
812  PG_RETURN_FLOAT8(float8_mi(arg1, arg2));
813 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181

◆ float8mul()

Datum float8mul ( PG_FUNCTION_ARGS  )

Definition at line 816 of file float.c.

References float8_mul(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

817 {
818  float8 arg1 = PG_GETARG_FLOAT8(0);
819  float8 arg2 = PG_GETARG_FLOAT8(1);
820 
821  PG_RETURN_FLOAT8(float8_mul(arg1, arg2));
822 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
double float8
Definition: c.h:498

◆ float8ne()

Datum float8ne ( PG_FUNCTION_ARGS  )

Definition at line 957 of file float.c.

References float8_ne(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

958 {
959  float8 arg1 = PG_GETARG_FLOAT8(0);
960  float8 arg2 = PG_GETARG_FLOAT8(1);
961 
962  PG_RETURN_BOOL(float8_ne(arg1, arg2));
963 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
static bool float8_ne(const float8 val1, const float8 val2)
Definition: float.h:279
double float8
Definition: c.h:498
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ float8out()

Datum float8out ( PG_FUNCTION_ARGS  )

Definition at line 550 of file float.c.

References float8out_internal(), PG_GETARG_FLOAT8, and PG_RETURN_CSTRING.

551 {
552  float8 num = PG_GETARG_FLOAT8(0);
553 
555 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
char * float8out_internal(double num)
Definition: float.c:565
double float8
Definition: c.h:498
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361

◆ float8out_internal()

char* float8out_internal ( double  num)

Definition at line 565 of file float.c.

References ascii(), double_to_shortest_decimal_buf(), extra_float_digits, palloc(), and pg_strfromd().

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

566 {
567  char *ascii = (char *) palloc(32);
568  int ndig = DBL_DIG + extra_float_digits;
569 
570  if (extra_float_digits > 0)
571  {
572  double_to_shortest_decimal_buf(num, ascii);
573  return ascii;
574  }
575 
576  (void) pg_strfromd(ascii, 32, ndig, num);
577  return ascii;
578 }
Datum ascii(PG_FUNCTION_ARGS)
int pg_strfromd(char *str, size_t count, int precision, double value)
Definition: snprintf.c:1263
int extra_float_digits
Definition: float.c:42
int double_to_shortest_decimal_buf(double f, char *result)
Definition: d2s.c:1053
void * palloc(Size size)
Definition: mcxt.c:949

◆ float8pl()

Datum float8pl ( PG_FUNCTION_ARGS  )

Definition at line 798 of file float.c.

References float8_pl(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

799 {
800  float8 arg1 = PG_GETARG_FLOAT8(0);
801  float8 arg2 = PG_GETARG_FLOAT8(1);
802 
803  PG_RETURN_FLOAT8(float8_pl(arg1, arg2));
804 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157

◆ float8recv()

Datum float8recv ( PG_FUNCTION_ARGS  )

Definition at line 584 of file float.c.

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

585 {
587 
589 }
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
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 595 of file float.c.

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

596 {
597  float8 num = PG_GETARG_FLOAT8(0);
599 
600  pq_begintypsend(&buf);
601  pq_sendfloat8(&buf, num);
603 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
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:369
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
double float8
Definition: c.h:498
static char * buf
Definition: pg_test_fsync.c:67

◆ float8smaller()

Datum float8smaller ( PG_FUNCTION_ARGS  )

Definition at line 729 of file float.c.

References float8_lt(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

730 {
731  float8 arg1 = PG_GETARG_FLOAT8(0);
732  float8 arg2 = PG_GETARG_FLOAT8(1);
733  float8 result;
734 
735  if (float8_lt(arg1, arg2))
736  result = arg1;
737  else
738  result = arg2;
739  PG_RETURN_FLOAT8(result);
740 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291

◆ float8um()

Datum float8um ( PG_FUNCTION_ARGS  )

Definition at line 697 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

698 {
699  float8 arg1 = PG_GETARG_FLOAT8(0);
700  float8 result;
701 
702  result = -arg1;
703  PG_RETURN_FLOAT8(result);
704 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498

◆ float8up()

Datum float8up ( PG_FUNCTION_ARGS  )

Definition at line 707 of file float.c.

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

708 {
710 
711  PG_RETURN_FLOAT8(arg);
712 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
void * arg

◆ float_overflow_error()

pg_noinline void float_overflow_error ( void  )

Definition at line 84 of file float.c.

References ereport, errcode(), errmsg(), ERROR, and pg_noinline.

Referenced by dacos(), dacosd(), dasin(), dasind(), datan(), datan2(), datan2d(), datand(), dcbrt(), dcos(), dcosd(), dexp(), dlog1(), dlog10(), dpow(), dsin(), dsind(), dsqrt(), dtanh(), dtof(), float4_accum(), float4_div(), float4_mi(), float4_mul(), float4_pl(), float8_accum(), float8_combine(), float8_div(), float8_mi(), float8_mul(), float8_pl(), float8_regr_accum(), float8_regr_combine(), and pg_hypot().

85 {
86  ereport(ERROR,
87  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
88  errmsg("value out of range: overflow")));
89 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ float_underflow_error()

pg_noinline void float_underflow_error ( void  )

Definition at line 92 of file float.c.

References ereport, errcode(), errmsg(), ERROR, and pg_noinline.

Referenced by dcbrt(), dcosh(), dexp(), dlog1(), dlog10(), dpow(), dsqrt(), dtof(), float4_div(), float4_mul(), float8_div(), float8_mul(), and pg_hypot().

93 {
94  ereport(ERROR,
95  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
96  errmsg("value out of range: underflow")));
97 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ float_zero_divide_error()

pg_noinline void float_zero_divide_error ( void  )

Definition at line 100 of file float.c.

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

Referenced by float4_div(), and float8_div().

101 {
102  ereport(ERROR,
103  (errcode(ERRCODE_DIVISION_BY_ZERO),
104  errmsg("division by zero")));
105 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ftod()

Datum ftod ( PG_FUNCTION_ARGS  )

Definition at line 1211 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT8.

1212 {
1213  float4 num = PG_GETARG_FLOAT4(0);
1214 
1215  PG_RETURN_FLOAT8((float8) num);
1216 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497

◆ ftoi2()

Datum ftoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1341 of file float.c.

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

1342 {
1343  float4 num = PG_GETARG_FLOAT4(0);
1344 
1345  /*
1346  * Get rid of any fractional part in the input. This is so we don't fail
1347  * on just-out-of-range values that would round into range. Note
1348  * assumption that rint() will pass through a NaN or Inf unchanged.
1349  */
1350  num = rint(num);
1351 
1352  /* Range check */
1353  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT16(num)))
1354  ereport(ERROR,
1355  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1356  errmsg("smallint out of range")));
1357 
1358  PG_RETURN_INT16((int16) num);
1359 }
signed short int16
Definition: c.h:361
#define PG_RETURN_INT16(x)
Definition: fmgr.h:355
int errcode(int sqlerrcode)
Definition: elog.c:610
#define FLOAT4_FITS_IN_INT16(num)
Definition: c.h:1067
#define ERROR
Definition: elog.h:43
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ ftoi4()

Datum ftoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1316 of file float.c.

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

1317 {
1318  float4 num = PG_GETARG_FLOAT4(0);
1319 
1320  /*
1321  * Get rid of any fractional part in the input. This is so we don't fail
1322  * on just-out-of-range values that would round into range. Note
1323  * assumption that rint() will pass through a NaN or Inf unchanged.
1324  */
1325  num = rint(num);
1326 
1327  /* Range check */
1328  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT32(num)))
1329  ereport(ERROR,
1330  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1331  errmsg("integer out of range")));
1332 
1333  PG_RETURN_INT32((int32) num);
1334 }
#define FLOAT4_FITS_IN_INT32(num)
Definition: c.h:1069
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:362
#define ERROR
Definition: elog.h:43
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ i2tod()

Datum i2tod ( PG_FUNCTION_ARGS  )

Definition at line 1304 of file float.c.

References PG_GETARG_INT16, and PG_RETURN_FLOAT8.

1305 {
1306  int16 num = PG_GETARG_INT16(0);
1307 
1308  PG_RETURN_FLOAT8((float8) num);
1309 }
signed short int16
Definition: c.h:361
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:498
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271

◆ i2tof()

Datum i2tof ( PG_FUNCTION_ARGS  )

Definition at line 1378 of file float.c.

References PG_GETARG_INT16, and PG_RETURN_FLOAT4.

1379 {
1380  int16 num = PG_GETARG_INT16(0);
1381 
1382  PG_RETURN_FLOAT4((float4) num);
1383 }
signed short int16
Definition: c.h:361
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
float float4
Definition: c.h:497
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271

◆ i4tod()

Datum i4tod ( PG_FUNCTION_ARGS  )

Definition at line 1292 of file float.c.

References PG_GETARG_INT32, and PG_RETURN_FLOAT8.

1293 {
1294  int32 num = PG_GETARG_INT32(0);
1295 
1296  PG_RETURN_FLOAT8((float8) num);
1297 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
signed int int32
Definition: c.h:362
double float8
Definition: c.h:498

◆ i4tof()

Datum i4tof ( PG_FUNCTION_ARGS  )

Definition at line 1366 of file float.c.

References PG_GETARG_INT32, and PG_RETURN_FLOAT4.

1367 {
1368  int32 num = PG_GETARG_INT32(0);
1369 
1370  PG_RETURN_FLOAT4((float4) num);
1371 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:364
signed int int32
Definition: c.h:362
float float4
Definition: c.h:497

◆ in_range_float4_float8()

Datum in_range_float4_float8 ( PG_FUNCTION_ARGS  )

Definition at line 1131 of file float.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_BOOL, PG_GETARG_FLOAT4, PG_GETARG_FLOAT8, PG_RETURN_BOOL, and val.

1132 {
1134  float4 base = PG_GETARG_FLOAT4(1);
1135  float8 offset = PG_GETARG_FLOAT8(2);
1136  bool sub = PG_GETARG_BOOL(3);
1137  bool less = PG_GETARG_BOOL(4);
1138  float8 sum;
1139 
1140  /*
1141  * Reject negative or NaN offset. Negative is per spec, and NaN is
1142  * because appropriate semantics for that seem non-obvious.
1143  */
1144  if (isnan(offset) || offset < 0)
1145  ereport(ERROR,
1146  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1147  errmsg("invalid preceding or following size in window function")));
1148 
1149  /*
1150  * Deal with cases where val and/or base is NaN, following the rule that
1151  * NaN sorts after non-NaN (cf float8_cmp_internal). The offset cannot
1152  * affect the conclusion.
1153  */
1154  if (isnan(val))
1155  {
1156  if (isnan(base))
1157  PG_RETURN_BOOL(true); /* NAN = NAN */
1158  else
1159  PG_RETURN_BOOL(!less); /* NAN > non-NAN */
1160  }
1161  else if (isnan(base))
1162  {
1163  PG_RETURN_BOOL(less); /* non-NAN < NAN */
1164  }
1165 
1166  /*
1167  * Deal with cases where both base and offset are infinite, and computing
1168  * base +/- offset would produce NaN. This corresponds to a window frame
1169  * whose boundary infinitely precedes +inf or infinitely follows -inf,
1170  * which is not well-defined. For consistency with other cases involving
1171  * infinities, such as the fact that +inf infinitely follows +inf, we
1172  * choose to assume that +inf infinitely precedes +inf and -inf infinitely
1173  * follows -inf, and therefore that all finite and infinite values are in
1174  * such a window frame.
1175  *
1176  * offset is known positive, so we need only check the sign of base in
1177  * this test.
1178  */
1179  if (isinf(offset) && isinf(base) &&
1180  (sub ? base > 0 : base < 0))
1181  PG_RETURN_BOOL(true);
1182 
1183  /*
1184  * Otherwise it should be safe to compute base +/- offset. We trust the
1185  * FPU to cope if an input is +/-inf or the true sum would overflow, and
1186  * produce a suitably signed infinity, which will compare properly against
1187  * val whether or not that's infinity.
1188  */
1189  if (sub)
1190  sum = base - offset;
1191  else
1192  sum = base + offset;
1193 
1194  if (less)
1195  PG_RETURN_BOOL(val <= sum);
1196  else
1197  PG_RETURN_BOOL(val >= sum);
1198 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:280
float float4
Definition: c.h:497
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
long val
Definition: informix.c:664

◆ in_range_float8_float8()

Datum in_range_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 1055 of file float.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_BOOL, PG_GETARG_FLOAT8, PG_RETURN_BOOL, and val.

1056 {
1058  float8 base = PG_GETARG_FLOAT8(1);
1059  float8 offset = PG_GETARG_FLOAT8(2);
1060  bool sub = PG_GETARG_BOOL(3);
1061  bool less = PG_GETARG_BOOL(4);
1062  float8 sum;
1063 
1064  /*
1065  * Reject negative or NaN offset. Negative is per spec, and NaN is
1066  * because appropriate semantics for that seem non-obvious.
1067  */
1068  if (isnan(offset) || offset < 0)
1069  ereport(ERROR,
1070  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1071  errmsg("invalid preceding or following size in window function")));
1072 
1073  /*
1074  * Deal with cases where val and/or base is NaN, following the rule that
1075  * NaN sorts after non-NaN (cf float8_cmp_internal). The offset cannot
1076  * affect the conclusion.
1077  */
1078  if (isnan(val))
1079  {
1080  if (isnan(base))
1081  PG_RETURN_BOOL(true); /* NAN = NAN */
1082  else
1083  PG_RETURN_BOOL(!less); /* NAN > non-NAN */
1084  }
1085  else if (isnan(base))
1086  {
1087  PG_RETURN_BOOL(less); /* non-NAN < NAN */
1088  }
1089 
1090  /*
1091  * Deal with cases where both base and offset are infinite, and computing
1092  * base +/- offset would produce NaN. This corresponds to a window frame
1093  * whose boundary infinitely precedes +inf or infinitely follows -inf,
1094  * which is not well-defined. For consistency with other cases involving
1095  * infinities, such as the fact that +inf infinitely follows +inf, we
1096  * choose to assume that +inf infinitely precedes +inf and -inf infinitely
1097  * follows -inf, and therefore that all finite and infinite values are in
1098  * such a window frame.
1099  *
1100  * offset is known positive, so we need only check the sign of base in
1101  * this test.
1102  */
1103  if (isinf(offset) && isinf(base) &&
1104  (sub ? base > 0 : base < 0))
1105  PG_RETURN_BOOL(true);
1106 
1107  /*
1108  * Otherwise it should be safe to compute base +/- offset. We trust the
1109  * FPU to cope if an input is +/-inf or the true sum would overflow, and
1110  * produce a suitably signed infinity, which will compare properly against
1111  * val whether or not that's infinity.
1112  */
1113  if (sub)
1114  sum = base - offset;
1115  else
1116  sum = base + offset;
1117 
1118  if (less)
1119  PG_RETURN_BOOL(val <= sum);
1120  else
1121  PG_RETURN_BOOL(val >= sum);
1122 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
long val
Definition: informix.c:664

◆ init_degree_constants()

static void init_degree_constants ( void  )
static

Definition at line 2047 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.

2048 {
2051  asin_0_5 = asin(degree_c_one_half);
2052  acos_0_5 = acos(degree_c_one_half);
2053  atan_1_0 = atan(degree_c_one);
2056  degree_consts_set = true;
2057 }
float8 degree_c_sixty
Definition: float.c:62
static float8 cot_45
Definition: float.c:52
#define RADIANS_PER_DEGREE
Definition: float.h:26
float8 degree_c_one
Definition: float.c:64
float8 degree_c_one_half
Definition: float.c:63
static bool degree_consts_set
Definition: float.c:45
static double sind_q1(double x)
Definition: float.c:2307
static float8 acos_0_5
Definition: float.c:49
float8 degree_c_thirty
Definition: float.c:60
static float8 atan_1_0
Definition: float.c:50
float8 degree_c_forty_five
Definition: float.c:61
static float8 sin_30
Definition: float.c:46
static float8 one_minus_cos_60
Definition: float.c:47
static double cosd_q1(double x)
Definition: float.c:2327
static float8 asin_0_5
Definition: float.c:48
static float8 tan_45
Definition: float.c:51

◆ is_infinite()

int is_infinite ( double  val)

Definition at line 116 of file float.c.

117 {
118  int inf = isinf(val);
119 
120  if (inf == 0)
121  return 0;
122  else if (val > 0)
123  return 1;
124  else
125  return -1;
126 }
long val
Definition: informix.c:664

◆ radians()

Datum radians ( PG_FUNCTION_ARGS  )

Definition at line 2611 of file float.c.

References float8_mul(),