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 2035 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 347 of file float.c.

Referenced by float8in_internal_opt_error().

Function Documentation

◆ acosd_q1()

static double acosd_q1 ( double  x)
static

Definition at line 2085 of file float.c.

References acos_0_5, and asin_0_5.

Referenced by dacosd().

2086 {
2087  /*
2088  * Stitch together inverse sine and cosine functions for the ranges [0,
2089  * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
2090  * exactly 60 for x=0.5, so the result is a continuous monotonic function
2091  * over the full range.
2092  */
2093  if (x <= 0.5)
2094  {
2095  volatile float8 asin_x = asin(x);
2096 
2097  return 90.0 - (asin_x / asin_0_5) * 30.0;
2098  }
2099  else
2100  {
2101  volatile float8 acos_x = acos(x);
2102 
2103  return (acos_x / acos_0_5) * 60.0;
2104  }
2105 }
static float8 acos_0_5
Definition: float.c:49
double float8
Definition: c.h:553
static float8 asin_0_5
Definition: float.c:48

◆ asind_q1()

static double asind_q1 ( double  x)
static

Definition at line 2052 of file float.c.

References acos_0_5, and asin_0_5.

Referenced by dacosd(), and dasind().

2053 {
2054  /*
2055  * Stitch together inverse sine and cosine functions for the ranges [0,
2056  * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
2057  * exactly 30 for x=0.5, so the result is a continuous monotonic function
2058  * over the full range.
2059  */
2060  if (x <= 0.5)
2061  {
2062  volatile float8 asin_x = asin(x);
2063 
2064  return (asin_x / asin_0_5) * 30.0;
2065  }
2066  else
2067  {
2068  volatile float8 acos_x = acos(x);
2069 
2070  return 90.0 - (acos_x / acos_0_5) * 60.0;
2071  }
2072 }
static float8 acos_0_5
Definition: float.c:49
double float8
Definition: c.h:553
static float8 asin_0_5
Definition: float.c:48

◆ btfloat48cmp()

Datum btfloat48cmp ( PG_FUNCTION_ARGS  )

Definition at line 1005 of file float.c.

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

1006 {
1007  float4 arg1 = PG_GETARG_FLOAT4(0);
1008  float8 arg2 = PG_GETARG_FLOAT8(1);
1009 
1010  /* widen float4 to float8 and then compare */
1011  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1012 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:914
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ btfloat4cmp()

Datum btfloat4cmp ( PG_FUNCTION_ARGS  )

Definition at line 884 of file float.c.

References float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_INT32.

Referenced by leftmostvalue_float4().

885 {
886  float4 arg1 = PG_GETARG_FLOAT4(0);
887  float4 arg2 = PG_GETARG_FLOAT4(1);
888 
890 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:820
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ btfloat4fastcmp()

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

Definition at line 893 of file float.c.

References DatumGetFloat4(), and float4_cmp_internal().

Referenced by btfloat4sortsupport().

894 {
895  float4 arg1 = DatumGetFloat4(x);
896  float4 arg2 = DatumGetFloat4(y);
897 
898  return float4_cmp_internal(arg1, arg2);
899 }
int float4_cmp_internal(float4 a, float4 b)
Definition: float.c:820
static float4 DatumGetFloat4(Datum X)
Definition: postgres.h:664
float float4
Definition: c.h:552

◆ btfloat4sortsupport()

Datum btfloat4sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 902 of file float.c.

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

903 {
905 
906  ssup->comparator = btfloat4fastcmp;
907  PG_RETURN_VOID();
908 }
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:349
static int btfloat4fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: float.c:893

◆ btfloat84cmp()

Datum btfloat84cmp ( PG_FUNCTION_ARGS  )

Definition at line 1015 of file float.c.

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

1016 {
1017  float8 arg1 = PG_GETARG_FLOAT8(0);
1018  float4 arg2 = PG_GETARG_FLOAT4(1);
1019 
1020  /* widen float4 to float8 and then compare */
1021  PG_RETURN_INT32(float8_cmp_internal(arg1, arg2));
1022 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:914
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ btfloat8cmp()

Datum btfloat8cmp ( PG_FUNCTION_ARGS  )

Definition at line 978 of file float.c.

References float8_cmp_internal(), PG_GETARG_FLOAT8, and PG_RETURN_INT32.

Referenced by leftmostvalue_float8().

979 {
980  float8 arg1 = PG_GETARG_FLOAT8(0);
981  float8 arg2 = PG_GETARG_FLOAT8(1);
982 
984 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:914
double float8
Definition: c.h:553

◆ btfloat8fastcmp()

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

Definition at line 987 of file float.c.

References DatumGetFloat8, and float8_cmp_internal().

Referenced by btfloat8sortsupport().

988 {
989  float8 arg1 = DatumGetFloat8(x);
990  float8 arg2 = DatumGetFloat8(y);
991 
992  return float8_cmp_internal(arg1, arg2);
993 }
int float8_cmp_internal(float8 a, float8 b)
Definition: float.c:914
double float8
Definition: c.h:553
#define DatumGetFloat8(X)
Definition: postgres.h:714

◆ btfloat8sortsupport()

Datum btfloat8sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 996 of file float.c.

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

997 {
999 
1000  ssup->comparator = btfloat8fastcmp;
1001  PG_RETURN_VOID();
1002 }
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:987
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
#define PG_RETURN_VOID()
Definition: fmgr.h:349

◆ check_float8_array()

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

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

2863 {
2864  /*
2865  * We expect the input to be an N-element float array; verify that. We
2866  * don't need to use deconstruct_array() since the array data is just
2867  * going to look like a C array of N float8 values.
2868  */
2869  if (ARR_NDIM(transarray) != 1 ||
2870  ARR_DIMS(transarray)[0] != n ||
2871  ARR_HASNULL(transarray) ||
2872  ARR_ELEMTYPE(transarray) != FLOAT8OID)
2873  elog(ERROR, "%s: expected %d-element float8 array", caller, n);
2874  return (float8 *) ARR_DATA_PTR(transarray);
2875 }
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#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:228
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ cosd_0_to_60()

static double cosd_0_to_60 ( double  x)
static

Definition at line 2270 of file float.c.

References one_minus_cos_60, and RADIANS_PER_DEGREE.

Referenced by cosd_q1(), and sind_q1().

2271 {
2272  volatile float8 one_minus_cos_x = 1.0 - cos(x * RADIANS_PER_DEGREE);
2273 
2274  return 1.0 - (one_minus_cos_x / one_minus_cos_60) / 2.0;
2275 }
#define RADIANS_PER_DEGREE
Definition: float.h:26
double float8
Definition: c.h:553
static float8 one_minus_cos_60
Definition: float.c:47

◆ cosd_q1()

static double cosd_q1 ( double  x)
static

Definition at line 2303 of file float.c.

References cosd_0_to_60(), and sind_0_to_30().

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

2304 {
2305  /*
2306  * Stitch together the sine and cosine functions for the ranges [0, 60]
2307  * and (60, 90]. These guarantee to return exact answers at their
2308  * endpoints, so the overall result is a continuous monotonic function
2309  * that gives exact results when x = 0, 60 and 90 degrees.
2310  */
2311  if (x <= 60.0)
2312  return cosd_0_to_60(x);
2313  else
2314  return sind_0_to_30(90.0 - x);
2315 }
static double cosd_0_to_60(double x)
Definition: float.c:2270
static double sind_0_to_30(double x)
Definition: float.c:2256

◆ dacos()

Datum dacos ( PG_FUNCTION_ARGS  )

Definition at line 1759 of file float.c.

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

1760 {
1761  float8 arg1 = PG_GETARG_FLOAT8(0);
1762  float8 result;
1763 
1764  /* Per the POSIX spec, return NaN if the input is NaN */
1765  if (isnan(arg1))
1767 
1768  /*
1769  * The principal branch of the inverse cosine function maps values in the
1770  * range [-1, 1] to values in the range [0, Pi], so we should reject any
1771  * inputs outside that range and the result will always be finite.
1772  */
1773  if (arg1 < -1.0 || arg1 > 1.0)
1774  ereport(ERROR,
1775  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1776  errmsg("input is out of range")));
1777 
1778  result = acos(arg1);
1779  if (unlikely(isinf(result)))
1781 
1782  PG_RETURN_FLOAT8(result);
1783 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dacosd()

Datum dacosd ( PG_FUNCTION_ARGS  )

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

2113 {
2114  float8 arg1 = PG_GETARG_FLOAT8(0);
2115  float8 result;
2116 
2117  /* Per the POSIX spec, return NaN if the input is NaN */
2118  if (isnan(arg1))
2120 
2122 
2123  /*
2124  * The principal branch of the inverse cosine function maps values in the
2125  * range [-1, 1] to values in the range [0, 180], so we should reject any
2126  * inputs outside that range and the result will always be finite.
2127  */
2128  if (arg1 < -1.0 || arg1 > 1.0)
2129  ereport(ERROR,
2130  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2131  errmsg("input is out of range")));
2132 
2133  if (arg1 >= 0.0)
2134  result = acosd_q1(arg1);
2135  else
2136  result = 90.0 + asind_q1(-arg1);
2137 
2138  if (unlikely(isinf(result)))
2140 
2141  PG_RETURN_FLOAT8(result);
2142 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
static double asind_q1(double x)
Definition: float.c:2052
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static double acosd_q1(double x)
Definition: float.c:2085
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dacosh()

Datum dacosh ( PG_FUNCTION_ARGS  )

Definition at line 2693 of file float.c.

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

2694 {
2695  float8 arg1 = PG_GETARG_FLOAT8(0);
2696  float8 result;
2697 
2698  /*
2699  * acosh is only defined for inputs >= 1.0. By checking this ourselves,
2700  * we need not worry about checking for an EDOM error, which is a good
2701  * thing because some implementations will report that for NaN. Otherwise,
2702  * no error is possible.
2703  */
2704  if (arg1 < 1.0)
2705  ereport(ERROR,
2706  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2707  errmsg("input is out of range")));
2708 
2709  result = acosh(arg1);
2710 
2711  PG_RETURN_FLOAT8(result);
2712 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ dasin()

Datum dasin ( PG_FUNCTION_ARGS  )

Definition at line 1790 of file float.c.

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

1791 {
1792  float8 arg1 = PG_GETARG_FLOAT8(0);
1793  float8 result;
1794 
1795  /* Per the POSIX spec, return NaN if the input is NaN */
1796  if (isnan(arg1))
1798 
1799  /*
1800  * The principal branch of the inverse sine function maps values in the
1801  * range [-1, 1] to values in the range [-Pi/2, Pi/2], so we should reject
1802  * any inputs outside that range and the result will always be finite.
1803  */
1804  if (arg1 < -1.0 || arg1 > 1.0)
1805  ereport(ERROR,
1806  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1807  errmsg("input is out of range")));
1808 
1809  result = asin(arg1);
1810  if (unlikely(isinf(result)))
1812 
1813  PG_RETURN_FLOAT8(result);
1814 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dasind()

Datum dasind ( PG_FUNCTION_ARGS  )

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

2150 {
2151  float8 arg1 = PG_GETARG_FLOAT8(0);
2152  float8 result;
2153 
2154  /* Per the POSIX spec, return NaN if the input is NaN */
2155  if (isnan(arg1))
2157 
2159 
2160  /*
2161  * The principal branch of the inverse sine function maps values in the
2162  * range [-1, 1] to values in the range [-90, 90], so we should reject any
2163  * inputs outside that range and the result will always be finite.
2164  */
2165  if (arg1 < -1.0 || arg1 > 1.0)
2166  ereport(ERROR,
2167  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2168  errmsg("input is out of range")));
2169 
2170  if (arg1 >= 0.0)
2171  result = asind_q1(arg1);
2172  else
2173  result = -asind_q1(-arg1);
2174 
2175  if (unlikely(isinf(result)))
2177 
2178  PG_RETURN_FLOAT8(result);
2179 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
static double asind_q1(double x)
Definition: float.c:2052
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dasinh()

Datum dasinh ( PG_FUNCTION_ARGS  )

Definition at line 2676 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

2677 {
2678  float8 arg1 = PG_GETARG_FLOAT8(0);
2679  float8 result;
2680 
2681  /*
2682  * For asinh, we don't need an errno check because it never overflows.
2683  */
2684  result = asinh(arg1);
2685 
2686  PG_RETURN_FLOAT8(result);
2687 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ datan()

Datum datan ( PG_FUNCTION_ARGS  )

Definition at line 1821 of file float.c.

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

1822 {
1823  float8 arg1 = PG_GETARG_FLOAT8(0);
1824  float8 result;
1825 
1826  /* Per the POSIX spec, return NaN if the input is NaN */
1827  if (isnan(arg1))
1829 
1830  /*
1831  * The principal branch of the inverse tangent function maps all inputs to
1832  * values in the range [-Pi/2, Pi/2], so the result should always be
1833  * finite, even if the input is infinite.
1834  */
1835  result = atan(arg1);
1836  if (unlikely(isinf(result)))
1838 
1839  PG_RETURN_FLOAT8(result);
1840 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
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:261

◆ datan2()

Datum datan2 ( PG_FUNCTION_ARGS  )

Definition at line 1847 of file float.c.

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

1848 {
1849  float8 arg1 = PG_GETARG_FLOAT8(0);
1850  float8 arg2 = PG_GETARG_FLOAT8(1);
1851  float8 result;
1852 
1853  /* Per the POSIX spec, return NaN if either input is NaN */
1854  if (isnan(arg1) || isnan(arg2))
1856 
1857  /*
1858  * atan2 maps all inputs to values in the range [-Pi, Pi], so the result
1859  * should always be finite, even if the inputs are infinite.
1860  */
1861  result = atan2(arg1, arg2);
1862  if (unlikely(isinf(result)))
1864 
1865  PG_RETURN_FLOAT8(result);
1866 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
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:261

◆ datan2d()

Datum datan2d ( PG_FUNCTION_ARGS  )

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

2219 {
2220  float8 arg1 = PG_GETARG_FLOAT8(0);
2221  float8 arg2 = PG_GETARG_FLOAT8(1);
2222  float8 result;
2223  volatile float8 atan2_arg1_arg2;
2224 
2225  /* Per the POSIX spec, return NaN if either input is NaN */
2226  if (isnan(arg1) || isnan(arg2))
2228 
2230 
2231  /*
2232  * atan2d maps all inputs to values in the range [-180, 180], so the
2233  * result should always be finite, even if the inputs are infinite.
2234  *
2235  * Note: this coding assumes that atan(1.0) is a suitable scaling constant
2236  * to get an exact result from atan2(). This might well fail on us at
2237  * some point, requiring us to decide exactly what inputs we think we're
2238  * going to guarantee an exact result for.
2239  */
2240  atan2_arg1_arg2 = atan2(arg1, arg2);
2241  result = (atan2_arg1_arg2 / atan_1_0) * 45.0;
2242 
2243  if (unlikely(isinf(result)))
2245 
2246  PG_RETURN_FLOAT8(result);
2247 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
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:261

◆ datand()

Datum datand ( PG_FUNCTION_ARGS  )

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

2187 {
2188  float8 arg1 = PG_GETARG_FLOAT8(0);
2189  float8 result;
2190  volatile float8 atan_arg1;
2191 
2192  /* Per the POSIX spec, return NaN if the input is NaN */
2193  if (isnan(arg1))
2195 
2197 
2198  /*
2199  * The principal branch of the inverse tangent function maps all inputs to
2200  * values in the range [-90, 90], so the result should always be finite,
2201  * even if the input is infinite. Additionally, we take care to ensure
2202  * than when arg1 is 1, the result is exactly 45.
2203  */
2204  atan_arg1 = atan(arg1);
2205  result = (atan_arg1 / atan_1_0) * 45.0;
2206 
2207  if (unlikely(isinf(result)))
2209 
2210  PG_RETURN_FLOAT8(result);
2211 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
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:261

◆ datanh()

Datum datanh ( PG_FUNCTION_ARGS  )

Definition at line 2718 of file float.c.

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

2719 {
2720  float8 arg1 = PG_GETARG_FLOAT8(0);
2721  float8 result;
2722 
2723  /*
2724  * atanh is only defined for inputs between -1 and 1. By checking this
2725  * ourselves, we need not worry about checking for an EDOM error, which is
2726  * a good thing because some implementations will report that for NaN.
2727  */
2728  if (arg1 < -1.0 || arg1 > 1.0)
2729  ereport(ERROR,
2730  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2731  errmsg("input is out of range")));
2732 
2733  /*
2734  * Also handle the infinity cases ourselves; this is helpful because old
2735  * glibc versions may produce the wrong errno for this. All other inputs
2736  * cannot produce an error.
2737  */
2738  if (arg1 == -1.0)
2739  result = -get_float8_infinity();
2740  else if (arg1 == 1.0)
2741  result = get_float8_infinity();
2742  else
2743  result = atanh(arg1);
2744 
2745  PG_RETURN_FLOAT8(result);
2746 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static float8 get_float8_infinity(void)
Definition: float.h:93
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ dcbrt()

Datum dcbrt ( PG_FUNCTION_ARGS  )

Definition at line 1474 of file float.c.

References 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  result = cbrt(arg1);
1480  if (unlikely(isinf(result)) && !isinf(arg1))
1482  if (unlikely(result == 0.0) && arg1 != 0.0)
1484 
1485  PG_RETURN_FLOAT8(result);
1486 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:553
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:261

◆ dceil()

Datum dceil ( PG_FUNCTION_ARGS  )

Definition at line 1384 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1385 {
1386  float8 arg1 = PG_GETARG_FLOAT8(0);
1387 
1388  PG_RETURN_FLOAT8(ceil(arg1));
1389 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ dcos()

Datum dcos ( PG_FUNCTION_ARGS  )

Definition at line 1873 of file float.c.

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

1874 {
1875  float8 arg1 = PG_GETARG_FLOAT8(0);
1876  float8 result;
1877 
1878  /* Per the POSIX spec, return NaN if the input is NaN */
1879  if (isnan(arg1))
1881 
1882  /*
1883  * cos() is periodic and so theoretically can work for all finite inputs,
1884  * but some implementations may choose to throw error if the input is so
1885  * large that there are no significant digits in the result. So we should
1886  * check for errors. POSIX allows an error to be reported either via
1887  * errno or via fetestexcept(), but currently we only support checking
1888  * errno. (fetestexcept() is rumored to report underflow unreasonably
1889  * early on some platforms, so it's not clear that believing it would be a
1890  * net improvement anyway.)
1891  *
1892  * For infinite inputs, POSIX specifies that the trigonometric functions
1893  * should return a domain error; but we won't notice that unless the
1894  * platform reports via errno, so also explicitly test for infinite
1895  * inputs.
1896  */
1897  errno = 0;
1898  result = cos(arg1);
1899  if (errno != 0 || isinf(arg1))
1900  ereport(ERROR,
1901  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1902  errmsg("input is out of range")));
1903  if (unlikely(isinf(result)))
1905 
1906  PG_RETURN_FLOAT8(result);
1907 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dcosd()

Datum dcosd ( PG_FUNCTION_ARGS  )

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

2323 {
2324  float8 arg1 = PG_GETARG_FLOAT8(0);
2325  float8 result;
2326  int sign = 1;
2327 
2328  /*
2329  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2330  * if the input is infinite.
2331  */
2332  if (isnan(arg1))
2334 
2335  if (isinf(arg1))
2336  ereport(ERROR,
2337  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2338  errmsg("input is out of range")));
2339 
2341 
2342  /* Reduce the range of the input to [0,90] degrees */
2343  arg1 = fmod(arg1, 360.0);
2344 
2345  if (arg1 < 0.0)
2346  {
2347  /* cosd(-x) = cosd(x) */
2348  arg1 = -arg1;
2349  }
2350 
2351  if (arg1 > 180.0)
2352  {
2353  /* cosd(360-x) = cosd(x) */
2354  arg1 = 360.0 - arg1;
2355  }
2356 
2357  if (arg1 > 90.0)
2358  {
2359  /* cosd(180-x) = -cosd(x) */
2360  arg1 = 180.0 - arg1;
2361  sign = -sign;
2362  }
2363 
2364  result = sign * cosd_q1(arg1);
2365 
2366  if (unlikely(isinf(result)))
2368 
2369  PG_RETURN_FLOAT8(result);
2370 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
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:2303
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dcosh()

Datum dcosh ( PG_FUNCTION_ARGS  )

Definition at line 2631 of file float.c.

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

2632 {
2633  float8 arg1 = PG_GETARG_FLOAT8(0);
2634  float8 result;
2635 
2636  errno = 0;
2637  result = cosh(arg1);
2638 
2639  /*
2640  * if an ERANGE error occurs, it means there is an overflow. As cosh is
2641  * always positive, it always means the result is positive infinity.
2642  */
2643  if (errno == ERANGE)
2644  result = get_float8_infinity();
2645 
2646  if (unlikely(result == 0.0))
2648 
2649  PG_RETURN_FLOAT8(result);
2650 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static float8 get_float8_infinity(void)
Definition: float.h:93
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:553
#define unlikely(x)
Definition: c.h:261

◆ dcot()

Datum dcot ( PG_FUNCTION_ARGS  )

Definition at line 1914 of file float.c.

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

1915 {
1916  float8 arg1 = PG_GETARG_FLOAT8(0);
1917  float8 result;
1918 
1919  /* Per the POSIX spec, return NaN if the input is NaN */
1920  if (isnan(arg1))
1922 
1923  /* Be sure to throw an error if the input is infinite --- see dcos() */
1924  errno = 0;
1925  result = tan(arg1);
1926  if (errno != 0 || isinf(arg1))
1927  ereport(ERROR,
1928  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1929  errmsg("input is out of range")));
1930 
1931  result = 1.0 / result;
1932  /* Not checking for overflow because cot(0) == Inf */
1933 
1934  PG_RETURN_FLOAT8(result);
1935 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ dcotd()

Datum dcotd ( PG_FUNCTION_ARGS  )

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

2378 {
2379  float8 arg1 = PG_GETARG_FLOAT8(0);
2380  float8 result;
2381  volatile float8 cot_arg1;
2382  int sign = 1;
2383 
2384  /*
2385  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2386  * if the input is infinite.
2387  */
2388  if (isnan(arg1))
2390 
2391  if (isinf(arg1))
2392  ereport(ERROR,
2393  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2394  errmsg("input is out of range")));
2395 
2397 
2398  /* Reduce the range of the input to [0,90] degrees */
2399  arg1 = fmod(arg1, 360.0);
2400 
2401  if (arg1 < 0.0)
2402  {
2403  /* cotd(-x) = -cotd(x) */
2404  arg1 = -arg1;
2405  sign = -sign;
2406  }
2407 
2408  if (arg1 > 180.0)
2409  {
2410  /* cotd(360-x) = -cotd(x) */
2411  arg1 = 360.0 - arg1;
2412  sign = -sign;
2413  }
2414 
2415  if (arg1 > 90.0)
2416  {
2417  /* cotd(180-x) = -cotd(x) */
2418  arg1 = 180.0 - arg1;
2419  sign = -sign;
2420  }
2421 
2422  cot_arg1 = cosd_q1(arg1) / sind_q1(arg1);
2423  result = sign * (cot_arg1 / cot_45);
2424 
2425  /*
2426  * On some machines we get cotd(270) = minus zero, but this isn't always
2427  * true. For portability, and because the user constituency for this
2428  * function probably doesn't want minus zero, force it to plain zero.
2429  */
2430  if (result == 0.0)
2431  result = 0.0;
2432 
2433  /* Not checking for overflow because cotd(0) == Inf */
2434 
2435  PG_RETURN_FLOAT8(result);
2436 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static float8 cot_45
Definition: float.c:52
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static double sind_q1(double x)
Definition: float.c:2283
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
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:2303
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ degrees()

Datum degrees ( PG_FUNCTION_ARGS  )

Definition at line 2565 of file float.c.

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

2566 {
2567  float8 arg1 = PG_GETARG_FLOAT8(0);
2568 
2570 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define RADIANS_PER_DEGREE
Definition: float.h:26
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ dexp()

Datum dexp ( PG_FUNCTION_ARGS  )

Definition at line 1648 of file float.c.

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

1649 {
1650  float8 arg1 = PG_GETARG_FLOAT8(0);
1651  float8 result;
1652 
1653  /*
1654  * Handle NaN and Inf cases explicitly. This avoids needing to assume
1655  * that the platform's exp() conforms to POSIX for these cases, and it
1656  * removes some edge cases for the overflow checks below.
1657  */
1658  if (isnan(arg1))
1659  result = arg1;
1660  else if (isinf(arg1))
1661  {
1662  /* Per POSIX, exp(-Inf) is 0 */
1663  result = (arg1 > 0.0) ? arg1 : 0;
1664  }
1665  else
1666  {
1667  /*
1668  * On some platforms, exp() will not set errno but just return Inf or
1669  * zero to report overflow/underflow; therefore, test both cases.
1670  */
1671  errno = 0;
1672  result = exp(arg1);
1673  if (unlikely(errno == ERANGE))
1674  {
1675  if (result != 0.0)
1677  else
1679  }
1680  else if (unlikely(isinf(result)))
1682  else if (unlikely(result == 0.0))
1684  }
1685 
1686  PG_RETURN_FLOAT8(result);
1687 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:553
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:261

◆ dfloor()

Datum dfloor ( 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(floor(arg1));
1401 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ dlog1()

Datum dlog1 ( PG_FUNCTION_ARGS  )

Definition at line 1694 of file float.c.

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

1695 {
1696  float8 arg1 = PG_GETARG_FLOAT8(0);
1697  float8 result;
1698 
1699  /*
1700  * Emit particular SQLSTATE error codes for ln(). This is required by the
1701  * SQL standard.
1702  */
1703  if (arg1 == 0.0)
1704  ereport(ERROR,
1705  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1706  errmsg("cannot take logarithm of zero")));
1707  if (arg1 < 0)
1708  ereport(ERROR,
1709  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1710  errmsg("cannot take logarithm of a negative number")));
1711 
1712  result = log(arg1);
1713  if (unlikely(isinf(result)) && !isinf(arg1))
1715  if (unlikely(result == 0.0) && arg1 != 1.0)
1717 
1718  PG_RETURN_FLOAT8(result);
1719 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
pg_noinline void float_underflow_error(void)
Definition: float.c:92
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dlog10()

Datum dlog10 ( PG_FUNCTION_ARGS  )

Definition at line 1726 of file float.c.

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

1727 {
1728  float8 arg1 = PG_GETARG_FLOAT8(0);
1729  float8 result;
1730 
1731  /*
1732  * Emit particular SQLSTATE error codes for log(). The SQL spec doesn't
1733  * define log(), but it does define ln(), so it makes sense to emit the
1734  * same error code for an analogous error condition.
1735  */
1736  if (arg1 == 0.0)
1737  ereport(ERROR,
1738  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1739  errmsg("cannot take logarithm of zero")));
1740  if (arg1 < 0)
1741  ereport(ERROR,
1742  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
1743  errmsg("cannot take logarithm of a negative number")));
1744 
1745  result = log10(arg1);
1746  if (unlikely(isinf(result)) && !isinf(arg1))
1748  if (unlikely(result == 0.0) && arg1 != 1.0)
1750 
1751  PG_RETURN_FLOAT8(result);
1752 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
pg_noinline void float_underflow_error(void)
Definition: float.c:92
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dpi()

Definition at line 2577 of file float.c.

References M_PI, and PG_RETURN_FLOAT8.

2578 {
2580 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define M_PI
Definition: earthdistance.c:10

◆ dpow()

Datum dpow ( PG_FUNCTION_ARGS  )

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

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

◆ drandom()

Datum drandom ( PG_FUNCTION_ARGS  )

Definition at line 2753 of file float.c.

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

2754 {
2755  float8 result;
2756 
2757  /* Initialize random seed, if not done yet in this process */
2758  if (unlikely(!drandom_seed_set))
2759  {
2760  /*
2761  * If possible, initialize the seed using high-quality random bits.
2762  * Should that fail for some reason, we fall back on a lower-quality
2763  * seed based on current time and PID.
2764  */
2766  {
2768  uint64 iseed;
2769 
2770  /* Mix the PID with the most predictable bits of the timestamp */
2771  iseed = (uint64) now ^ ((uint64) MyProcPid << 32);
2772  drandom_seed[0] = (unsigned short) iseed;
2773  drandom_seed[1] = (unsigned short) (iseed >> 16);
2774  drandom_seed[2] = (unsigned short) (iseed >> 32);
2775  }
2776  drandom_seed_set = true;
2777  }
2778 
2779  /* pg_erand48 produces desired result range [0.0 - 1.0) */
2780  result = pg_erand48(drandom_seed);
2781 
2782  PG_RETURN_FLOAT8(result);
2783 }
int MyProcPid
Definition: globals.c:40
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1578
int64 TimestampTz
Definition: timestamp.h:39
static unsigned short drandom_seed[3]
Definition: float.c:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static bool drandom_seed_set
Definition: float.c:67
double float8
Definition: c.h:553
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:261
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1542

◆ dround()

Datum dround ( PG_FUNCTION_ARGS  )

Definition at line 1372 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1373 {
1374  float8 arg1 = PG_GETARG_FLOAT8(0);
1375 
1376  PG_RETURN_FLOAT8(rint(arg1));
1377 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ dsign()

Datum dsign ( PG_FUNCTION_ARGS  )

Definition at line 1409 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1410 {
1411  float8 arg1 = PG_GETARG_FLOAT8(0);
1412  float8 result;
1413 
1414  if (arg1 > 0)
1415  result = 1.0;
1416  else if (arg1 < 0)
1417  result = -1.0;
1418  else
1419  result = 0.0;
1420 
1421  PG_RETURN_FLOAT8(result);
1422 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ dsin()

Datum dsin ( PG_FUNCTION_ARGS  )

Definition at line 1942 of file float.c.

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

1943 {
1944  float8 arg1 = PG_GETARG_FLOAT8(0);
1945  float8 result;
1946 
1947  /* Per the POSIX spec, return NaN if the input is NaN */
1948  if (isnan(arg1))
1950 
1951  /* Be sure to throw an error if the input is infinite --- see dcos() */
1952  errno = 0;
1953  result = sin(arg1);
1954  if (errno != 0 || isinf(arg1))
1955  ereport(ERROR,
1956  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1957  errmsg("input is out of range")));
1958  if (unlikely(isinf(result)))
1960 
1961  PG_RETURN_FLOAT8(result);
1962 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dsind()

Datum dsind ( PG_FUNCTION_ARGS  )

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

2444 {
2445  float8 arg1 = PG_GETARG_FLOAT8(0);
2446  float8 result;
2447  int sign = 1;
2448 
2449  /*
2450  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2451  * if the input is infinite.
2452  */
2453  if (isnan(arg1))
2455 
2456  if (isinf(arg1))
2457  ereport(ERROR,
2458  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2459  errmsg("input is out of range")));
2460 
2462 
2463  /* Reduce the range of the input to [0,90] degrees */
2464  arg1 = fmod(arg1, 360.0);
2465 
2466  if (arg1 < 0.0)
2467  {
2468  /* sind(-x) = -sind(x) */
2469  arg1 = -arg1;
2470  sign = -sign;
2471  }
2472 
2473  if (arg1 > 180.0)
2474  {
2475  /* sind(360-x) = -sind(x) */
2476  arg1 = 360.0 - arg1;
2477  sign = -sign;
2478  }
2479 
2480  if (arg1 > 90.0)
2481  {
2482  /* sind(180-x) = sind(x) */
2483  arg1 = 180.0 - arg1;
2484  }
2485 
2486  result = sign * sind_q1(arg1);
2487 
2488  if (unlikely(isinf(result)))
2490 
2491  PG_RETURN_FLOAT8(result);
2492 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static double sind_q1(double x)
Definition: float.c:2283
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
char sign
Definition: informix.c:668
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dsinh()

Datum dsinh ( PG_FUNCTION_ARGS  )

Definition at line 2602 of file float.c.

References get_float8_infinity(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

2603 {
2604  float8 arg1 = PG_GETARG_FLOAT8(0);
2605  float8 result;
2606 
2607  errno = 0;
2608  result = sinh(arg1);
2609 
2610  /*
2611  * if an ERANGE error occurs, it means there is an overflow. For sinh,
2612  * the result should be either -infinity or infinity, depending on the
2613  * sign of arg1.
2614  */
2615  if (errno == ERANGE)
2616  {
2617  if (arg1 < 0)
2618  result = -get_float8_infinity();
2619  else
2620  result = get_float8_infinity();
2621  }
2622 
2623  PG_RETURN_FLOAT8(result);
2624 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static float8 get_float8_infinity(void)
Definition: float.h:93
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ dsqrt()

Datum dsqrt ( PG_FUNCTION_ARGS  )

Definition at line 1450 of file float.c.

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

1451 {
1452  float8 arg1 = PG_GETARG_FLOAT8(0);
1453  float8 result;
1454 
1455  if (arg1 < 0)
1456  ereport(ERROR,
1457  (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
1458  errmsg("cannot take square root of a negative number")));
1459 
1460  result = sqrt(arg1);
1461  if (unlikely(isinf(result)) && !isinf(arg1))
1463  if (unlikely(result == 0.0) && arg1 != 0.0)
1465 
1466  PG_RETURN_FLOAT8(result);
1467 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
pg_noinline void float_underflow_error(void)
Definition: float.c:92
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define ereport(elevel,...)
Definition: elog.h:155
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dtan()

Datum dtan ( PG_FUNCTION_ARGS  )

Definition at line 1969 of file float.c.

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

1970 {
1971  float8 arg1 = PG_GETARG_FLOAT8(0);
1972  float8 result;
1973 
1974  /* Per the POSIX spec, return NaN if the input is NaN */
1975  if (isnan(arg1))
1977 
1978  /* Be sure to throw an error if the input is infinite --- see dcos() */
1979  errno = 0;
1980  result = tan(arg1);
1981  if (errno != 0 || isinf(arg1))
1982  ereport(ERROR,
1983  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1984  errmsg("input is out of range")));
1985  /* Not checking for overflow because tan(pi/2) == Inf */
1986 
1987  PG_RETURN_FLOAT8(result);
1988 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 get_float8_nan(void)
Definition: float.h:122
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ dtand()

Datum dtand ( PG_FUNCTION_ARGS  )

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

2500 {
2501  float8 arg1 = PG_GETARG_FLOAT8(0);
2502  float8 result;
2503  volatile float8 tan_arg1;
2504  int sign = 1;
2505 
2506  /*
2507  * Per the POSIX spec, return NaN if the input is NaN and throw an error
2508  * if the input is infinite.
2509  */
2510  if (isnan(arg1))
2512 
2513  if (isinf(arg1))
2514  ereport(ERROR,
2515  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
2516  errmsg("input is out of range")));
2517 
2519 
2520  /* Reduce the range of the input to [0,90] degrees */
2521  arg1 = fmod(arg1, 360.0);
2522 
2523  if (arg1 < 0.0)
2524  {
2525  /* tand(-x) = -tand(x) */
2526  arg1 = -arg1;
2527  sign = -sign;
2528  }
2529 
2530  if (arg1 > 180.0)
2531  {
2532  /* tand(360-x) = -tand(x) */
2533  arg1 = 360.0 - arg1;
2534  sign = -sign;
2535  }
2536 
2537  if (arg1 > 90.0)
2538  {
2539  /* tand(180-x) = -tand(x) */
2540  arg1 = 180.0 - arg1;
2541  sign = -sign;
2542  }
2543 
2544  tan_arg1 = sind_q1(arg1) / cosd_q1(arg1);
2545  result = sign * (tan_arg1 / tan_45);
2546 
2547  /*
2548  * On some machines we get tand(180) = minus zero, but this isn't always
2549  * true. For portability, and because the user constituency for this
2550  * function probably doesn't want minus zero, force it to plain zero.
2551  */
2552  if (result == 0.0)
2553  result = 0.0;
2554 
2555  /* Not checking for overflow because tand(90) == Inf */
2556 
2557  PG_RETURN_FLOAT8(result);
2558 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define INIT_DEGREE_CONSTANTS()
Definition: float.c:2035
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static double sind_q1(double x)
Definition: float.c:2283
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
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:2303
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
static float8 tan_45
Definition: float.c:51

◆ dtanh()

Datum dtanh ( PG_FUNCTION_ARGS  )

Definition at line 2656 of file float.c.

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

2657 {
2658  float8 arg1 = PG_GETARG_FLOAT8(0);
2659  float8 result;
2660 
2661  /*
2662  * For tanh, we don't need an errno check because it never overflows.
2663  */
2664  result = tanh(arg1);
2665 
2666  if (unlikely(isinf(result)))
2668 
2669  PG_RETURN_FLOAT8(result);
2670 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:261

◆ dtof()

Datum dtof ( PG_FUNCTION_ARGS  )

Definition at line 1199 of file float.c.

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

1200 {
1201  float8 num = PG_GETARG_FLOAT8(0);
1202  float4 result;
1203 
1204  result = (float4) num;
1205  if (unlikely(isinf(result)) && !isinf(num))
1207  if (unlikely(result == 0.0f) && num != 0.0)
1209 
1210  PG_RETURN_FLOAT4(result);
1211 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
pg_noinline void float_underflow_error(void)
Definition: float.c:92
double float8
Definition: c.h:553
float float4
Definition: c.h:552
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:261

◆ dtoi2()

Datum dtoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1243 of file float.c.

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

1244 {
1245  float8 num = PG_GETARG_FLOAT8(0);
1246 
1247  /*
1248  * Get rid of any fractional part in the input. This is so we don't fail
1249  * on just-out-of-range values that would round into range. Note
1250  * assumption that rint() will pass through a NaN or Inf unchanged.
1251  */
1252  num = rint(num);
1253 
1254  /* Range check */
1255  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT16(num)))
1256  ereport(ERROR,
1257  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1258  errmsg("smallint out of range")));
1259 
1260  PG_RETURN_INT16((int16) num);
1261 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
signed short int16
Definition: c.h:416
#define PG_RETURN_INT16(x)
Definition: fmgr.h:356
int errcode(int sqlerrcode)
Definition: elog.c:691
#define FLOAT8_FITS_IN_INT16(num)
Definition: c.h:1099
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dtoi4()

Datum dtoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1218 of file float.c.

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

1219 {
1220  float8 num = PG_GETARG_FLOAT8(0);
1221 
1222  /*
1223  * Get rid of any fractional part in the input. This is so we don't fail
1224  * on just-out-of-range values that would round into range. Note
1225  * assumption that rint() will pass through a NaN or Inf unchanged.
1226  */
1227  num = rint(num);
1228 
1229  /* Range check */
1230  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT32(num)))
1231  ereport(ERROR,
1232  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1233  errmsg("integer out of range")));
1234 
1235  PG_RETURN_INT32((int32) num);
1236 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int errcode(int sqlerrcode)
Definition: elog.c:691
signed int int32
Definition: c.h:417
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define ereport(elevel,...)
Definition: elog.h:155
#define FLOAT8_FITS_IN_INT32(num)
Definition: c.h:1101
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ dtrunc()

Datum dtrunc ( PG_FUNCTION_ARGS  )

Definition at line 1432 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

1433 {
1434  float8 arg1 = PG_GETARG_FLOAT8(0);
1435  float8 result;
1436 
1437  if (arg1 >= 0)
1438  result = floor(arg1);
1439  else
1440  result = -floor(-arg1);
1441 
1442  PG_RETURN_FLOAT8(result);
1443 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ float48div()

Datum float48div ( PG_FUNCTION_ARGS  )

Definition at line 3834 of file float.c.

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

3835 {
3836  float4 arg1 = PG_GETARG_FLOAT4(0);
3837  float8 arg2 = PG_GETARG_FLOAT8(1);
3838 
3839  PG_RETURN_FLOAT8(float8_div((float8) arg1, arg2));
3840 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ float48eq()

Datum float48eq ( PG_FUNCTION_ARGS  )

Definition at line 3894 of file float.c.

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

3895 {
3896  float4 arg1 = PG_GETARG_FLOAT4(0);
3897  float8 arg2 = PG_GETARG_FLOAT8(1);
3898 
3899  PG_RETURN_BOOL(float8_eq((float8) arg1, arg2));
3900 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:267

◆ float48ge()

Datum float48ge ( PG_FUNCTION_ARGS  )

Definition at line 3939 of file float.c.

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

3940 {
3941  float4 arg1 = PG_GETARG_FLOAT4(0);
3942  float8 arg2 = PG_GETARG_FLOAT8(1);
3943 
3944  PG_RETURN_BOOL(float8_ge((float8) arg1, arg2));
3945 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
static bool float8_ge(const float8 val1, const float8 val2)
Definition: float.h:327
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float48gt()

Datum float48gt ( PG_FUNCTION_ARGS  )

Definition at line 3930 of file float.c.

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

3931 {
3932  float4 arg1 = PG_GETARG_FLOAT4(0);
3933  float8 arg2 = PG_GETARG_FLOAT8(1);
3934 
3935  PG_RETURN_BOOL(float8_gt((float8) arg1, arg2));
3936 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float48le()

Datum float48le ( PG_FUNCTION_ARGS  )

Definition at line 3921 of file float.c.

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

3922 {
3923  float4 arg1 = PG_GETARG_FLOAT4(0);
3924  float8 arg2 = PG_GETARG_FLOAT8(1);
3925 
3926  PG_RETURN_BOOL(float8_le((float8) arg1, arg2));
3927 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static bool float8_le(const float8 val1, const float8 val2)
Definition: float.h:303
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float48lt()

Datum float48lt ( PG_FUNCTION_ARGS  )

Definition at line 3912 of file float.c.

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

3913 {
3914  float4 arg1 = PG_GETARG_FLOAT4(0);
3915  float8 arg2 = PG_GETARG_FLOAT8(1);
3916 
3917  PG_RETURN_BOOL(float8_lt((float8) arg1, arg2));
3918 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float48mi()

Datum float48mi ( PG_FUNCTION_ARGS  )

Definition at line 3816 of file float.c.

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

3817 {
3818  float4 arg1 = PG_GETARG_FLOAT4(0);
3819  float8 arg2 = PG_GETARG_FLOAT8(1);
3820 
3821  PG_RETURN_FLOAT8(float8_mi((float8) arg1, arg2));
3822 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float48mul()

Datum float48mul ( PG_FUNCTION_ARGS  )

Definition at line 3825 of file float.c.

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

3826 {
3827  float4 arg1 = PG_GETARG_FLOAT4(0);
3828  float8 arg2 = PG_GETARG_FLOAT8(1);
3829 
3830  PG_RETURN_FLOAT8(float8_mul((float8) arg1, arg2));
3831 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float48ne()

Datum float48ne ( PG_FUNCTION_ARGS  )

Definition at line 3903 of file float.c.

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

3904 {
3905  float4 arg1 = PG_GETARG_FLOAT4(0);
3906  float8 arg2 = PG_GETARG_FLOAT8(1);
3907 
3908  PG_RETURN_BOOL(float8_ne((float8) arg1, arg2));
3909 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static bool float8_ne(const float8 val1, const float8 val2)
Definition: float.h:279
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float48pl()

Datum float48pl ( PG_FUNCTION_ARGS  )

Definition at line 3807 of file float.c.

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

3808 {
3809  float4 arg1 = PG_GETARG_FLOAT4(0);
3810  float8 arg2 = PG_GETARG_FLOAT8(1);
3811 
3812  PG_RETURN_FLOAT8(float8_pl((float8) arg1, arg2));
3813 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float4_accum()

Datum float4_accum ( PG_FUNCTION_ARGS  )

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

3064 {
3065  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3066 
3067  /* do computations as float8 */
3069  float8 *transvalues;
3070  float8 N,
3071  Sx,
3072  Sxx,
3073  tmp;
3074 
3075  transvalues = check_float8_array(transarray, "float4_accum", 3);
3076  N = transvalues[0];
3077  Sx = transvalues[1];
3078  Sxx = transvalues[2];
3079 
3080  /*
3081  * Use the Youngs-Cramer algorithm to incorporate the new value into the
3082  * transition values.
3083  */
3084  N += 1.0;
3085  Sx += newval;
3086  if (transvalues[0] > 0.0)
3087  {
3088  tmp = newval * N - Sx;
3089  Sxx += tmp * tmp / (N * transvalues[0]);
3090 
3091  /*
3092  * Overflow check. We only report an overflow error when finite
3093  * inputs lead to infinite results. Note also that Sxx should be NaN
3094  * if any of the inputs are infinite, so we intentionally prevent Sxx
3095  * from becoming infinite.
3096  */
3097  if (isinf(Sx) || isinf(Sxx))
3098  {
3099  if (!isinf(transvalues[1]) && !isinf(newval))
3101 
3102  Sxx = get_float8_nan();
3103  }
3104  }
3105  else
3106  {
3107  /*
3108  * At the first input, we normally can leave Sxx as 0. However, if
3109  * the first input is Inf or NaN, we'd better force Sxx to NaN;
3110  * otherwise we will falsely report variance zero when there are no
3111  * more inputs.
3112  */
3113  if (isnan(newval) || isinf(newval))
3114  Sxx = get_float8_nan();
3115  }
3116 
3117  /*
3118  * If we're invoked as an aggregate, we can cheat and modify our first
3119  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3120  * new array with the updated transition data and return it.
3121  */
3122  if (AggCheckCallContext(fcinfo, NULL))
3123  {
3124  transvalues[0] = N;
3125  transvalues[1] = Sx;
3126  transvalues[2] = Sxx;
3127 
3128  PG_RETURN_ARRAYTYPE_P(transarray);
3129  }
3130  else
3131  {
3132  Datum transdatums[3];
3133  ArrayType *result;
3134 
3135  transdatums[0] = Float8GetDatumFast(N);
3136  transdatums[1] = Float8GetDatumFast(Sx);
3137  transdatums[2] = Float8GetDatumFast(Sxx);
3138 
3139  result = construct_array(transdatums, 3,
3140  FLOAT8OID,
3141  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3142 
3143  PG_RETURN_ARRAYTYPE_P(result);
3144  }
3145 }
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:553
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:281
uintptr_t Datum
Definition: postgres.h:367
#define Float8GetDatumFast(X)
Definition: postgres.h:761
#define FLOAT8PASSBYVAL
Definition: c.h:558
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define newval
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4572
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862

◆ float4_cmp_internal()

int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 820 of file float.c.

References float4_gt(), and float4_lt().

Referenced by btfloat4cmp(), and btfloat4fastcmp().

821 {
822  if (float4_gt(a, b))
823  return 1;
824  if (float4_lt(a, b))
825  return -1;
826  return 0;
827 }
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 595 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

596 {
597  float4 arg1 = PG_GETARG_FLOAT4(0);
598 
599  PG_RETURN_FLOAT4((float4) fabs(arg1));
600 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float4div()

Datum float4div ( PG_FUNCTION_ARGS  )

Definition at line 759 of file float.c.

References float4_div(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

760 {
761  float4 arg1 = PG_GETARG_FLOAT4(0);
762  float4 arg2 = PG_GETARG_FLOAT4(1);
763 
764  PG_RETURN_FLOAT4(float4_div(arg1, arg2));
765 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
static float4 float4_div(const float4 val1, const float4 val2)
Definition: float.h:221
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float4eq()

Datum float4eq ( PG_FUNCTION_ARGS  )

Definition at line 830 of file float.c.

References float4_eq(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

831 {
832  float4 arg1 = PG_GETARG_FLOAT4(0);
833  float4 arg2 = PG_GETARG_FLOAT4(1);
834 
835  PG_RETURN_BOOL(float4_eq(arg1, arg2));
836 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float4_eq(const float4 val1, const float4 val2)
Definition: float.h:261

◆ float4ge()

Datum float4ge ( PG_FUNCTION_ARGS  )

Definition at line 875 of file float.c.

References float4_ge(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

876 {
877  float4 arg1 = PG_GETARG_FLOAT4(0);
878  float4 arg2 = PG_GETARG_FLOAT4(1);
879 
880  PG_RETURN_BOOL(float4_ge(arg1, arg2));
881 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float4_ge(const float4 val1, const float4 val2)
Definition: float.h:321

◆ float4gt()

Datum float4gt ( PG_FUNCTION_ARGS  )

Definition at line 866 of file float.c.

References float4_gt(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

867 {
868  float4 arg1 = PG_GETARG_FLOAT4(0);
869  float4 arg2 = PG_GETARG_FLOAT4(1);
870 
871  PG_RETURN_BOOL(float4_gt(arg1, arg2));
872 }
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:309
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ 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 
275  /* skip trailing whitespace */
276  while (*endptr != '\0' && isspace((unsigned char) *endptr))
277  endptr++;
278 
279  /* if there is any junk left at the end of the string, bail out */
280  if (*endptr != '\0')
281  ereport(ERROR,
282  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
283  errmsg("invalid input syntax for type %s: \"%s\"",
284  "real", orig_num)));
285 
286  PG_RETURN_FLOAT4(val);
287 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
int errcode(int sqlerrcode)
Definition: elog.c:691
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:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
#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 624 of file float.c.

References float4_gt(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

625 {
626  float4 arg1 = PG_GETARG_FLOAT4(0);
627  float4 arg2 = PG_GETARG_FLOAT4(1);
628  float4 result;
629 
630  if (float4_gt(arg1, arg2))
631  result = arg1;
632  else
633  result = arg2;
634  PG_RETURN_FLOAT4(result);
635 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:309
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float4le()

Datum float4le ( PG_FUNCTION_ARGS  )

Definition at line 857 of file float.c.

References float4_le(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

858 {
859  float4 arg1 = PG_GETARG_FLOAT4(0);
860  float4 arg2 = PG_GETARG_FLOAT4(1);
861 
862  PG_RETURN_BOOL(float4_le(arg1, arg2));
863 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float4_le(const float4 val1, const float4 val2)
Definition: float.h:297

◆ float4lt()

Datum float4lt ( PG_FUNCTION_ARGS  )

Definition at line 848 of file float.c.

References float4_lt(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

849 {
850  float4 arg1 = PG_GETARG_FLOAT4(0);
851  float4 arg2 = PG_GETARG_FLOAT4(1);
852 
853  PG_RETURN_BOOL(float4_lt(arg1, arg2));
854 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:285

◆ float4mi()

Datum float4mi ( PG_FUNCTION_ARGS  )

Definition at line 741 of file float.c.

References float4_mi(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

742 {
743  float4 arg1 = PG_GETARG_FLOAT4(0);
744  float4 arg2 = PG_GETARG_FLOAT4(1);
745 
746  PG_RETURN_FLOAT4(float4_mi(arg1, arg2));
747 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
static float4 float4_mi(const float4 val1, const float4 val2)
Definition: float.h:169
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float4mul()

Datum float4mul ( PG_FUNCTION_ARGS  )

Definition at line 750 of file float.c.

References float4_mul(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

751 {
752  float4 arg1 = PG_GETARG_FLOAT4(0);
753  float4 arg2 = PG_GETARG_FLOAT4(1);
754 
755  PG_RETURN_FLOAT4(float4_mul(arg1, arg2));
756 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
static float4 float4_mul(const float4 val1, const float4 val2)
Definition: float.h:193

◆ float4ne()

Datum float4ne ( PG_FUNCTION_ARGS  )

Definition at line 839 of file float.c.

References float4_ne(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

840 {
841  float4 arg1 = PG_GETARG_FLOAT4(0);
842  float4 arg2 = PG_GETARG_FLOAT4(1);
843 
844  PG_RETURN_BOOL(float4_ne(arg1, arg2));
845 }
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float4_ne(const float4 val1, const float4 val2)
Definition: float.h:273

◆ float4out()

Datum float4out ( PG_FUNCTION_ARGS  )

Definition at line 294 of file float.c.

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

295 {
296  float4 num = PG_GETARG_FLOAT4(0);
297  char *ascii = (char *) palloc(32);
298  int ndig = FLT_DIG + extra_float_digits;
299 
300  if (extra_float_digits > 0)
301  {
302  float_to_shortest_decimal_buf(num, ascii);
303  PG_RETURN_CSTRING(ascii);
304  }
305 
306  (void) pg_strfromd(ascii, 32, ndig, num);
307  PG_RETURN_CSTRING(ascii);
308 }
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:281
int pg_strfromd(char *str, size_t count, int precision, double value)
Definition: snprintf.c:1263
float float4
Definition: c.h:552
int extra_float_digits
Definition: float.c:42
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:950

◆ float4pl()

Datum float4pl ( PG_FUNCTION_ARGS  )

Definition at line 732 of file float.c.

References float4_pl(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

733 {
734  float4 arg1 = PG_GETARG_FLOAT4(0);
735  float4 arg2 = PG_GETARG_FLOAT4(1);
736 
737  PG_RETURN_FLOAT4(float4_pl(arg1, arg2));
738 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
static float4 float4_pl(const float4 val1, const float4 val2)
Definition: float.h:145

◆ float4recv()

Datum float4recv ( PG_FUNCTION_ARGS  )

Definition at line 314 of file float.c.

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

315 {
317 
319 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:68
float4 pq_getmsgfloat4(StringInfo msg)
Definition: pqformat.c:471

◆ float4send()

Datum float4send ( PG_FUNCTION_ARGS  )

Definition at line 325 of file float.c.

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

326 {
327  float4 num = PG_GETARG_FLOAT4(0);
329 
330  pq_begintypsend(&buf);
331  pq_sendfloat4(&buf, num);
333 }
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:371
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:68
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float4smaller()

Datum float4smaller ( PG_FUNCTION_ARGS  )

Definition at line 638 of file float.c.

References float4_lt(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

639 {
640  float4 arg1 = PG_GETARG_FLOAT4(0);
641  float4 arg2 = PG_GETARG_FLOAT4(1);
642  float4 result;
643 
644  if (float4_lt(arg1, arg2))
645  result = arg1;
646  else
647  result = arg2;
648  PG_RETURN_FLOAT4(result);
649 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:285

◆ float4um()

Datum float4um ( PG_FUNCTION_ARGS  )

Definition at line 606 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

607 {
608  float4 arg1 = PG_GETARG_FLOAT4(0);
609  float4 result;
610 
611  result = -arg1;
612  PG_RETURN_FLOAT4(result);
613 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float4up()

Datum float4up ( PG_FUNCTION_ARGS  )

Definition at line 616 of file float.c.

References arg, PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

617 {
619 
620  PG_RETURN_FLOAT4(arg);
621 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
void * arg

◆ float84div()

Datum float84div ( PG_FUNCTION_ARGS  )

Definition at line 3876 of file float.c.

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

3877 {
3878  float8 arg1 = PG_GETARG_FLOAT8(0);
3879  float4 arg2 = PG_GETARG_FLOAT4(1);
3880 
3881  PG_RETURN_FLOAT8(float8_div(arg1, (float8) arg2));
3882 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ float84eq()

Datum float84eq ( PG_FUNCTION_ARGS  )

Definition at line 3951 of file float.c.

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

3952 {
3953  float8 arg1 = PG_GETARG_FLOAT8(0);
3954  float4 arg2 = PG_GETARG_FLOAT4(1);
3955 
3956  PG_RETURN_BOOL(float8_eq(arg1, (float8) arg2));
3957 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:267

◆ float84ge()

Datum float84ge ( PG_FUNCTION_ARGS  )

Definition at line 3996 of file float.c.

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

3997 {
3998  float8 arg1 = PG_GETARG_FLOAT8(0);
3999  float4 arg2 = PG_GETARG_FLOAT4(1);
4000 
4001  PG_RETURN_BOOL(float8_ge(arg1, (float8) arg2));
4002 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
static bool float8_ge(const float8 val1, const float8 val2)
Definition: float.h:327
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float84gt()

Datum float84gt ( PG_FUNCTION_ARGS  )

Definition at line 3987 of file float.c.

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

3988 {
3989  float8 arg1 = PG_GETARG_FLOAT8(0);
3990  float4 arg2 = PG_GETARG_FLOAT4(1);
3991 
3992  PG_RETURN_BOOL(float8_gt(arg1, (float8) arg2));
3993 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float84le()

Datum float84le ( PG_FUNCTION_ARGS  )

Definition at line 3978 of file float.c.

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

3979 {
3980  float8 arg1 = PG_GETARG_FLOAT8(0);
3981  float4 arg2 = PG_GETARG_FLOAT4(1);
3982 
3983  PG_RETURN_BOOL(float8_le(arg1, (float8) arg2));
3984 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static bool float8_le(const float8 val1, const float8 val2)
Definition: float.h:303
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float84lt()

Datum float84lt ( PG_FUNCTION_ARGS  )

Definition at line 3969 of file float.c.

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

3970 {
3971  float8 arg1 = PG_GETARG_FLOAT8(0);
3972  float4 arg2 = PG_GETARG_FLOAT4(1);
3973 
3974  PG_RETURN_BOOL(float8_lt(arg1, (float8) arg2));
3975 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float84mi()

Datum float84mi ( PG_FUNCTION_ARGS  )

Definition at line 3858 of file float.c.

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

3859 {
3860  float8 arg1 = PG_GETARG_FLOAT8(0);
3861  float4 arg2 = PG_GETARG_FLOAT4(1);
3862 
3863  PG_RETURN_FLOAT8(float8_mi(arg1, (float8) arg2));
3864 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float84mul()

Datum float84mul ( PG_FUNCTION_ARGS  )

Definition at line 3867 of file float.c.

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

3868 {
3869  float8 arg1 = PG_GETARG_FLOAT8(0);
3870  float4 arg2 = PG_GETARG_FLOAT4(1);
3871 
3872  PG_RETURN_FLOAT8(float8_mul(arg1, (float8) arg2));
3873 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float84ne()

Datum float84ne ( PG_FUNCTION_ARGS  )

Definition at line 3960 of file float.c.

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

3961 {
3962  float8 arg1 = PG_GETARG_FLOAT8(0);
3963  float4 arg2 = PG_GETARG_FLOAT4(1);
3964 
3965  PG_RETURN_BOOL(float8_ne(arg1, (float8) arg2));
3966 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static bool float8_ne(const float8 val1, const float8 val2)
Definition: float.h:279
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float84pl()

Datum float84pl ( PG_FUNCTION_ARGS  )

Definition at line 3849 of file float.c.

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

3850 {
3851  float8 arg1 = PG_GETARG_FLOAT8(0);
3852  float4 arg2 = PG_GETARG_FLOAT4(1);
3853 
3854  PG_RETURN_FLOAT8(float8_pl(arg1, (float8) arg2));
3855 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ float8_accum()

Datum float8_accum ( PG_FUNCTION_ARGS  )

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

2981 {
2982  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
2984  float8 *transvalues;
2985  float8 N,
2986  Sx,
2987  Sxx,
2988  tmp;
2989 
2990  transvalues = check_float8_array(transarray, "float8_accum", 3);
2991  N = transvalues[0];
2992  Sx = transvalues[1];
2993  Sxx = transvalues[2];
2994 
2995  /*
2996  * Use the Youngs-Cramer algorithm to incorporate the new value into the
2997  * transition values.
2998  */
2999  N += 1.0;
3000  Sx += newval;
3001  if (transvalues[0] > 0.0)
3002  {
3003  tmp = newval * N - Sx;
3004  Sxx += tmp * tmp / (N * transvalues[0]);
3005 
3006  /*
3007  * Overflow check. We only report an overflow error when finite
3008  * inputs lead to infinite results. Note also that Sxx should be NaN
3009  * if any of the inputs are infinite, so we intentionally prevent Sxx
3010  * from becoming infinite.
3011  */
3012  if (isinf(Sx) || isinf(Sxx))
3013  {
3014  if (!isinf(transvalues[1]) && !isinf(newval))
3016 
3017  Sxx = get_float8_nan();
3018  }
3019  }
3020  else
3021  {
3022  /*
3023  * At the first input, we normally can leave Sxx as 0. However, if
3024  * the first input is Inf or NaN, we'd better force Sxx to NaN;
3025  * otherwise we will falsely report variance zero when there are no
3026  * more inputs.
3027  */
3028  if (isnan(newval) || isinf(newval))
3029  Sxx = get_float8_nan();
3030  }
3031 
3032  /*
3033  * If we're invoked as an aggregate, we can cheat and modify our first
3034  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3035  * new array with the updated transition data and return it.
3036  */
3037  if (AggCheckCallContext(fcinfo, NULL))
3038  {
3039  transvalues[0] = N;
3040  transvalues[1] = Sx;
3041  transvalues[2] = Sxx;
3042 
3043  PG_RETURN_ARRAYTYPE_P(transarray);
3044  }
3045  else
3046  {
3047  Datum transdatums[3];
3048  ArrayType *result;
3049 
3050  transdatums[0] = Float8GetDatumFast(N);
3051  transdatums[1] = Float8GetDatumFast(Sx);
3052  transdatums[2] = Float8GetDatumFast(Sxx);
3053 
3054  result = construct_array(transdatums, 3,
3055  FLOAT8OID,
3056  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3057 
3058  PG_RETURN_ARRAYTYPE_P(result);
3059  }
3060 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
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:553
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:558
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define newval
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4572
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862

◆ float8_avg()

Datum float8_avg ( PG_FUNCTION_ARGS  )

Definition at line 3148 of file float.c.

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

3149 {
3150  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3151  float8 *transvalues;
3152  float8 N,
3153  Sx;
3154 
3155  transvalues = check_float8_array(transarray, "float8_avg", 3);
3156  N = transvalues[0];
3157  Sx = transvalues[1];
3158  /* ignore Sxx */
3159 
3160  /* SQL defines AVG of no values to be NULL */
3161  if (N == 0.0)
3162  PG_RETURN_NULL();
3163 
3164  PG_RETURN_FLOAT8(Sx / N);
3165 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_cmp_internal()

int float8_cmp_internal ( float8  a,
float8  b 
)

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

915 {
916  if (float8_gt(a, b))
917  return 1;
918  if (float8_lt(a, b))
919  return -1;
920  return 0;
921 }
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 2886 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.

2887 {
2888  ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(0);
2889  ArrayType *transarray2 = PG_GETARG_ARRAYTYPE_P(1);
2890  float8 *transvalues1;
2891  float8 *transvalues2;
2892  float8 N1,
2893  Sx1,
2894  Sxx1,
2895  N2,
2896  Sx2,
2897  Sxx2,
2898  tmp,
2899  N,
2900  Sx,
2901  Sxx;
2902 
2903  transvalues1 = check_float8_array(transarray1, "float8_combine", 3);
2904  transvalues2 = check_float8_array(transarray2, "float8_combine", 3);
2905 
2906  N1 = transvalues1[0];
2907  Sx1 = transvalues1[1];
2908  Sxx1 = transvalues1[2];
2909 
2910  N2 = transvalues2[0];
2911  Sx2 = transvalues2[1];
2912  Sxx2 = transvalues2[2];
2913 
2914  /*--------------------
2915  * The transition values combine using a generalization of the
2916  * Youngs-Cramer algorithm as follows:
2917  *
2918  * N = N1 + N2
2919  * Sx = Sx1 + Sx2
2920  * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N;
2921  *
2922  * It's worth handling the special cases N1 = 0 and N2 = 0 separately
2923  * since those cases are trivial, and we then don't need to worry about
2924  * division-by-zero errors in the general case.
2925  *--------------------
2926  */
2927  if (N1 == 0.0)
2928  {
2929  N = N2;
2930  Sx = Sx2;
2931  Sxx = Sxx2;
2932  }
2933  else if (N2 == 0.0)
2934  {
2935  N = N1;
2936  Sx = Sx1;
2937  Sxx = Sxx1;
2938  }
2939  else
2940  {
2941  N = N1 + N2;
2942  Sx = float8_pl(Sx1, Sx2);
2943  tmp = Sx1 / N1 - Sx2 / N2;
2944  Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp * tmp / N;
2945  if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))
2947  }
2948 
2949  /*
2950  * If we're invoked as an aggregate, we can cheat and modify our first
2951  * parameter in-place to reduce palloc overhead. Otherwise we construct a
2952  * new array with the updated transition data and return it.
2953  */
2954  if (AggCheckCallContext(fcinfo, NULL))
2955  {
2956  transvalues1[0] = N;
2957  transvalues1[1] = Sx;
2958  transvalues1[2] = Sxx;
2959 
2960  PG_RETURN_ARRAYTYPE_P(transarray1);
2961  }
2962  else
2963  {
2964  Datum transdatums[3];
2965  ArrayType *result;
2966 
2967  transdatums[0] = Float8GetDatumFast(N);
2968  transdatums[1] = Float8GetDatumFast(Sx);
2969  transdatums[2] = Float8GetDatumFast(Sxx);
2970 
2971  result = construct_array(transdatums, 3,
2972  FLOAT8OID,
2973  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
2974 
2975  PG_RETURN_ARRAYTYPE_P(result);
2976  }
2977 }
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:553
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:558
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4572
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define unlikely(x)
Definition: c.h:261

◆ float8_corr()

Datum float8_corr ( PG_FUNCTION_ARGS  )

Definition at line 3674 of file float.c.

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

3675 {
3676  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3677  float8 *transvalues;
3678  float8 N,
3679  Sxx,
3680  Syy,
3681  Sxy;
3682 
3683  transvalues = check_float8_array(transarray, "float8_corr", 6);
3684  N = transvalues[0];
3685  Sxx = transvalues[2];
3686  Syy = transvalues[4];
3687  Sxy = transvalues[5];
3688 
3689  /* if N is 0 we should return NULL */
3690  if (N < 1.0)
3691  PG_RETURN_NULL();
3692 
3693  /* Note that Sxx and Syy are guaranteed to be non-negative */
3694 
3695  /* per spec, return NULL for horizontal and vertical lines */
3696  if (Sxx == 0 || Syy == 0)
3697  PG_RETURN_NULL();
3698 
3699  PG_RETURN_FLOAT8(Sxy / sqrt(Sxx * Syy));
3700 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_covar_pop()

Datum float8_covar_pop ( PG_FUNCTION_ARGS  )

Definition at line 3636 of file float.c.

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

3637 {
3638  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3639  float8 *transvalues;
3640  float8 N,
3641  Sxy;
3642 
3643  transvalues = check_float8_array(transarray, "float8_covar_pop", 6);
3644  N = transvalues[0];
3645  Sxy = transvalues[5];
3646 
3647  /* if N is 0 we should return NULL */
3648  if (N < 1.0)
3649  PG_RETURN_NULL();
3650 
3651  PG_RETURN_FLOAT8(Sxy / N);
3652 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_covar_samp()

Datum float8_covar_samp ( PG_FUNCTION_ARGS  )

Definition at line 3655 of file float.c.

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

3656 {
3657  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3658  float8 *transvalues;
3659  float8 N,
3660  Sxy;
3661 
3662  transvalues = check_float8_array(transarray, "float8_covar_samp", 6);
3663  N = transvalues[0];
3664  Sxy = transvalues[5];
3665 
3666  /* if N is <= 1 we should return NULL */
3667  if (N < 2.0)
3668  PG_RETURN_NULL();
3669 
3670  PG_RETURN_FLOAT8(Sxy / (N - 1.0));
3671 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_accum()

Datum float8_regr_accum ( PG_FUNCTION_ARGS  )

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

3278 {
3279  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3280  float8 newvalY = PG_GETARG_FLOAT8(1);
3281  float8 newvalX = PG_GETARG_FLOAT8(2);
3282  float8 *transvalues;
3283  float8 N,
3284  Sx,
3285  Sxx,
3286  Sy,
3287  Syy,
3288  Sxy,
3289  tmpX,
3290  tmpY,
3291  scale;
3292 
3293  transvalues = check_float8_array(transarray, "float8_regr_accum", 6);
3294  N = transvalues[0];
3295  Sx = transvalues[1];
3296  Sxx = transvalues[2];
3297  Sy = transvalues[3];
3298  Syy = transvalues[4];
3299  Sxy = transvalues[5];
3300 
3301  /*
3302  * Use the Youngs-Cramer algorithm to incorporate the new values into the
3303  * transition values.
3304  */
3305  N += 1.0;
3306  Sx += newvalX;
3307  Sy += newvalY;
3308  if (transvalues[0] > 0.0)
3309  {
3310  tmpX = newvalX * N - Sx;
3311  tmpY = newvalY * N - Sy;
3312  scale = 1.0 / (N * transvalues[0]);
3313  Sxx += tmpX * tmpX * scale;
3314  Syy += tmpY * tmpY * scale;
3315  Sxy += tmpX * tmpY * scale;
3316 
3317  /*
3318  * Overflow check. We only report an overflow error when finite
3319  * inputs lead to infinite results. Note also that Sxx, Syy and Sxy
3320  * should be NaN if any of the relevant inputs are infinite, so we
3321  * intentionally prevent them from becoming infinite.
3322  */
3323  if (isinf(Sx) || isinf(Sxx) || isinf(Sy) || isinf(Syy) || isinf(Sxy))
3324  {
3325  if (((isinf(Sx) || isinf(Sxx)) &&
3326  !isinf(transvalues[1]) && !isinf(newvalX)) ||
3327  ((isinf(Sy) || isinf(Syy)) &&
3328  !isinf(transvalues[3]) && !isinf(newvalY)) ||
3329  (isinf(Sxy) &&
3330  !isinf(transvalues[1]) && !isinf(newvalX) &&
3331  !isinf(transvalues[3]) && !isinf(newvalY)))
3333 
3334  if (isinf(Sxx))
3335  Sxx = get_float8_nan();
3336  if (isinf(Syy))
3337  Syy = get_float8_nan();
3338  if (isinf(Sxy))
3339  Sxy = get_float8_nan();
3340  }
3341  }
3342  else
3343  {
3344  /*
3345  * At the first input, we normally can leave Sxx et al as 0. However,
3346  * if the first input is Inf or NaN, we'd better force the dependent
3347  * sums to NaN; otherwise we will falsely report variance zero when
3348  * there are no more inputs.
3349  */
3350  if (isnan(newvalX) || isinf(newvalX))
3351  Sxx = Sxy = get_float8_nan();
3352  if (isnan(newvalY) || isinf(newvalY))
3353  Syy = Sxy = get_float8_nan();
3354  }
3355 
3356  /*
3357  * If we're invoked as an aggregate, we can cheat and modify our first
3358  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3359  * new array with the updated transition data and return it.
3360  */
3361  if (AggCheckCallContext(fcinfo, NULL))
3362  {
3363  transvalues[0] = N;
3364  transvalues[1] = Sx;
3365  transvalues[2] = Sxx;
3366  transvalues[3] = Sy;
3367  transvalues[4] = Syy;
3368  transvalues[5] = Sxy;
3369 
3370  PG_RETURN_ARRAYTYPE_P(transarray);
3371  }
3372  else
3373  {
3374  Datum transdatums[6];
3375  ArrayType *result;
3376 
3377  transdatums[0] = Float8GetDatumFast(N);
3378  transdatums[1] = Float8GetDatumFast(Sx);
3379  transdatums[2] = Float8GetDatumFast(Sxx);
3380  transdatums[3] = Float8GetDatumFast(Sy);
3381  transdatums[4] = Float8GetDatumFast(Syy);
3382  transdatums[5] = Float8GetDatumFast(Sxy);
3383 
3384  result = construct_array(transdatums, 6,
3385  FLOAT8OID,
3386  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3387 
3388  PG_RETURN_ARRAYTYPE_P(result);
3389  }
3390 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
int scale
Definition: pgbench.c:154
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
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:558
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4572
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862

◆ float8_regr_avgx()

Datum float8_regr_avgx ( PG_FUNCTION_ARGS  )

Definition at line 3598 of file float.c.

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

3599 {
3600  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3601  float8 *transvalues;
3602  float8 N,
3603  Sx;
3604 
3605  transvalues = check_float8_array(transarray, "float8_regr_avgx", 6);
3606  N = transvalues[0];
3607  Sx = transvalues[1];
3608 
3609  /* if N is 0 we should return NULL */
3610  if (N < 1.0)
3611  PG_RETURN_NULL();
3612 
3613  PG_RETURN_FLOAT8(Sx / N);
3614 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_avgy()

Datum float8_regr_avgy ( PG_FUNCTION_ARGS  )

Definition at line 3617 of file float.c.

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

3618 {
3619  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3620  float8 *transvalues;
3621  float8 N,
3622  Sy;
3623 
3624  transvalues = check_float8_array(transarray, "float8_regr_avgy", 6);
3625  N = transvalues[0];
3626  Sy = transvalues[3];
3627 
3628  /* if N is 0 we should return NULL */
3629  if (N < 1.0)
3630  PG_RETURN_NULL();
3631 
3632  PG_RETURN_FLOAT8(Sy / N);
3633 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_combine()

Datum float8_regr_combine ( PG_FUNCTION_ARGS  )

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

3402 {
3403  ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(0);
3404  ArrayType *transarray2 = PG_GETARG_ARRAYTYPE_P(1);
3405  float8 *transvalues1;
3406  float8 *transvalues2;
3407  float8 N1,
3408  Sx1,
3409  Sxx1,
3410  Sy1,
3411  Syy1,
3412  Sxy1,
3413  N2,
3414  Sx2,
3415  Sxx2,
3416  Sy2,
3417  Syy2,
3418  Sxy2,
3419  tmp1,
3420  tmp2,
3421  N,
3422  Sx,
3423  Sxx,
3424  Sy,
3425  Syy,
3426  Sxy;
3427 
3428  transvalues1 = check_float8_array(transarray1, "float8_regr_combine", 6);
3429  transvalues2 = check_float8_array(transarray2, "float8_regr_combine", 6);
3430 
3431  N1 = transvalues1[0];
3432  Sx1 = transvalues1[1];
3433  Sxx1 = transvalues1[2];
3434  Sy1 = transvalues1[3];
3435  Syy1 = transvalues1[4];
3436  Sxy1 = transvalues1[5];
3437 
3438  N2 = transvalues2[0];
3439  Sx2 = transvalues2[1];
3440  Sxx2 = transvalues2[2];
3441  Sy2 = transvalues2[3];
3442  Syy2 = transvalues2[4];
3443  Sxy2 = transvalues2[5];
3444 
3445  /*--------------------
3446  * The transition values combine using a generalization of the
3447  * Youngs-Cramer algorithm as follows:
3448  *
3449  * N = N1 + N2
3450  * Sx = Sx1 + Sx2
3451  * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N
3452  * Sy = Sy1 + Sy2
3453  * Syy = Syy1 + Syy2 + N1 * N2 * (Sy1/N1 - Sy2/N2)^2 / N
3454  * Sxy = Sxy1 + Sxy2 + N1 * N2 * (Sx1/N1 - Sx2/N2) * (Sy1/N1 - Sy2/N2) / N
3455  *
3456  * It's worth handling the special cases N1 = 0 and N2 = 0 separately
3457  * since those cases are trivial, and we then don't need to worry about
3458  * division-by-zero errors in the general case.
3459  *--------------------
3460  */
3461  if (N1 == 0.0)
3462  {
3463  N = N2;
3464  Sx = Sx2;
3465  Sxx = Sxx2;
3466  Sy = Sy2;
3467  Syy = Syy2;
3468  Sxy = Sxy2;
3469  }
3470  else if (N2 == 0.0)
3471  {
3472  N = N1;
3473  Sx = Sx1;
3474  Sxx = Sxx1;
3475  Sy = Sy1;
3476  Syy = Syy1;
3477  Sxy = Sxy1;
3478  }
3479  else
3480  {
3481  N = N1 + N2;
3482  Sx = float8_pl(Sx1, Sx2);
3483  tmp1 = Sx1 / N1 - Sx2 / N2;
3484  Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp1 * tmp1 / N;
3485  if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))
3487  Sy = float8_pl(Sy1, Sy2);
3488  tmp2 = Sy1 / N1 - Sy2 / N2;
3489  Syy = Syy1 + Syy2 + N1 * N2 * tmp2 * tmp2 / N;
3490  if (unlikely(isinf(Syy)) && !isinf(Syy1) && !isinf(Syy2))
3492  Sxy = Sxy1 + Sxy2 + N1 * N2 * tmp1 * tmp2 / N;
3493  if (unlikely(isinf(Sxy)) && !isinf(Sxy1) && !isinf(Sxy2))
3495  }
3496 
3497  /*
3498  * If we're invoked as an aggregate, we can cheat and modify our first
3499  * parameter in-place to reduce palloc overhead. Otherwise we construct a
3500  * new array with the updated transition data and return it.
3501  */
3502  if (AggCheckCallContext(fcinfo, NULL))
3503  {
3504  transvalues1[0] = N;
3505  transvalues1[1] = Sx;
3506  transvalues1[2] = Sxx;
3507  transvalues1[3] = Sy;
3508  transvalues1[4] = Syy;
3509  transvalues1[5] = Sxy;
3510 
3511  PG_RETURN_ARRAYTYPE_P(transarray1);
3512  }
3513  else
3514  {
3515  Datum transdatums[6];
3516  ArrayType *result;
3517 
3518  transdatums[0] = Float8GetDatumFast(N);
3519  transdatums[1] = Float8GetDatumFast(Sx);
3520  transdatums[2] = Float8GetDatumFast(Sxx);
3521  transdatums[3] = Float8GetDatumFast(Sy);
3522  transdatums[4] = Float8GetDatumFast(Syy);
3523  transdatums[5] = Float8GetDatumFast(Sxy);
3524 
3525  result = construct_array(transdatums, 6,
3526  FLOAT8OID,
3527  sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
3528 
3529  PG_RETURN_ARRAYTYPE_P(result);
3530  }
3531 }
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:553
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:558
pg_noinline void float_overflow_error(void)
Definition: float.c:84
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4572
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define unlikely(x)
Definition: c.h:261

◆ float8_regr_intercept()

Datum float8_regr_intercept ( PG_FUNCTION_ARGS  )

Definition at line 3763 of file float.c.

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

3764 {
3765  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3766  float8 *transvalues;
3767  float8 N,
3768  Sx,
3769  Sxx,
3770  Sy,
3771  Sxy;
3772 
3773  transvalues = check_float8_array(transarray, "float8_regr_intercept", 6);
3774  N = transvalues[0];
3775  Sx = transvalues[1];
3776  Sxx = transvalues[2];
3777  Sy = transvalues[3];
3778  Sxy = transvalues[5];
3779 
3780  /* if N is 0 we should return NULL */
3781  if (N < 1.0)
3782  PG_RETURN_NULL();
3783 
3784  /* Note that Sxx is guaranteed to be non-negative */
3785 
3786  /* per spec, return NULL for a vertical line */
3787  if (Sxx == 0)
3788  PG_RETURN_NULL();
3789 
3790  PG_RETURN_FLOAT8((Sy - Sx * Sxy / Sxx) / N);
3791 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_r2()

Datum float8_regr_r2 ( PG_FUNCTION_ARGS  )

Definition at line 3703 of file float.c.

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

3704 {
3705  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3706  float8 *transvalues;
3707  float8 N,
3708  Sxx,
3709  Syy,
3710  Sxy;
3711 
3712  transvalues = check_float8_array(transarray, "float8_regr_r2", 6);
3713  N = transvalues[0];
3714  Sxx = transvalues[2];
3715  Syy = transvalues[4];
3716  Sxy = transvalues[5];
3717 
3718  /* if N is 0 we should return NULL */
3719  if (N < 1.0)
3720  PG_RETURN_NULL();
3721 
3722  /* Note that Sxx and Syy are guaranteed to be non-negative */
3723 
3724  /* per spec, return NULL for a vertical line */
3725  if (Sxx == 0)
3726  PG_RETURN_NULL();
3727 
3728  /* per spec, return 1.0 for a horizontal line */
3729  if (Syy == 0)
3730  PG_RETURN_FLOAT8(1.0);
3731 
3732  PG_RETURN_FLOAT8((Sxy * Sxy) / (Sxx * Syy));
3733 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_slope()

Datum float8_regr_slope ( PG_FUNCTION_ARGS  )

Definition at line 3736 of file float.c.

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

3737 {
3738  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3739  float8 *transvalues;
3740  float8 N,
3741  Sxx,
3742  Sxy;
3743 
3744  transvalues = check_float8_array(transarray, "float8_regr_slope", 6);
3745  N = transvalues[0];
3746  Sxx = transvalues[2];
3747  Sxy = transvalues[5];
3748 
3749  /* if N is 0 we should return NULL */
3750  if (N < 1.0)
3751  PG_RETURN_NULL();
3752 
3753  /* Note that Sxx is guaranteed to be non-negative */
3754 
3755  /* per spec, return NULL for a vertical line */
3756  if (Sxx == 0)
3757  PG_RETURN_NULL();
3758 
3759  PG_RETURN_FLOAT8(Sxy / Sxx);
3760 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_sxx()

Datum float8_regr_sxx ( PG_FUNCTION_ARGS  )

Definition at line 3535 of file float.c.

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

3536 {
3537  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3538  float8 *transvalues;
3539  float8 N,
3540  Sxx;
3541 
3542  transvalues = check_float8_array(transarray, "float8_regr_sxx", 6);
3543  N = transvalues[0];
3544  Sxx = transvalues[2];
3545 
3546  /* if N is 0 we should return NULL */
3547  if (N < 1.0)
3548  PG_RETURN_NULL();
3549 
3550  /* Note that Sxx is guaranteed to be non-negative */
3551 
3552  PG_RETURN_FLOAT8(Sxx);
3553 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_sxy()

Datum float8_regr_sxy ( PG_FUNCTION_ARGS  )

Definition at line 3577 of file float.c.

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

3578 {
3579  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3580  float8 *transvalues;
3581  float8 N,
3582  Sxy;
3583 
3584  transvalues = check_float8_array(transarray, "float8_regr_sxy", 6);
3585  N = transvalues[0];
3586  Sxy = transvalues[5];
3587 
3588  /* if N is 0 we should return NULL */
3589  if (N < 1.0)
3590  PG_RETURN_NULL();
3591 
3592  /* A negative result is valid here */
3593 
3594  PG_RETURN_FLOAT8(Sxy);
3595 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_regr_syy()

Datum float8_regr_syy ( PG_FUNCTION_ARGS  )

Definition at line 3556 of file float.c.

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

3557 {
3558  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3559  float8 *transvalues;
3560  float8 N,
3561  Syy;
3562 
3563  transvalues = check_float8_array(transarray, "float8_regr_syy", 6);
3564  N = transvalues[0];
3565  Syy = transvalues[4];
3566 
3567  /* if N is 0 we should return NULL */
3568  if (N < 1.0)
3569  PG_RETURN_NULL();
3570 
3571  /* Note that Syy is guaranteed to be non-negative */
3572 
3573  PG_RETURN_FLOAT8(Syy);
3574 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_stddev_pop()

Datum float8_stddev_pop ( PG_FUNCTION_ARGS  )

Definition at line 3212 of file float.c.

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

3213 {
3214  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3215  float8 *transvalues;
3216  float8 N,
3217  Sxx;
3218 
3219  transvalues = check_float8_array(transarray, "float8_stddev_pop", 3);
3220  N = transvalues[0];
3221  /* ignore Sx */
3222  Sxx = transvalues[2];
3223 
3224  /* Population stddev is undefined when N is 0, so return NULL */
3225  if (N == 0.0)
3226  PG_RETURN_NULL();
3227 
3228  /* Note that Sxx is guaranteed to be non-negative */
3229 
3230  PG_RETURN_FLOAT8(sqrt(Sxx / N));
3231 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_stddev_samp()

Datum float8_stddev_samp ( PG_FUNCTION_ARGS  )

Definition at line 3234 of file float.c.

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

3235 {
3236  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3237  float8 *transvalues;
3238  float8 N,
3239  Sxx;
3240 
3241  transvalues = check_float8_array(transarray, "float8_stddev_samp", 3);
3242  N = transvalues[0];
3243  /* ignore Sx */
3244  Sxx = transvalues[2];
3245 
3246  /* Sample stddev is undefined when N is 0 or 1, so return NULL */
3247  if (N <= 1.0)
3248  PG_RETURN_NULL();
3249 
3250  /* Note that Sxx is guaranteed to be non-negative */
3251 
3252  PG_RETURN_FLOAT8(sqrt(Sxx / (N - 1.0)));
3253 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_var_pop()

Datum float8_var_pop ( PG_FUNCTION_ARGS  )

Definition at line 3168 of file float.c.

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

3169 {
3170  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3171  float8 *transvalues;
3172  float8 N,
3173  Sxx;
3174 
3175  transvalues = check_float8_array(transarray, "float8_var_pop", 3);
3176  N = transvalues[0];
3177  /* ignore Sx */
3178  Sxx = transvalues[2];
3179 
3180  /* Population variance is undefined when N is 0, so return NULL */
3181  if (N == 0.0)
3182  PG_RETURN_NULL();
3183 
3184  /* Note that Sxx is guaranteed to be non-negative */
3185 
3186  PG_RETURN_FLOAT8(Sxx / N);
3187 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8_var_samp()

Datum float8_var_samp ( PG_FUNCTION_ARGS  )

Definition at line 3190 of file float.c.

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

3191 {
3192  ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
3193  float8 *transvalues;
3194  float8 N,
3195  Sxx;
3196 
3197  transvalues = check_float8_array(transarray, "float8_var_samp", 3);
3198  N = transvalues[0];
3199  /* ignore Sx */
3200  Sxx = transvalues[2];
3201 
3202  /* Sample variance is undefined when N is 0 or 1, so return NULL */
3203  if (N <= 1.0)
3204  PG_RETURN_NULL();
3205 
3206  /* Note that Sxx is guaranteed to be non-negative */
3207 
3208  PG_RETURN_FLOAT8(Sxx / (N - 1.0));
3209 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
double float8
Definition: c.h:553
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition: float.c:2862
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ float8abs()

Datum float8abs ( PG_FUNCTION_ARGS  )

Definition at line 661 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

662 {
663  float8 arg1 = PG_GETARG_FLOAT8(0);
664 
665  PG_RETURN_FLOAT8(fabs(arg1));
666 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ float8div()

Datum float8div ( PG_FUNCTION_ARGS  )

Definition at line 801 of file float.c.

References float8_div(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

802 {
803  float8 arg1 = PG_GETARG_FLOAT8(0);
804  float8 arg2 = PG_GETARG_FLOAT8(1);
805 
806  PG_RETURN_FLOAT8(float8_div(arg1, arg2));
807 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ float8eq()

Datum float8eq ( PG_FUNCTION_ARGS  )

Definition at line 924 of file float.c.

References float8_eq(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

925 {
926  float8 arg1 = PG_GETARG_FLOAT8(0);
927  float8 arg2 = PG_GETARG_FLOAT8(1);
928 
929  PG_RETURN_BOOL(float8_eq(arg1, arg2));
930 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:267

◆ float8ge()

Datum float8ge ( PG_FUNCTION_ARGS  )

Definition at line 969 of file float.c.

References float8_ge(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

970 {
971  float8 arg1 = PG_GETARG_FLOAT8(0);
972  float8 arg2 = PG_GETARG_FLOAT8(1);
973 
974  PG_RETURN_BOOL(float8_ge(arg1, arg2));
975 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
static bool float8_ge(const float8 val1, const float8 val2)
Definition: float.h:327
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float8gt()

Datum float8gt ( PG_FUNCTION_ARGS  )

Definition at line 960 of file float.c.

References float8_gt(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

961 {
962  float8 arg1 = PG_GETARG_FLOAT8(0);
963  float8 arg2 = PG_GETARG_FLOAT8(1);
964 
965  PG_RETURN_BOOL(float8_gt(arg1, arg2));
966 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float8in()

Datum float8in ( PG_FUNCTION_ARGS  )

Definition at line 339 of file float.c.

References float8in_internal(), PG_GETARG_CSTRING, and PG_RETURN_FLOAT8.

Referenced by numeric_float8().

340 {
341  char *num = PG_GETARG_CSTRING(0);
342 
343  PG_RETURN_FLOAT8(float8in_internal(num, NULL, "double precision", num));
344 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string)
Definition: float.c:513
#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 513 of file float.c.

References float8in_internal_opt_error().

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

515 {
516  return float8in_internal_opt_error(num, endptr_p, type_name,
517  orig_string, NULL);
518 }
double float8in_internal_opt_error(char *num, char **endptr_p, const char *type_name, const char *orig_string, bool *have_error)
Definition: float.c:379

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

382 {
383  double val;
384  char *endptr;
385 
386  if (have_error)
387  *have_error = false;
388 
389  /* skip leading whitespace */
390  while (*num != '\0' && isspace((unsigned char) *num))
391  num++;
392 
393  /*
394  * Check for an empty-string input to begin with, to avoid the vagaries of
395  * strtod() on different platforms.
396  */
397  if (*num == '\0')
399  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
400  errmsg("invalid input syntax for type %s: \"%s\"",
401  type_name, orig_string))),
402  have_error);
403 
404  errno = 0;
405  val = strtod(num, &endptr);
406 
407  /* did we not see anything that looks like a double? */
408  if (endptr == num || errno != 0)
409  {
410  int save_errno = errno;
411 
412  /*
413  * C99 requires that strtod() accept NaN, [+-]Infinity, and [+-]Inf,
414  * but not all platforms support all of these (and some accept them
415  * but set ERANGE anyway...) Therefore, we check for these inputs
416  * ourselves if strtod() fails.
417  *
418  * Note: C99 also requires hexadecimal input as well as some extended
419  * forms of NaN, but we consider these forms unportable and don't try
420  * to support them. You can use 'em if your strtod() takes 'em.
421  */
422  if (pg_strncasecmp(num, "NaN", 3) == 0)
423  {
424  val = get_float8_nan();
425  endptr = num + 3;
426  }
427  else if (pg_strncasecmp(num, "Infinity", 8) == 0)
428  {
429  val = get_float8_infinity();
430  endptr = num + 8;
431  }
432  else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
433  {
434  val = get_float8_infinity();
435  endptr = num + 9;
436  }
437  else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
438  {
439  val = -get_float8_infinity();
440  endptr = num + 9;
441  }
442  else if (pg_strncasecmp(num, "inf", 3) == 0)
443  {
444  val = get_float8_infinity();
445  endptr = num + 3;
446  }
447  else if (pg_strncasecmp(num, "+inf", 4) == 0)
448  {
449  val = get_float8_infinity();
450  endptr = num + 4;
451  }
452  else if (pg_strncasecmp(num, "-inf", 4) == 0)
453  {
454  val = -get_float8_infinity();
455  endptr = num + 4;
456  }
457  else if (save_errno == ERANGE)
458  {
459  /*
460  * Some platforms return ERANGE for denormalized numbers (those
461  * that are not zero, but are too close to zero to have full
462  * precision). We'd prefer not to throw error for that, so try to
463  * detect whether it's a "real" out-of-range condition by checking
464  * to see if the result is zero or huge.
465  *
466  * On error, we intentionally complain about double precision not
467  * the given type name, and we print only the part of the string
468  * that is the current number.
469  */
470  if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL)
471  {
472  char *errnumber = pstrdup(num);
473 
474  errnumber[endptr - num] = '\0';
476  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
477  errmsg("\"%s\" is out of range for type double precision",
478  errnumber))),
479  have_error);
480  }
481  }
482  else
484  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
485  errmsg("invalid input syntax for type "
486  "%s: \"%s\"",
487  type_name, orig_string))),
488  have_error);
489  }
490 
491  /* skip trailing whitespace */
492  while (*endptr != '\0' && isspace((unsigned char) *endptr))
493  endptr++;
494 
495  /* report stopping point if wanted, else complain if not end of string */
496  if (endptr_p)
497  *endptr_p = endptr;
498  else if (*endptr != '\0')
500  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
501  errmsg("invalid input syntax for type "
502  "%s: \"%s\"",
503  type_name, orig_string))),
504  have_error);
505 
506  return val;
507 }
static float8 get_float8_infinity(void)
Definition: float.h:93
char * pstrdup(const char *in)
Definition: mcxt.c:1187
int errcode(int sqlerrcode)
Definition: elog.c:691
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:155
#define RETURN_ERROR(throw_error, have_error)
Definition: float.c:347
int errmsg(const char *fmt,...)
Definition: elog.c:902
long val
Definition: informix.c:664

◆ float8larger()

Datum float8larger ( PG_FUNCTION_ARGS  )

Definition at line 691 of file float.c.

References float8_gt(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

692 {
693  float8 arg1 = PG_GETARG_FLOAT8(0);
694  float8 arg2 = PG_GETARG_FLOAT8(1);
695  float8 result;
696 
697  if (float8_gt(arg1, arg2))
698  result = arg1;
699  else
700  result = arg2;
701  PG_RETURN_FLOAT8(result);
702 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ float8le()

Datum float8le ( PG_FUNCTION_ARGS  )

Definition at line 951 of file float.c.

References float8_le(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

952 {
953  float8 arg1 = PG_GETARG_FLOAT8(0);
954  float8 arg2 = PG_GETARG_FLOAT8(1);
955 
956  PG_RETURN_BOOL(float8_le(arg1, arg2));
957 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static bool float8_le(const float8 val1, const float8 val2)
Definition: float.h:303
double float8
Definition: c.h:553
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float8lt()

Datum float8lt ( PG_FUNCTION_ARGS  )

Definition at line 942 of file float.c.

References float8_lt(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

943 {
944  float8 arg1 = PG_GETARG_FLOAT8(0);
945  float8 arg2 = PG_GETARG_FLOAT8(1);
946 
947  PG_RETURN_BOOL(float8_lt(arg1, arg2));
948 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
double float8
Definition: c.h:553
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float8mi()

Datum float8mi ( PG_FUNCTION_ARGS  )

Definition at line 783 of file float.c.

References float8_mi(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

784 {
785  float8 arg1 = PG_GETARG_FLOAT8(0);
786  float8 arg2 = PG_GETARG_FLOAT8(1);
787 
788  PG_RETURN_FLOAT8(float8_mi(arg1, arg2));
789 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181

◆ float8mul()

Datum float8mul ( PG_FUNCTION_ARGS  )

Definition at line 792 of file float.c.

References float8_mul(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

793 {
794  float8 arg1 = PG_GETARG_FLOAT8(0);
795  float8 arg2 = PG_GETARG_FLOAT8(1);
796 
797  PG_RETURN_FLOAT8(float8_mul(arg1, arg2));
798 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
double float8
Definition: c.h:553

◆ float8ne()

Datum float8ne ( PG_FUNCTION_ARGS  )

Definition at line 933 of file float.c.

References float8_ne(), PG_GETARG_FLOAT8, and PG_RETURN_BOOL.

934 {
935  float8 arg1 = PG_GETARG_FLOAT8(0);
936  float8 arg2 = PG_GETARG_FLOAT8(1);
937 
938  PG_RETURN_BOOL(float8_ne(arg1, arg2));
939 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static bool float8_ne(const float8 val1, const float8 val2)
Definition: float.h:279
double float8
Definition: c.h:553
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ float8out()

Datum float8out ( PG_FUNCTION_ARGS  )

Definition at line 526 of file float.c.

References float8out_internal(), PG_GETARG_FLOAT8, and PG_RETURN_CSTRING.

527 {
528  float8 num = PG_GETARG_FLOAT8(0);
529 
531 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
char * float8out_internal(double num)
Definition: float.c:541
double float8
Definition: c.h:553
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362

◆ float8out_internal()

char* float8out_internal ( double  num)

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

542 {
543  char *ascii = (char *) palloc(32);
544  int ndig = DBL_DIG + extra_float_digits;
545 
546  if (extra_float_digits > 0)
547  {
548  double_to_shortest_decimal_buf(num, ascii);
549  return ascii;
550  }
551 
552  (void) pg_strfromd(ascii, 32, ndig, num);
553  return ascii;
554 }
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:950

◆ float8pl()

Datum float8pl ( PG_FUNCTION_ARGS  )

Definition at line 774 of file float.c.

References float8_pl(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

775 {
776  float8 arg1 = PG_GETARG_FLOAT8(0);
777  float8 arg2 = PG_GETARG_FLOAT8(1);
778 
779  PG_RETURN_FLOAT8(float8_pl(arg1, arg2));
780 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157

◆ float8recv()

Datum float8recv ( PG_FUNCTION_ARGS  )

Definition at line 560 of file float.c.

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

561 {
563 
565 }
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:68
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490

◆ float8send()

Datum float8send ( PG_FUNCTION_ARGS  )

Definition at line 571 of file float.c.

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

572 {
573  float8 num = PG_GETARG_FLOAT8(0);
575 
576  pq_begintypsend(&buf);
577  pq_sendfloat8(&buf, num);
579 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
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:371
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
double float8
Definition: c.h:553
static char * buf
Definition: pg_test_fsync.c:68

◆ float8smaller()

Datum float8smaller ( PG_FUNCTION_ARGS  )

Definition at line 705 of file float.c.

References float8_lt(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

706 {
707  float8 arg1 = PG_GETARG_FLOAT8(0);
708  float8 arg2 = PG_GETARG_FLOAT8(1);
709  float8 result;
710 
711  if (float8_lt(arg1, arg2))
712  result = arg1;
713  else
714  result = arg2;
715  PG_RETURN_FLOAT8(result);
716 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291

◆ float8um()

Datum float8um ( PG_FUNCTION_ARGS  )

Definition at line 673 of file float.c.

References PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

674 {
675  float8 arg1 = PG_GETARG_FLOAT8(0);
676  float8 result;
677 
678  result = -arg1;
679  PG_RETURN_FLOAT8(result);
680 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553

◆ float8up()

Datum float8up ( PG_FUNCTION_ARGS  )

Definition at line 683 of file float.c.

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

684 {
686 
687  PG_RETURN_FLOAT8(arg);
688 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
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:691
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ 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:691
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ 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:691
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ ftod()

Datum ftod ( PG_FUNCTION_ARGS  )

Definition at line 1187 of file float.c.

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT8.

1188 {
1189  float4 num = PG_GETARG_FLOAT4(0);
1190 
1191  PG_RETURN_FLOAT8((float8) num);
1192 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552

◆ ftoi2()

Datum ftoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1317 of file float.c.

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

1318 {
1319  float4 num = PG_GETARG_FLOAT4(0);
1320 
1321  /*
1322  * Get rid of any fractional part in the input. This is so we don't fail
1323  * on just-out-of-range values that would round into range. Note
1324  * assumption that rint() will pass through a NaN or Inf unchanged.
1325  */
1326  num = rint(num);
1327 
1328  /* Range check */
1329  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT16(num)))
1330  ereport(ERROR,
1331  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1332  errmsg("smallint out of range")));
1333 
1334  PG_RETURN_INT16((int16) num);
1335 }
signed short int16
Definition: c.h:416
#define PG_RETURN_INT16(x)
Definition: fmgr.h:356
int errcode(int sqlerrcode)
Definition: elog.c:691
#define FLOAT4_FITS_IN_INT16(num)
Definition: c.h:1093
#define ERROR
Definition: elog.h:43
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ ftoi4()

Datum ftoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1292 of file float.c.

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

1293 {
1294  float4 num = PG_GETARG_FLOAT4(0);
1295 
1296  /*
1297  * Get rid of any fractional part in the input. This is so we don't fail
1298  * on just-out-of-range values that would round into range. Note
1299  * assumption that rint() will pass through a NaN or Inf unchanged.
1300  */
1301  num = rint(num);
1302 
1303  /* Range check */
1304  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT32(num)))
1305  ereport(ERROR,
1306  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1307  errmsg("integer out of range")));
1308 
1309  PG_RETURN_INT32((int32) num);
1310 }
#define FLOAT4_FITS_IN_INT32(num)
Definition: c.h:1095
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int errcode(int sqlerrcode)
Definition: elog.c:691
signed int int32
Definition: c.h:417
#define ERROR
Definition: elog.h:43
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define unlikely(x)
Definition: c.h:261

◆ i2tod()

Datum i2tod ( PG_FUNCTION_ARGS  )

Definition at line 1280 of file float.c.

References PG_GETARG_INT16, and PG_RETURN_FLOAT8.

1281 {
1282  int16 num = PG_GETARG_INT16(0);
1283 
1284  PG_RETURN_FLOAT8((float8) num);
1285 }
signed short int16
Definition: c.h:416
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
double float8
Definition: c.h:553
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271

◆ i2tof()

Datum i2tof ( PG_FUNCTION_ARGS  )

Definition at line 1354 of file float.c.

References PG_GETARG_INT16, and PG_RETURN_FLOAT4.

1355 {
1356  int16 num = PG_GETARG_INT16(0);
1357 
1358  PG_RETURN_FLOAT4((float4) num);
1359 }
signed short int16
Definition: c.h:416
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
float float4
Definition: c.h:552
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271

◆ i4tod()

Datum i4tod ( PG_FUNCTION_ARGS  )

Definition at line 1268 of file float.c.

References PG_GETARG_INT32, and PG_RETURN_FLOAT8.

1269 {
1270  int32 num = PG_GETARG_INT32(0);
1271 
1272  PG_RETURN_FLOAT8((float8) num);
1273 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
signed int int32
Definition: c.h:417
double float8
Definition: c.h:553

◆ i4tof()

Datum i4tof ( PG_FUNCTION_ARGS  )

Definition at line 1342 of file float.c.

References PG_GETARG_INT32, and PG_RETURN_FLOAT4.

1343 {
1344  int32 num = PG_GETARG_INT32(0);
1345 
1346  PG_RETURN_FLOAT4((float4) num);
1347 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
signed int int32
Definition: c.h:417
float float4
Definition: c.h:552

◆ in_range_float4_float8()

Datum in_range_float4_float8 ( PG_FUNCTION_ARGS  )

Definition at line 1107 of file float.c.

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

1108 {
1110  float4 base = PG_GETARG_FLOAT4(1);
1111  float8 offset = PG_GETARG_FLOAT8(2);
1112  bool sub = PG_GETARG_BOOL(3);
1113  bool less = PG_GETARG_BOOL(4);
1114  float8 sum;
1115 
1116  /*
1117  * Reject negative or NaN offset. Negative is per spec, and NaN is
1118  * because appropriate semantics for that seem non-obvious.
1119  */
1120  if (isnan(offset) || offset < 0)
1121  ereport(ERROR,
1122  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1123  errmsg("invalid preceding or following size in window function")));
1124 
1125  /*
1126  * Deal with cases where val and/or base is NaN, following the rule that
1127  * NaN sorts after non-NaN (cf float8_cmp_internal). The offset cannot
1128  * affect the conclusion.
1129  */
1130  if (isnan(val))
1131  {
1132  if (isnan(base))
1133  PG_RETURN_BOOL(true); /* NAN = NAN */
1134  else
1135  PG_RETURN_BOOL(!less); /* NAN > non-NAN */
1136  }
1137  else if (isnan(base))
1138  {
1139  PG_RETURN_BOOL(less); /* non-NAN < NAN */
1140  }
1141 
1142  /*
1143  * Deal with cases where both base and offset are infinite, and computing
1144  * base +/- offset would produce NaN. This corresponds to a window frame
1145  * whose boundary infinitely precedes +inf or infinitely follows -inf,
1146  * which is not well-defined. For consistency with other cases involving
1147  * infinities, such as the fact that +inf infinitely follows +inf, we
1148  * choose to assume that +inf infinitely precedes +inf and -inf infinitely
1149  * follows -inf, and therefore that all finite and infinite values are in
1150  * such a window frame.
1151  *
1152  * offset is known positive, so we need only check the sign of base in
1153  * this test.
1154  */
1155  if (isinf(offset) && isinf(base) &&
1156  (sub ? base > 0 : base < 0))
1157  PG_RETURN_BOOL(true);
1158 
1159  /*
1160  * Otherwise it should be safe to compute base +/- offset. We trust the
1161  * FPU to cope if an input is +/-inf or the true sum would overflow, and
1162  * produce a suitably signed infinity, which will compare properly against
1163  * val whether or not that's infinity.
1164  */
1165  if (sub)
1166  sum = base - offset;
1167  else
1168  sum = base + offset;
1169 
1170  if (less)
1171  PG_RETURN_BOOL(val <= sum);
1172  else
1173  PG_RETURN_BOOL(val >= sum);
1174 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
int errcode(int sqlerrcode)
Definition: elog.c:691
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:552
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
long val
Definition: informix.c:664

◆ in_range_float8_float8()

Datum in_range_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 1031 of file float.c.

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

1032 {
1034  float8 base = PG_GETARG_FLOAT8(1);
1035  float8 offset = PG_GETARG_FLOAT8(2);
1036  bool sub = PG_GETARG_BOOL(3);
1037  bool less = PG_GETARG_BOOL(4);
1038  float8 sum;
1039 
1040  /*
1041  * Reject negative or NaN offset. Negative is per spec, and NaN is
1042  * because appropriate semantics for that seem non-obvious.
1043  */
1044  if (isnan(offset) || offset < 0)
1045  ereport(ERROR,
1046  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1047  errmsg("invalid preceding or following size in window function")));
1048 
1049  /*
1050  * Deal with cases where val and/or base is NaN, following the rule that
1051  * NaN sorts after non-NaN (cf float8_cmp_internal). The offset cannot
1052  * affect the conclusion.
1053  */
1054  if (isnan(val))
1055  {
1056  if (isnan(base))
1057  PG_RETURN_BOOL(true); /* NAN = NAN */
1058  else
1059  PG_RETURN_BOOL(!less); /* NAN > non-NAN */
1060  }
1061  else if (isnan(base))
1062  {
1063  PG_RETURN_BOOL(less); /* non-NAN < NAN */
1064  }
1065 
1066  /*
1067  * Deal with cases where both base and offset are infinite, and computing
1068  * base +/- offset would produce NaN. This corresponds to a window frame
1069  * whose boundary infinitely precedes +inf or infinitely follows -inf,
1070  * which is not well-defined. For consistency with other cases involving
1071  * infinities, such as the fact that +inf infinitely follows +inf, we
1072  * choose to assume that +inf infinitely precedes +inf and -inf infinitely
1073  * follows -inf, and therefore that all finite and infinite values are in
1074  * such a window frame.
1075  *
1076  * offset is known positive, so we need only check the sign of base in
1077  * this test.
1078  */
1079  if (isinf(offset) && isinf(base) &&
1080  (sub ? base > 0 : base < 0))
1081  PG_RETURN_BOOL(true);
1082 
1083  /*
1084  * Otherwise it should be safe to compute base +/- offset. We trust the
1085  * FPU to cope if an input is +/-inf or the true sum would overflow, and
1086  * produce a suitably signed infinity, which will compare properly against
1087  * val whether or not that's infinity.
1088  */
1089  if (sub)
1090  sum = base - offset;
1091  else
1092  sum = base + offset;
1093 
1094  if (less)
1095  PG_RETURN_BOOL(val <= sum);
1096  else
1097  PG_RETURN_BOOL(val >= sum);
1098 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
int errcode(int sqlerrcode)
Definition: elog.c:691
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
long val
Definition: informix.c:664

◆ init_degree_constants()

static void init_degree_constants ( void  )
static

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

2024 {
2027  asin_0_5 = asin(degree_c_one_half);
2028  acos_0_5 = acos(degree_c_one_half);
2029  atan_1_0 = atan(degree_c_one);
2032  degree_consts_set = true;
2033 }
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:2283
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:2303
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 2587 of file float.c.

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

2588 {
2589  float8 arg1 = PG_GETARG_FLOAT8(0);
2590 
2592 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define RADIANS_PER_DEGREE
Definition: float.h:26
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
double float8
Definition: c.h:553

◆ setseed()

Datum setseed ( PG_FUNCTION_ARGS  )

Definition at line 2790 of file