PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 "utils/array.h"
#include "utils/fmgrprotos.h"
#include "utils/sortsupport.h"
Include dependency graph for float.c:

Go to the source code of this file.

Macros

#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)
 
float8 float_overflow_error_ext (struct Node *escontext)
 
float8 float_underflow_error_ext (struct Node *escontext)
 
float8 float_zero_divide_error_ext (struct Node *escontext)
 
int is_infinite (double val)
 
Datum float4in (PG_FUNCTION_ARGS)
 
float4 float4in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
 
Datum float4out (PG_FUNCTION_ARGS)
 
Datum float4recv (PG_FUNCTION_ARGS)
 
Datum float4send (PG_FUNCTION_ARGS)
 
Datum float8in (PG_FUNCTION_ARGS)
 
float8 float8in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
 
Datum float8out (PG_FUNCTION_ARGS)
 
charfloat8out_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 derf (PG_FUNCTION_ARGS)
 
Datum derfc (PG_FUNCTION_ARGS)
 
Datum dgamma (PG_FUNCTION_ARGS)
 
Datum dlgamma (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
 

Macro Definition Documentation

◆ INIT_DEGREE_CONSTANTS

#define INIT_DEGREE_CONSTANTS ( )
Value:
do { \
} while(0)
static bool degree_consts_set
Definition float.c:60
static int fb(int x)

Definition at line 2072 of file float.c.

2073 { \
2076} while(0)

Function Documentation

◆ acosd_q1()

static double acosd_q1 ( double  x)
static

Definition at line 2122 of file float.c.

2123{
2124 /*
2125 * Stitch together inverse sine and cosine functions for the ranges [0,
2126 * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
2127 * exactly 60 for x=0.5, so the result is a continuous monotonic function
2128 * over the full range.
2129 */
2130 if (x <= 0.5)
2131 {
2132 volatile float8 asin_x = asin(x);
2133
2134 return 90.0 - (asin_x / asin_0_5) * 30.0;
2135 }
2136 else
2137 {
2138 volatile float8 acos_x = acos(x);
2139
2140 return (acos_x / acos_0_5) * 60.0;
2141 }
2142}
double float8
Definition c.h:714
static float8 acos_0_5
Definition float.c:64
static float8 asin_0_5
Definition float.c:63
int x
Definition isn.c:75

References acos_0_5, asin_0_5, fb(), and x.

Referenced by dacosd().

◆ asind_q1()

static double asind_q1 ( double  x)
static

Definition at line 2089 of file float.c.

2090{
2091 /*
2092 * Stitch together inverse sine and cosine functions for the ranges [0,
2093 * 0.5] and (0.5, 1]. Each expression below is guaranteed to return
2094 * exactly 30 for x=0.5, so the result is a continuous monotonic function
2095 * over the full range.
2096 */
2097 if (x <= 0.5)
2098 {
2099 volatile float8 asin_x = asin(x);
2100
2101 return (asin_x / asin_0_5) * 30.0;
2102 }
2103 else
2104 {
2105 volatile float8 acos_x = acos(x);
2106
2107 return 90.0 - (acos_x / acos_0_5) * 60.0;
2108 }
2109}

References acos_0_5, asin_0_5, fb(), and x.

Referenced by dacosd(), and dasind().

◆ btfloat48cmp()

Datum btfloat48cmp ( PG_FUNCTION_ARGS  )

Definition at line 1042 of file float.c.

1043{
1046
1047 /* widen float4 to float8 and then compare */
1049}
float float4
Definition c.h:713
int float8_cmp_internal(float8 a, float8 b)
Definition float.c:951
#define PG_GETARG_FLOAT8(n)
Definition fmgr.h:283
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_GETARG_FLOAT4(n)
Definition fmgr.h:282

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

◆ btfloat4cmp()

Datum btfloat4cmp ( PG_FUNCTION_ARGS  )

Definition at line 921 of file float.c.

922{
925
927}
int float4_cmp_internal(float4 a, float4 b)
Definition float.c:857

References fb(), float4_cmp_internal(), PG_GETARG_FLOAT4, and PG_RETURN_INT32.

◆ btfloat4fastcmp()

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

Definition at line 930 of file float.c.

931{
934
936}
int y
Definition isn.c:76
static float4 DatumGetFloat4(Datum X)
Definition postgres.h:451

References DatumGetFloat4(), fb(), float4_cmp_internal(), x, and y.

Referenced by btfloat4sortsupport().

◆ btfloat4sortsupport()

Datum btfloat4sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 939 of file float.c.

940{
942
945}
struct SortSupportData * SortSupport
Definition execnodes.h:61
static int btfloat4fastcmp(Datum x, Datum y, SortSupport ssup)
Definition float.c:930
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
int(* comparator)(Datum x, Datum y, SortSupport ssup)

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

◆ btfloat84cmp()

Datum btfloat84cmp ( PG_FUNCTION_ARGS  )

Definition at line 1052 of file float.c.

1053{
1056
1057 /* widen float4 to float8 and then compare */
1059}

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

◆ btfloat8cmp()

Datum btfloat8cmp ( PG_FUNCTION_ARGS  )

Definition at line 1015 of file float.c.

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

◆ btfloat8fastcmp()

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

Definition at line 1024 of file float.c.

1025{
1028
1029 return float8_cmp_internal(arg1, arg2);
1030}
static float8 DatumGetFloat8(Datum X)
Definition postgres.h:485

References DatumGetFloat8(), fb(), float8_cmp_internal(), x, and y.

Referenced by btfloat8sortsupport().

◆ btfloat8sortsupport()

Datum btfloat8sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 1033 of file float.c.

1034{
1036
1039}
static int btfloat8fastcmp(Datum x, Datum y, SortSupport ssup)
Definition float.c:1024

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

◆ check_float8_array()

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

Definition at line 2974 of file float.c.

2975{
2976 /*
2977 * We expect the input to be an N-element float array; verify that. We
2978 * don't need to use deconstruct_array() since the array data is just
2979 * going to look like a C array of N float8 values.
2980 */
2981 if (ARR_NDIM(transarray) != 1 ||
2982 ARR_DIMS(transarray)[0] != n ||
2985 elog(ERROR, "%s: expected %d-element float8 array", caller, n);
2986 return (float8 *) ARR_DATA_PTR(transarray);
2987}
#define ARR_NDIM(a)
Definition array.h:290
#define ARR_DATA_PTR(a)
Definition array.h:322
#define ARR_ELEMTYPE(a)
Definition array.h:292
#define ARR_DIMS(a)
Definition array.h:294
#define ARR_HASNULL(a)
Definition array.h:291
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228

References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, elog, ERROR, and fb().

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

◆ cosd_0_to_60()

static double cosd_0_to_60 ( double  x)
static

Definition at line 2307 of file float.c.

2308{
2309 volatile float8 one_minus_cos_x = 1.0 - cos(x * RADIANS_PER_DEGREE);
2310
2311 return 1.0 - (one_minus_cos_x / one_minus_cos_60) / 2.0;
2312}
static float8 one_minus_cos_60
Definition float.c:62
#define RADIANS_PER_DEGREE
Definition float.h:26

References fb(), one_minus_cos_60, RADIANS_PER_DEGREE, and x.

Referenced by cosd_q1(), and sind_q1().

◆ cosd_q1()

static double cosd_q1 ( double  x)
static

Definition at line 2340 of file float.c.

2341{
2342 /*
2343 * Stitch together the sine and cosine functions for the ranges [0, 60]
2344 * and (60, 90]. These guarantee to return exact answers at their
2345 * endpoints, so the overall result is a continuous monotonic function
2346 * that gives exact results when x = 0, 60 and 90 degrees.
2347 */
2348 if (x <= 60.0)
2349 return cosd_0_to_60(x);
2350 else
2351 return sind_0_to_30(90.0 - x);
2352}
static double sind_0_to_30(double x)
Definition float.c:2293
static double cosd_0_to_60(double x)
Definition float.c:2307

References cosd_0_to_60(), sind_0_to_30(), and x.

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

◆ dacos()

Datum dacos ( PG_FUNCTION_ARGS  )

Definition at line 1796 of file float.c.

1797{
1799 float8 result;
1800
1801 /* Per the POSIX spec, return NaN if the input is NaN */
1802 if (isnan(arg1))
1804
1805 /*
1806 * The principal branch of the inverse cosine function maps values in the
1807 * range [-1, 1] to values in the range [0, Pi], so we should reject any
1808 * inputs outside that range and the result will always be finite.
1809 */
1810 if (arg1 < -1.0 || arg1 > 1.0)
1811 ereport(ERROR,
1813 errmsg("input is out of range")));
1814
1815 result = acos(arg1);
1816 if (unlikely(isinf(result)))
1818
1820}
#define unlikely(x)
Definition c.h:438
uint32 result
int errcode(int sqlerrcode)
Definition elog.c:874
#define ereport(elevel,...)
Definition elog.h:152
pg_noinline void float_overflow_error(void)
Definition float.c:103
static float8 get_float8_nan(void)
Definition float.h:87
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369
static char * errmsg

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

◆ dacosd()

Datum dacosd ( PG_FUNCTION_ARGS  )

Definition at line 2149 of file float.c.

2150{
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 cosine function maps values in the
2162 * range [-1, 1] to values in the range [0, 180], 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,
2168 errmsg("input is out of range")));
2169
2170 if (arg1 >= 0.0)
2171 result = acosd_q1(arg1);
2172 else
2173 result = 90.0 + asind_q1(-arg1);
2174
2175 if (unlikely(isinf(result)))
2177
2179}
static double acosd_q1(double x)
Definition float.c:2122
static double asind_q1(double x)
Definition float.c:2089
#define INIT_DEGREE_CONSTANTS()
Definition float.c:2072

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

◆ dacosh()

Datum dacosh ( PG_FUNCTION_ARGS  )

Definition at line 2730 of file float.c.

2731{
2733 float8 result;
2734
2735 /*
2736 * acosh is only defined for inputs >= 1.0. By checking this ourselves,
2737 * we need not worry about checking for an EDOM error, which is a good
2738 * thing because some implementations will report that for NaN. Otherwise,
2739 * no error is possible.
2740 */
2741 if (arg1 < 1.0)
2742 ereport(ERROR,
2744 errmsg("input is out of range")));
2745
2746 result = acosh(arg1);
2747
2749}

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

◆ dasin()

Datum dasin ( PG_FUNCTION_ARGS  )

Definition at line 1827 of file float.c.

1828{
1830 float8 result;
1831
1832 /* Per the POSIX spec, return NaN if the input is NaN */
1833 if (isnan(arg1))
1835
1836 /*
1837 * The principal branch of the inverse sine function maps values in the
1838 * range [-1, 1] to values in the range [-Pi/2, Pi/2], so we should reject
1839 * any inputs outside that range and the result will always be finite.
1840 */
1841 if (arg1 < -1.0 || arg1 > 1.0)
1842 ereport(ERROR,
1844 errmsg("input is out of range")));
1845
1846 result = asin(arg1);
1847 if (unlikely(isinf(result)))
1849
1851}

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

◆ dasind()

Datum dasind ( PG_FUNCTION_ARGS  )

Definition at line 2186 of file float.c.

2187{
2189 float8 result;
2190
2191 /* Per the POSIX spec, return NaN if the input is NaN */
2192 if (isnan(arg1))
2194
2196
2197 /*
2198 * The principal branch of the inverse sine function maps values in the
2199 * range [-1, 1] to values in the range [-90, 90], so we should reject any
2200 * inputs outside that range and the result will always be finite.
2201 */
2202 if (arg1 < -1.0 || arg1 > 1.0)
2203 ereport(ERROR,
2205 errmsg("input is out of range")));
2206
2207 if (arg1 >= 0.0)
2208 result = asind_q1(arg1);
2209 else
2210 result = -asind_q1(-arg1);
2211
2212 if (unlikely(isinf(result)))
2214
2216}

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

◆ dasinh()

Datum dasinh ( PG_FUNCTION_ARGS  )

Definition at line 2713 of file float.c.

2714{
2716 float8 result;
2717
2718 /*
2719 * For asinh, we don't need an errno check because it never overflows.
2720 */
2721 result = asinh(arg1);
2722
2724}

References fb(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ datan()

Datum datan ( PG_FUNCTION_ARGS  )

Definition at line 1858 of file float.c.

1859{
1861 float8 result;
1862
1863 /* Per the POSIX spec, return NaN if the input is NaN */
1864 if (isnan(arg1))
1866
1867 /*
1868 * The principal branch of the inverse tangent function maps all inputs to
1869 * values in the range [-Pi/2, Pi/2], so the result should always be
1870 * finite, even if the input is infinite.
1871 */
1872 result = atan(arg1);
1873 if (unlikely(isinf(result)))
1875
1877}

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

◆ datan2()

Datum datan2 ( PG_FUNCTION_ARGS  )

Definition at line 1884 of file float.c.

1885{
1888 float8 result;
1889
1890 /* Per the POSIX spec, return NaN if either input is NaN */
1891 if (isnan(arg1) || isnan(arg2))
1893
1894 /*
1895 * atan2 maps all inputs to values in the range [-Pi, Pi], so the result
1896 * should always be finite, even if the inputs are infinite.
1897 */
1898 result = atan2(arg1, arg2);
1899 if (unlikely(isinf(result)))
1901
1903}

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

◆ datan2d()

Datum datan2d ( PG_FUNCTION_ARGS  )

Definition at line 2255 of file float.c.

2256{
2259 float8 result;
2260 volatile float8 atan2_arg1_arg2;
2261
2262 /* Per the POSIX spec, return NaN if either input is NaN */
2263 if (isnan(arg1) || isnan(arg2))
2265
2267
2268 /*
2269 * atan2d maps all inputs to values in the range [-180, 180], so the
2270 * result should always be finite, even if the inputs are infinite.
2271 *
2272 * Note: this coding assumes that atan(1.0) is a suitable scaling constant
2273 * to get an exact result from atan2(). This might well fail on us at
2274 * some point, requiring us to decide exactly what inputs we think we're
2275 * going to guarantee an exact result for.
2276 */
2278 result = (atan2_arg1_arg2 / atan_1_0) * 45.0;
2279
2280 if (unlikely(isinf(result)))
2282
2284}
static float8 atan_1_0
Definition float.c:65

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

◆ datand()

Datum datand ( PG_FUNCTION_ARGS  )

Definition at line 2223 of file float.c.

2224{
2226 float8 result;
2227 volatile float8 atan_arg1;
2228
2229 /* Per the POSIX spec, return NaN if the input is NaN */
2230 if (isnan(arg1))
2232
2234
2235 /*
2236 * The principal branch of the inverse tangent function maps all inputs to
2237 * values in the range [-90, 90], so the result should always be finite,
2238 * even if the input is infinite. Additionally, we take care to ensure
2239 * than when arg1 is 1, the result is exactly 45.
2240 */
2241 atan_arg1 = atan(arg1);
2242 result = (atan_arg1 / atan_1_0) * 45.0;
2243
2244 if (unlikely(isinf(result)))
2246
2248}

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

◆ datanh()

Datum datanh ( PG_FUNCTION_ARGS  )

Definition at line 2755 of file float.c.

2756{
2758 float8 result;
2759
2760 /*
2761 * atanh is only defined for inputs between -1 and 1. By checking this
2762 * ourselves, we need not worry about checking for an EDOM error, which is
2763 * a good thing because some implementations will report that for NaN.
2764 */
2765 if (arg1 < -1.0 || arg1 > 1.0)
2766 ereport(ERROR,
2768 errmsg("input is out of range")));
2769
2770 /*
2771 * Also handle the infinity cases ourselves; this is helpful because old
2772 * glibc versions may produce the wrong errno for this. All other inputs
2773 * cannot produce an error.
2774 */
2775 if (arg1 == -1.0)
2777 else if (arg1 == 1.0)
2779 else
2780 result = atanh(arg1);
2781
2783}
static float8 get_float8_infinity(void)
Definition float.h:68

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

◆ dcbrt()

Datum dcbrt ( PG_FUNCTION_ARGS  )

Definition at line 1511 of file float.c.

1512{
1514 float8 result;
1515
1516 result = cbrt(arg1);
1517 if (unlikely(isinf(result)) && !isinf(arg1))
1519 if (unlikely(result == 0.0) && arg1 != 0.0)
1521
1523}
pg_noinline void float_underflow_error(void)
Definition float.c:111

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

◆ dceil()

Datum dceil ( PG_FUNCTION_ARGS  )

Definition at line 1421 of file float.c.

1422{
1424
1426}

References fb(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

◆ dcos()

Datum dcos ( PG_FUNCTION_ARGS  )

Definition at line 1910 of file float.c.

1911{
1913 float8 result;
1914
1915 /* Per the POSIX spec, return NaN if the input is NaN */
1916 if (isnan(arg1))
1918
1919 /*
1920 * cos() is periodic and so theoretically can work for all finite inputs,
1921 * but some implementations may choose to throw error if the input is so
1922 * large that there are no significant digits in the result. So we should
1923 * check for errors. POSIX allows an error to be reported either via
1924 * errno or via fetestexcept(), but currently we only support checking
1925 * errno. (fetestexcept() is rumored to report underflow unreasonably
1926 * early on some platforms, so it's not clear that believing it would be a
1927 * net improvement anyway.)
1928 *
1929 * For infinite inputs, POSIX specifies that the trigonometric functions
1930 * should return a domain error; but we won't notice that unless the
1931 * platform reports via errno, so also explicitly test for infinite
1932 * inputs.
1933 */
1934 errno = 0;
1935 result = cos(arg1);
1936 if (errno != 0 || isinf(arg1))
1937 ereport(ERROR,
1939 errmsg("input is out of range")));
1940 if (unlikely(isinf(result)))
1942
1944}

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

◆ dcosd()

Datum dcosd ( PG_FUNCTION_ARGS  )

Definition at line 2359 of file float.c.

2360{
2362 float8 result;
2363 int sign = 1;
2364
2365 /*
2366 * Per the POSIX spec, return NaN if the input is NaN and throw an error
2367 * if the input is infinite.
2368 */
2369 if (isnan(arg1))
2371
2372 if (isinf(arg1))
2373 ereport(ERROR,
2375 errmsg("input is out of range")));
2376
2378
2379 /* Reduce the range of the input to [0,90] degrees */
2380 arg1 = fmod(arg1, 360.0);
2381
2382 if (arg1 < 0.0)
2383 {
2384 /* cosd(-x) = cosd(x) */
2385 arg1 = -arg1;
2386 }
2387
2388 if (arg1 > 180.0)
2389 {
2390 /* cosd(360-x) = cosd(x) */
2391 arg1 = 360.0 - arg1;
2392 }
2393
2394 if (arg1 > 90.0)
2395 {
2396 /* cosd(180-x) = -cosd(x) */
2397 arg1 = 180.0 - arg1;
2398 sign = -sign;
2399 }
2400
2401 result = sign * cosd_q1(arg1);
2402
2403 if (unlikely(isinf(result)))
2405
2407}
static double cosd_q1(double x)
Definition float.c:2340
char sign
Definition informix.c:693

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

◆ dcosh()

Datum dcosh ( PG_FUNCTION_ARGS  )

Definition at line 2668 of file float.c.

2669{
2671 float8 result;
2672
2673 errno = 0;
2674 result = cosh(arg1);
2675
2676 /*
2677 * if an ERANGE error occurs, it means there is an overflow. As cosh is
2678 * always positive, it always means the result is positive infinity.
2679 */
2680 if (errno == ERANGE)
2682
2683 if (unlikely(result == 0.0))
2685
2687}

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

◆ dcot()

Datum dcot ( PG_FUNCTION_ARGS  )

Definition at line 1951 of file float.c.

1952{
1954 float8 result;
1955
1956 /* Per the POSIX spec, return NaN if the input is NaN */
1957 if (isnan(arg1))
1959
1960 /* Be sure to throw an error if the input is infinite --- see dcos() */
1961 errno = 0;
1962 result = tan(arg1);
1963 if (errno != 0 || isinf(arg1))
1964 ereport(ERROR,
1966 errmsg("input is out of range")));
1967
1968 result = 1.0 / result;
1969 /* Not checking for overflow because cot(0) == Inf */
1970
1972}

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

◆ dcotd()

Datum dcotd ( PG_FUNCTION_ARGS  )

Definition at line 2414 of file float.c.

2415{
2417 float8 result;
2418 volatile float8 cot_arg1;
2419 int sign = 1;
2420
2421 /*
2422 * Per the POSIX spec, return NaN if the input is NaN and throw an error
2423 * if the input is infinite.
2424 */
2425 if (isnan(arg1))
2427
2428 if (isinf(arg1))
2429 ereport(ERROR,
2431 errmsg("input is out of range")));
2432
2434
2435 /* Reduce the range of the input to [0,90] degrees */
2436 arg1 = fmod(arg1, 360.0);
2437
2438 if (arg1 < 0.0)
2439 {
2440 /* cotd(-x) = -cotd(x) */
2441 arg1 = -arg1;
2442 sign = -sign;
2443 }
2444
2445 if (arg1 > 180.0)
2446 {
2447 /* cotd(360-x) = -cotd(x) */
2448 arg1 = 360.0 - arg1;
2449 sign = -sign;
2450 }
2451
2452 if (arg1 > 90.0)
2453 {
2454 /* cotd(180-x) = -cotd(x) */
2455 arg1 = 180.0 - arg1;
2456 sign = -sign;
2457 }
2458
2460 result = sign * (cot_arg1 / cot_45);
2461
2462 /*
2463 * On some machines we get cotd(270) = minus zero, but this isn't always
2464 * true. For portability, and because the user constituency for this
2465 * function probably doesn't want minus zero, force it to plain zero.
2466 */
2467 if (result == 0.0)
2468 result = 0.0;
2469
2470 /* Not checking for overflow because cotd(0) == Inf */
2471
2473}
static float8 cot_45
Definition float.c:67
static double sind_q1(double x)
Definition float.c:2320

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

◆ degrees()

Datum degrees ( PG_FUNCTION_ARGS  )

Definition at line 2602 of file float.c.

2603{
2605
2607}
static float8 float8_div(const float8 val1, const float8 val2)
Definition float.h:230

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

Referenced by degtorad().

◆ derf()

Datum derf ( PG_FUNCTION_ARGS  )

Definition at line 2793 of file float.c.

2794{
2796 float8 result;
2797
2798 /*
2799 * For erf, we don't need an errno check because it never overflows.
2800 */
2801 result = erf(arg1);
2802
2803 if (unlikely(isinf(result)))
2805
2807}

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

◆ derfc()

Datum derfc ( PG_FUNCTION_ARGS  )

Definition at line 2813 of file float.c.

2814{
2816 float8 result;
2817
2818 /*
2819 * For erfc, we don't need an errno check because it never overflows.
2820 */
2821 result = erfc(arg1);
2822
2823 if (unlikely(isinf(result)))
2825
2827}

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

◆ dexp()

Datum dexp ( PG_FUNCTION_ARGS  )

Definition at line 1685 of file float.c.

1686{
1688 float8 result;
1689
1690 /*
1691 * Handle NaN and Inf cases explicitly. This avoids needing to assume
1692 * that the platform's exp() conforms to POSIX for these cases, and it
1693 * removes some edge cases for the overflow checks below.
1694 */
1695 if (isnan(arg1))
1696 result = arg1;
1697 else if (isinf(arg1))
1698 {
1699 /* Per POSIX, exp(-Inf) is 0 */
1700 result = (arg1 > 0.0) ? arg1 : 0;
1701 }
1702 else
1703 {
1704 /*
1705 * On some platforms, exp() will not set errno but just return Inf or
1706 * zero to report overflow/underflow; therefore, test both cases.
1707 */
1708 errno = 0;
1709 result = exp(arg1);
1710 if (unlikely(errno == ERANGE))
1711 {
1712 if (result != 0.0)
1714 else
1716 }
1717 else if (unlikely(isinf(result)))
1719 else if (unlikely(result == 0.0))
1721 }
1722
1724}

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

◆ dfloor()

Datum dfloor ( PG_FUNCTION_ARGS  )

Definition at line 1433 of file float.c.

1434{
1436
1438}

References fb(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

◆ dgamma()

Datum dgamma ( PG_FUNCTION_ARGS  )

Definition at line 2837 of file float.c.

2838{
2840 float8 result;
2841
2842 /*
2843 * Handle NaN and Inf cases explicitly. This simplifies the overflow
2844 * checks on platforms that do not set errno.
2845 */
2846 if (isnan(arg1))
2847 result = arg1;
2848 else if (isinf(arg1))
2849 {
2850 /* Per POSIX, an input of -Inf causes a domain error */
2851 if (arg1 < 0)
2852 {
2854 result = get_float8_nan(); /* keep compiler quiet */
2855 }
2856 else
2857 result = arg1;
2858 }
2859 else
2860 {
2861 /*
2862 * Note: the POSIX/C99 gamma function is called "tgamma", not "gamma".
2863 *
2864 * On some platforms, tgamma() will not set errno but just return Inf,
2865 * NaN, or zero to report overflow/underflow; therefore, test those
2866 * cases explicitly (note that, like the exponential function, the
2867 * gamma function has no zeros).
2868 */
2869 errno = 0;
2870 result = tgamma(arg1);
2871
2872 if (errno != 0 || isinf(result) || isnan(result))
2873 {
2874 if (result != 0.0)
2876 else
2878 }
2879 else if (result == 0.0)
2881 }
2882
2884}

References fb(), float_overflow_error(), float_underflow_error(), get_float8_nan(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ dlgamma()

Datum dlgamma ( PG_FUNCTION_ARGS  )

Definition at line 2891 of file float.c.

2892{
2894 float8 result;
2895
2896 /* On some versions of AIX, lgamma(NaN) fails with ERANGE */
2897#if defined(_AIX)
2898 if (isnan(arg1))
2900#endif
2901
2902 /*
2903 * Note: lgamma may not be thread-safe because it may write to a global
2904 * variable signgam, which may not be thread-local. However, this doesn't
2905 * matter to us, since we don't use signgam.
2906 */
2907 errno = 0;
2908 result = lgamma(arg1);
2909
2910 /*
2911 * If an ERANGE error occurs, it means there was an overflow or a pole
2912 * error (which happens for zero and negative integer inputs).
2913 *
2914 * On some platforms, lgamma() will not set errno but just return infinity
2915 * to report overflow, but it should never underflow.
2916 */
2917 if (errno == ERANGE || (isinf(result) && !isinf(arg1)))
2919
2921}

References fb(), float_overflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ dlog1()

Datum dlog1 ( PG_FUNCTION_ARGS  )

Definition at line 1731 of file float.c.

1732{
1734 float8 result;
1735
1736 /*
1737 * Emit particular SQLSTATE error codes for ln(). This is required by the
1738 * SQL standard.
1739 */
1740 if (arg1 == 0.0)
1741 ereport(ERROR,
1743 errmsg("cannot take logarithm of zero")));
1744 if (arg1 < 0)
1745 ereport(ERROR,
1747 errmsg("cannot take logarithm of a negative number")));
1748
1749 result = log(arg1);
1750 if (unlikely(isinf(result)) && !isinf(arg1))
1752 if (unlikely(result == 0.0) && arg1 != 1.0)
1754
1756}

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

◆ dlog10()

Datum dlog10 ( PG_FUNCTION_ARGS  )

Definition at line 1763 of file float.c.

1764{
1766 float8 result;
1767
1768 /*
1769 * Emit particular SQLSTATE error codes for log(). The SQL spec doesn't
1770 * define log(), but it does define ln(), so it makes sense to emit the
1771 * same error code for an analogous error condition.
1772 */
1773 if (arg1 == 0.0)
1774 ereport(ERROR,
1776 errmsg("cannot take logarithm of zero")));
1777 if (arg1 < 0)
1778 ereport(ERROR,
1780 errmsg("cannot take logarithm of a negative number")));
1781
1782 result = log10(arg1);
1783 if (unlikely(isinf(result)) && !isinf(arg1))
1785 if (unlikely(result == 0.0) && arg1 != 1.0)
1787
1789}

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

◆ dpi()

Definition at line 2614 of file float.c.

2615{
2617}
#define M_PI

References M_PI, and PG_RETURN_FLOAT8.

◆ dpow()

Datum dpow ( PG_FUNCTION_ARGS  )

Definition at line 1530 of file float.c.

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

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

◆ dround()

Datum dround ( PG_FUNCTION_ARGS  )

Definition at line 1409 of file float.c.

1410{
1412
1414}

References fb(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

◆ dsign()

Datum dsign ( PG_FUNCTION_ARGS  )

Definition at line 1446 of file float.c.

1447{
1449 float8 result;
1450
1451 if (arg1 > 0)
1452 result = 1.0;
1453 else if (arg1 < 0)
1454 result = -1.0;
1455 else
1456 result = 0.0;
1457
1459}

References fb(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ dsin()

Datum dsin ( PG_FUNCTION_ARGS  )

Definition at line 1979 of file float.c.

1980{
1982 float8 result;
1983
1984 /* Per the POSIX spec, return NaN if the input is NaN */
1985 if (isnan(arg1))
1987
1988 /* Be sure to throw an error if the input is infinite --- see dcos() */
1989 errno = 0;
1990 result = sin(arg1);
1991 if (errno != 0 || isinf(arg1))
1992 ereport(ERROR,
1994 errmsg("input is out of range")));
1995 if (unlikely(isinf(result)))
1997
1999}

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

◆ dsind()

Datum dsind ( PG_FUNCTION_ARGS  )

Definition at line 2480 of file float.c.

2481{
2483 float8 result;
2484 int sign = 1;
2485
2486 /*
2487 * Per the POSIX spec, return NaN if the input is NaN and throw an error
2488 * if the input is infinite.
2489 */
2490 if (isnan(arg1))
2492
2493 if (isinf(arg1))
2494 ereport(ERROR,
2496 errmsg("input is out of range")));
2497
2499
2500 /* Reduce the range of the input to [0,90] degrees */
2501 arg1 = fmod(arg1, 360.0);
2502
2503 if (arg1 < 0.0)
2504 {
2505 /* sind(-x) = -sind(x) */
2506 arg1 = -arg1;
2507 sign = -sign;
2508 }
2509
2510 if (arg1 > 180.0)
2511 {
2512 /* sind(360-x) = -sind(x) */
2513 arg1 = 360.0 - arg1;
2514 sign = -sign;
2515 }
2516
2517 if (arg1 > 90.0)
2518 {
2519 /* sind(180-x) = sind(x) */
2520 arg1 = 180.0 - arg1;
2521 }
2522
2523 result = sign * sind_q1(arg1);
2524
2525 if (unlikely(isinf(result)))
2527
2529}

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

◆ dsinh()

Datum dsinh ( PG_FUNCTION_ARGS  )

Definition at line 2639 of file float.c.

2640{
2642 float8 result;
2643
2644 errno = 0;
2645 result = sinh(arg1);
2646
2647 /*
2648 * if an ERANGE error occurs, it means there is an overflow. For sinh,
2649 * the result should be either -infinity or infinity, depending on the
2650 * sign of arg1.
2651 */
2652 if (errno == ERANGE)
2653 {
2654 if (arg1 < 0)
2656 else
2658 }
2659
2661}

References fb(), get_float8_infinity(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ dsqrt()

Datum dsqrt ( PG_FUNCTION_ARGS  )

Definition at line 1487 of file float.c.

1488{
1490 float8 result;
1491
1492 if (arg1 < 0)
1493 ereport(ERROR,
1495 errmsg("cannot take square root of a negative number")));
1496
1497 result = sqrt(arg1);
1498 if (unlikely(isinf(result)) && !isinf(arg1))
1500 if (unlikely(result == 0.0) && arg1 != 0.0)
1502
1504}

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

◆ dtan()

Datum dtan ( PG_FUNCTION_ARGS  )

Definition at line 2006 of file float.c.

2007{
2009 float8 result;
2010
2011 /* Per the POSIX spec, return NaN if the input is NaN */
2012 if (isnan(arg1))
2014
2015 /* Be sure to throw an error if the input is infinite --- see dcos() */
2016 errno = 0;
2017 result = tan(arg1);
2018 if (errno != 0 || isinf(arg1))
2019 ereport(ERROR,
2021 errmsg("input is out of range")));
2022 /* Not checking for overflow because tan(pi/2) == Inf */
2023
2025}

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

◆ dtand()

Datum dtand ( PG_FUNCTION_ARGS  )

Definition at line 2536 of file float.c.

2537{
2539 float8 result;
2540 volatile float8 tan_arg1;
2541 int sign = 1;
2542
2543 /*
2544 * Per the POSIX spec, return NaN if the input is NaN and throw an error
2545 * if the input is infinite.
2546 */
2547 if (isnan(arg1))
2549
2550 if (isinf(arg1))
2551 ereport(ERROR,
2553 errmsg("input is out of range")));
2554
2556
2557 /* Reduce the range of the input to [0,90] degrees */
2558 arg1 = fmod(arg1, 360.0);
2559
2560 if (arg1 < 0.0)
2561 {
2562 /* tand(-x) = -tand(x) */
2563 arg1 = -arg1;
2564 sign = -sign;
2565 }
2566
2567 if (arg1 > 180.0)
2568 {
2569 /* tand(360-x) = -tand(x) */
2570 arg1 = 360.0 - arg1;
2571 sign = -sign;
2572 }
2573
2574 if (arg1 > 90.0)
2575 {
2576 /* tand(180-x) = -tand(x) */
2577 arg1 = 180.0 - arg1;
2578 sign = -sign;
2579 }
2580
2582 result = sign * (tan_arg1 / tan_45);
2583
2584 /*
2585 * On some machines we get tand(180) = minus zero, but this isn't always
2586 * true. For portability, and because the user constituency for this
2587 * function probably doesn't want minus zero, force it to plain zero.
2588 */
2589 if (result == 0.0)
2590 result = 0.0;
2591
2592 /* Not checking for overflow because tand(90) == Inf */
2593
2595}
static float8 tan_45
Definition float.c:66

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

◆ dtanh()

Datum dtanh ( PG_FUNCTION_ARGS  )

Definition at line 2693 of file float.c.

2694{
2696 float8 result;
2697
2698 /*
2699 * For tanh, we don't need an errno check because it never overflows.
2700 */
2701 result = tanh(arg1);
2702
2703 if (unlikely(isinf(result)))
2705
2707}

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

◆ dtof()

Datum dtof ( PG_FUNCTION_ARGS  )

Definition at line 1236 of file float.c.

1237{
1238 float8 num = PG_GETARG_FLOAT8(0);
1239 float4 result;
1240
1241 result = (float4) num;
1242 if (unlikely(isinf(result)) && !isinf(num))
1243 float_overflow_error_ext(fcinfo->context);
1244 if (unlikely(result == 0.0f) && num != 0.0)
1245 float_underflow_error_ext(fcinfo->context);
1246
1248}
float8 float_underflow_error_ext(struct Node *escontext)
Definition float.c:135
float8 float_overflow_error_ext(struct Node *escontext)
Definition float.c:127
#define PG_RETURN_FLOAT4(x)
Definition fmgr.h:368

References fb(), float_overflow_error_ext(), float_underflow_error_ext(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT4, result, and unlikely.

◆ dtoi2()

Datum dtoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1280 of file float.c.

1281{
1282 float8 num = PG_GETARG_FLOAT8(0);
1283
1284 /*
1285 * Get rid of any fractional part in the input. This is so we don't fail
1286 * on just-out-of-range values that would round into range. Note
1287 * assumption that rint() will pass through a NaN or Inf unchanged.
1288 */
1289 num = rint(num);
1290
1291 /* Range check */
1292 if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT16(num)))
1293 ereturn(fcinfo->context, (Datum) 0,
1295 errmsg("smallint out of range")));
1296
1297 PG_RETURN_INT16((int16) num);
1298}
int16_t int16
Definition c.h:619
#define FLOAT8_FITS_IN_INT16(num)
Definition c.h:1175
#define ereturn(context, dummy_value,...)
Definition elog.h:280
#define PG_RETURN_INT16(x)
Definition fmgr.h:357
uint64_t Datum
Definition postgres.h:70

References ereturn, errcode(), errmsg, fb(), FLOAT8_FITS_IN_INT16, PG_GETARG_FLOAT8, PG_RETURN_INT16, and unlikely.

◆ dtoi4()

Datum dtoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1255 of file float.c.

1256{
1257 float8 num = PG_GETARG_FLOAT8(0);
1258
1259 /*
1260 * Get rid of any fractional part in the input. This is so we don't fail
1261 * on just-out-of-range values that would round into range. Note
1262 * assumption that rint() will pass through a NaN or Inf unchanged.
1263 */
1264 num = rint(num);
1265
1266 /* Range check */
1267 if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT32(num)))
1268 ereturn(fcinfo->context, (Datum) 0,
1270 errmsg("integer out of range")));
1271
1272 PG_RETURN_INT32((int32) num);
1273}
#define FLOAT8_FITS_IN_INT32(num)
Definition c.h:1177
int32_t int32
Definition c.h:620

References ereturn, errcode(), errmsg, fb(), FLOAT8_FITS_IN_INT32, PG_GETARG_FLOAT8, PG_RETURN_INT32, and unlikely.

◆ dtrunc()

Datum dtrunc ( PG_FUNCTION_ARGS  )

Definition at line 1469 of file float.c.

1470{
1472 float8 result;
1473
1474 if (arg1 >= 0)
1475 result = floor(arg1);
1476 else
1477 result = -floor(-arg1);
1478
1480}

References fb(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ float48div()

Datum float48div ( PG_FUNCTION_ARGS  )

Definition at line 4043 of file float.c.

4044{
4047
4049}

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

◆ float48eq()

Datum float48eq ( PG_FUNCTION_ARGS  )

Definition at line 4103 of file float.c.

4104{
4107
4109}
static bool float8_eq(const float8 val1, const float8 val2)
Definition float.h:250
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360

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

◆ float48ge()

Datum float48ge ( PG_FUNCTION_ARGS  )

Definition at line 4148 of file float.c.

4149{
4152
4154}
static bool float8_ge(const float8 val1, const float8 val2)
Definition float.h:310

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

◆ float48gt()

Datum float48gt ( PG_FUNCTION_ARGS  )

Definition at line 4139 of file float.c.

4140{
4143
4145}
static bool float8_gt(const float8 val1, const float8 val2)
Definition float.h:298

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

◆ float48le()

Datum float48le ( PG_FUNCTION_ARGS  )

Definition at line 4130 of file float.c.

4131{
4134
4136}
static bool float8_le(const float8 val1, const float8 val2)
Definition float.h:286

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

◆ float48lt()

Datum float48lt ( PG_FUNCTION_ARGS  )

Definition at line 4121 of file float.c.

4122{
4125
4127}
static bool float8_lt(const float8 val1, const float8 val2)
Definition float.h:274

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

◆ float48mi()

Datum float48mi ( PG_FUNCTION_ARGS  )

Definition at line 4025 of file float.c.

4026{
4029
4031}
static float8 float8_mi(const float8 val1, const float8 val2)
Definition float.h:158

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

◆ float48mul()

Datum float48mul ( PG_FUNCTION_ARGS  )

Definition at line 4034 of file float.c.

4035{
4038
4040}
static float8 float8_mul(const float8 val1, const float8 val2)
Definition float.h:192

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

◆ float48ne()

Datum float48ne ( PG_FUNCTION_ARGS  )

Definition at line 4112 of file float.c.

4113{
4116
4118}
static bool float8_ne(const float8 val1, const float8 val2)
Definition float.h:262

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

◆ float48pl()

Datum float48pl ( PG_FUNCTION_ARGS  )

Definition at line 4016 of file float.c.

4017{
4020
4022}
static float8 float8_pl(const float8 val1, const float8 val2)
Definition float.h:128

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

◆ float4_accum()

Datum float4_accum ( PG_FUNCTION_ARGS  )

Definition at line 3171 of file float.c.

3172{
3174
3175 /* do computations as float8 */
3178 float8 N,
3179 Sx,
3180 Sxx,
3181 tmp;
3182
3183 transvalues = check_float8_array(transarray, "float4_accum", 3);
3184 N = transvalues[0];
3185 Sx = transvalues[1];
3186 Sxx = transvalues[2];
3187
3188 /*
3189 * Use the Youngs-Cramer algorithm to incorporate the new value into the
3190 * transition values.
3191 */
3192 N += 1.0;
3193 Sx += newval;
3194 if (transvalues[0] > 0.0)
3195 {
3196 tmp = newval * N - Sx;
3197 Sxx += tmp * tmp / (N * transvalues[0]);
3198
3199 /*
3200 * Overflow check. We only report an overflow error when finite
3201 * inputs lead to infinite results. Note also that Sxx should be NaN
3202 * if any of the inputs are infinite, so we intentionally prevent Sxx
3203 * from becoming infinite.
3204 */
3205 if (isinf(Sx) || isinf(Sxx))
3206 {
3207 if (!isinf(transvalues[1]) && !isinf(newval))
3209
3210 Sxx = get_float8_nan();
3211 }
3212 }
3213 else
3214 {
3215 /*
3216 * At the first input, we normally can leave Sxx as 0. However, if
3217 * the first input is Inf or NaN, we'd better force Sxx to NaN;
3218 * otherwise we will falsely report variance zero when there are no
3219 * more inputs.
3220 */
3221 if (isnan(newval) || isinf(newval))
3222 Sxx = get_float8_nan();
3223 }
3224
3225 /*
3226 * If we're invoked as an aggregate, we can cheat and modify our first
3227 * parameter in-place to reduce palloc overhead. Otherwise we construct a
3228 * new array with the updated transition data and return it.
3229 */
3230 if (AggCheckCallContext(fcinfo, NULL))
3231 {
3232 transvalues[0] = N;
3233 transvalues[1] = Sx;
3234 transvalues[2] = Sxx;
3235
3237 }
3238 else
3239 {
3240 Datum transdatums[3];
3242
3246
3248
3250 }
3251}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
#define PG_RETURN_ARRAYTYPE_P(x)
Definition array.h:265
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)
Definition float.c:2974
#define newval
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition nodeAgg.c:4609
#define Float8GetDatumFast(X)
Definition postgres.h:527

References AggCheckCallContext(), check_float8_array(), construct_array_builtin(), fb(), Float8GetDatumFast, float_overflow_error(), get_float8_nan(), newval, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT4, PG_RETURN_ARRAYTYPE_P, and result.

◆ float4_cmp_internal()

int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 857 of file float.c.

858{
859 if (float4_gt(a, b))
860 return 1;
861 if (float4_lt(a, b))
862 return -1;
863 return 0;
864}
static bool float4_lt(const float4 val1, const float4 val2)
Definition float.h:268
static bool float4_gt(const float4 val1, const float4 val2)
Definition float.h:292
int b
Definition isn.c:74
int a
Definition isn.c:73

References a, b, float4_gt(), and float4_lt().

Referenced by btfloat4cmp(), btfloat4fastcmp(), and gbt_float4_ssup_cmp().

◆ float4abs()

Datum float4abs ( PG_FUNCTION_ARGS  )

Definition at line 632 of file float.c.

633{
635
637}

References fb(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

◆ float4div()

Datum float4div ( PG_FUNCTION_ARGS  )

Definition at line 796 of file float.c.

797{
800
802}
static float4 float4_div(const float4 val1, const float4 val2)
Definition float.h:198

References fb(), float4_div(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

◆ float4eq()

Datum float4eq ( PG_FUNCTION_ARGS  )

Definition at line 867 of file float.c.

868{
871
873}
static bool float4_eq(const float4 val1, const float4 val2)
Definition float.h:244

References fb(), float4_eq(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

◆ float4ge()

Datum float4ge ( PG_FUNCTION_ARGS  )

Definition at line 912 of file float.c.

913{
916
918}
static bool float4_ge(const float4 val1, const float4 val2)
Definition float.h:304

References fb(), float4_ge(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

◆ float4gt()

Datum float4gt ( PG_FUNCTION_ARGS  )

Definition at line 903 of file float.c.

References fb(), float4_gt(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

◆ float4in()

Datum float4in ( PG_FUNCTION_ARGS  )

Definition at line 205 of file float.c.

206{
207 char *num = PG_GETARG_CSTRING(0);
208
209 PG_RETURN_FLOAT4(float4in_internal(num, NULL, "real", num,
210 fcinfo->context));
211}
float4 float4in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
Definition float.c:224
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278

References fb(), float4in_internal(), PG_GETARG_CSTRING, and PG_RETURN_FLOAT4.

Referenced by import_pg_statistic(), and numeric_float4().

◆ float4in_internal()

float4 float4in_internal ( char num,
char **  endptr_p,
const char type_name,
const char orig_string,
struct Node escontext 
)

Definition at line 224 of file float.c.

227{
228 float val;
229 char *endptr;
230
231 /*
232 * endptr points to the first character _after_ the sequence we recognized
233 * as a valid floating point number. orig_string points to the original
234 * input string.
235 */
236
237 /* skip leading whitespace */
238 while (*num != '\0' && isspace((unsigned char) *num))
239 num++;
240
241 /*
242 * Check for an empty-string input to begin with, to avoid the vagaries of
243 * strtod() on different platforms.
244 */
245 if (*num == '\0')
246 ereturn(escontext, 0,
248 errmsg("invalid input syntax for type %s: \"%s\"",
249 type_name, orig_string)));
250
251 errno = 0;
252 val = strtof(num, &endptr);
253
254 /* did we not see anything that looks like a double? */
255 if (endptr == num || errno != 0)
256 {
257 int save_errno = errno;
258
259 /*
260 * C99 requires that strtof() accept NaN, [+-]Infinity, and [+-]Inf,
261 * but not all platforms support all of these (and some accept them
262 * but set ERANGE anyway...) Therefore, we check for these inputs
263 * ourselves if strtof() fails.
264 *
265 * Note: C99 also requires hexadecimal input as well as some extended
266 * forms of NaN, but we consider these forms unportable and don't try
267 * to support them. You can use 'em if your strtof() takes 'em.
268 */
269 if (pg_strncasecmp(num, "NaN", 3) == 0)
270 {
272 endptr = num + 3;
273 }
274 else if (pg_strncasecmp(num, "Infinity", 8) == 0)
275 {
277 endptr = num + 8;
278 }
279 else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
280 {
282 endptr = num + 9;
283 }
284 else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
285 {
287 endptr = num + 9;
288 }
289 else if (pg_strncasecmp(num, "inf", 3) == 0)
290 {
292 endptr = num + 3;
293 }
294 else if (pg_strncasecmp(num, "+inf", 4) == 0)
295 {
297 endptr = num + 4;
298 }
299 else if (pg_strncasecmp(num, "-inf", 4) == 0)
300 {
302 endptr = num + 4;
303 }
304 else if (save_errno == ERANGE)
305 {
306 /*
307 * Some platforms return ERANGE for denormalized numbers (those
308 * that are not zero, but are too close to zero to have full
309 * precision). We'd prefer not to throw error for that, so try to
310 * detect whether it's a "real" out-of-range condition by checking
311 * to see if the result is zero or huge.
312 */
313 if (val == 0.0 ||
314#if !defined(HUGE_VALF)
315 isinf(val)
316#else
317 (val >= HUGE_VALF || val <= -HUGE_VALF)
318#endif
319 )
320 {
321 /* see comments in float8in_internal for rationale */
322 char *errnumber = pstrdup(num);
323
324 errnumber[endptr - num] = '\0';
325
326 ereturn(escontext, 0,
328 errmsg("\"%s\" is out of range for type real",
329 errnumber)));
330 }
331 }
332 else
333 ereturn(escontext, 0,
335 errmsg("invalid input syntax for type %s: \"%s\"",
336 type_name, orig_string)));
337 }
338
339 /* skip trailing whitespace */
340 while (*endptr != '\0' && isspace((unsigned char) *endptr))
341 endptr++;
342
343 /* report stopping point if wanted, else complain if not end of string */
344 if (endptr_p)
345 *endptr_p = endptr;
346 else if (*endptr != '\0')
347 ereturn(escontext, 0,
349 errmsg("invalid input syntax for type %s: \"%s\"",
350 type_name, orig_string)));
351
352 return val;
353}
static float4 get_float4_infinity(void)
Definition float.h:61
static float4 get_float4_nan(void)
Definition float.h:80
long val
Definition informix.c:689
char * pstrdup(const char *in)
Definition mcxt.c:1781
int pg_strncasecmp(const char *s1, const char *s2, size_t n)

References ereturn, errcode(), errmsg, fb(), get_float4_infinity(), get_float4_nan(), pg_strncasecmp(), pstrdup(), and val.

Referenced by float4in().

◆ float4larger()

Datum float4larger ( PG_FUNCTION_ARGS  )

Definition at line 661 of file float.c.

662{
666
667 if (float4_gt(arg1, arg2))
668 result = arg1;
669 else
670 result = arg2;
672}

References fb(), float4_gt(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, and result.

◆ float4le()

Datum float4le ( PG_FUNCTION_ARGS  )

Definition at line 894 of file float.c.

895{
898
900}
static bool float4_le(const float4 val1, const float4 val2)
Definition float.h:280

References fb(), float4_le(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

◆ float4lt()

Datum float4lt ( PG_FUNCTION_ARGS  )

Definition at line 885 of file float.c.

References fb(), float4_lt(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

◆ float4mi()

Datum float4mi ( PG_FUNCTION_ARGS  )

Definition at line 778 of file float.c.

779{
782
784}
static float4 float4_mi(const float4 val1, const float4 val2)
Definition float.h:134

References fb(), float4_mi(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

◆ float4mul()

Datum float4mul ( PG_FUNCTION_ARGS  )

Definition at line 787 of file float.c.

788{
791
793}
static float4 float4_mul(const float4 val1, const float4 val2)
Definition float.h:164

References fb(), float4_mul(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

◆ float4ne()

Datum float4ne ( PG_FUNCTION_ARGS  )

Definition at line 876 of file float.c.

877{
880
882}
static bool float4_ne(const float4 val1, const float4 val2)
Definition float.h:256

References fb(), float4_ne(), PG_GETARG_FLOAT4, and PG_RETURN_BOOL.

◆ float4out()

Datum float4out ( PG_FUNCTION_ARGS  )

Definition at line 360 of file float.c.

361{
362 float4 num = PG_GETARG_FLOAT4(0);
363 char *ascii = (char *) palloc(32);
365
366 if (extra_float_digits > 0)
367 {
370 }
371
372 (void) pg_strfromd(ascii, 32, ndig, num);
374}
int float_to_shortest_decimal_buf(float f, char *result)
Definition f2s.c:780
int extra_float_digits
Definition float.c:57
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
void * palloc(Size size)
Definition mcxt.c:1387
Datum ascii(PG_FUNCTION_ARGS)
int pg_strfromd(char *str, size_t count, int precision, double value)
Definition snprintf.c:1276

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

◆ float4pl()

Datum float4pl ( PG_FUNCTION_ARGS  )

Definition at line 769 of file float.c.

770{
773
775}
static float4 float4_pl(const float4 val1, const float4 val2)
Definition float.h:104

References fb(), float4_pl(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

◆ float4recv()

Datum float4recv ( PG_FUNCTION_ARGS  )

Definition at line 380 of file float.c.

381{
383
385}
static char buf[DEFAULT_XLOG_SEG_SIZE]
float4 pq_getmsgfloat4(StringInfo msg)
Definition pqformat.c:468
struct StringInfoData * StringInfo
Definition string.h:15

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

◆ float4send()

Datum float4send ( PG_FUNCTION_ARGS  )

Definition at line 391 of file float.c.

392{
393 float4 num = PG_GETARG_FLOAT4(0);
395
397 pq_sendfloat4(&buf, num);
399}
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373
void pq_begintypsend(StringInfo buf)
Definition pqformat.c:325
void pq_sendfloat4(StringInfo buf, float4 f)
Definition pqformat.c:252
bytea * pq_endtypsend(StringInfo buf)
Definition pqformat.c:345

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

◆ float4smaller()

Datum float4smaller ( PG_FUNCTION_ARGS  )

Definition at line 675 of file float.c.

676{
680
681 if (float4_lt(arg1, arg2))
682 result = arg1;
683 else
684 result = arg2;
686}

References fb(), float4_lt(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, and result.

◆ float4um()

Datum float4um ( PG_FUNCTION_ARGS  )

Definition at line 643 of file float.c.

644{
647
648 result = -arg1;
650}

References fb(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, and result.

◆ float4up()

Datum float4up ( PG_FUNCTION_ARGS  )

Definition at line 653 of file float.c.

654{
656
658}
Datum arg
Definition elog.c:1322

References arg, PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

◆ float84div()

Datum float84div ( PG_FUNCTION_ARGS  )

Definition at line 4085 of file float.c.

4086{
4089
4091}

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

◆ float84eq()

Datum float84eq ( PG_FUNCTION_ARGS  )

Definition at line 4160 of file float.c.

4161{
4164
4166}

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

◆ float84ge()

Datum float84ge ( PG_FUNCTION_ARGS  )

Definition at line 4205 of file float.c.

4206{
4209
4211}

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

◆ float84gt()

Datum float84gt ( PG_FUNCTION_ARGS  )

Definition at line 4196 of file float.c.

4197{
4200
4202}

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

◆ float84le()

Datum float84le ( PG_FUNCTION_ARGS  )

Definition at line 4187 of file float.c.

4188{
4191
4193}

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

◆ float84lt()

Datum float84lt ( PG_FUNCTION_ARGS  )

Definition at line 4178 of file float.c.

4179{
4182
4184}

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

◆ float84mi()

Datum float84mi ( PG_FUNCTION_ARGS  )

Definition at line 4067 of file float.c.

4068{
4071
4073}

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

◆ float84mul()

Datum float84mul ( PG_FUNCTION_ARGS  )

Definition at line 4076 of file float.c.

4077{
4080
4082}

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

◆ float84ne()

Datum float84ne ( PG_FUNCTION_ARGS  )

Definition at line 4169 of file float.c.

4170{
4173
4175}

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

◆ float84pl()

Datum float84pl ( PG_FUNCTION_ARGS  )

Definition at line 4058 of file float.c.

4059{
4062
4064}

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

◆ float8_accum()

Datum float8_accum ( PG_FUNCTION_ARGS  )

Definition at line 3090 of file float.c.

3091{
3095 float8 N,
3096 Sx,
3097 Sxx,
3098 tmp;
3099
3100 transvalues = check_float8_array(transarray, "float8_accum", 3);
3101 N = transvalues[0];
3102 Sx = transvalues[1];
3103 Sxx = transvalues[2];
3104
3105 /*
3106 * Use the Youngs-Cramer algorithm to incorporate the new value into the
3107 * transition values.
3108 */
3109 N += 1.0;
3110 Sx += newval;
3111 if (transvalues[0] > 0.0)
3112 {
3113 tmp = newval * N - Sx;
3114 Sxx += tmp * tmp / (N * transvalues[0]);
3115
3116 /*
3117 * Overflow check. We only report an overflow error when finite
3118 * inputs lead to infinite results. Note also that Sxx should be NaN
3119 * if any of the inputs are infinite, so we intentionally prevent Sxx
3120 * from becoming infinite.
3121 */
3122 if (isinf(Sx) || isinf(Sxx))
3123 {
3124 if (!isinf(transvalues[1]) && !isinf(newval))
3126
3127 Sxx = get_float8_nan();
3128 }
3129 }
3130 else
3131 {
3132 /*
3133 * At the first input, we normally can leave Sxx as 0. However, if
3134 * the first input is Inf or NaN, we'd better force Sxx to NaN;
3135 * otherwise we will falsely report variance zero when there are no
3136 * more inputs.
3137 */
3138 if (isnan(newval) || isinf(newval))
3139 Sxx = get_float8_nan();
3140 }
3141
3142 /*
3143 * If we're invoked as an aggregate, we can cheat and modify our first
3144 * parameter in-place to reduce palloc overhead. Otherwise we construct a
3145 * new array with the updated transition data and return it.
3146 */
3147 if (AggCheckCallContext(fcinfo, NULL))
3148 {
3149 transvalues[0] = N;
3150 transvalues[1] = Sx;
3151 transvalues[2] = Sxx;
3152
3154 }
3155 else
3156 {
3157 Datum transdatums[3];
3159
3163
3165
3167 }
3168}

References AggCheckCallContext(), check_float8_array(), construct_array_builtin(), fb(), Float8GetDatumFast, float_overflow_error(), get_float8_nan(), newval, PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, PG_RETURN_ARRAYTYPE_P, and result.

◆ float8_avg()

Datum float8_avg ( PG_FUNCTION_ARGS  )

Definition at line 3254 of file float.c.

3255{
3258 float8 N,
3259 Sx;
3260
3261 transvalues = check_float8_array(transarray, "float8_avg", 3);
3262 N = transvalues[0];
3263 Sx = transvalues[1];
3264 /* ignore Sxx */
3265
3266 /* SQL defines AVG of no values to be NULL */
3267 if (N == 0.0)
3269
3270 PG_RETURN_FLOAT8(Sx / N);
3271}
#define PG_RETURN_NULL()
Definition fmgr.h:346

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

◆ float8_cmp_internal()

int float8_cmp_internal ( float8  a,
float8  b 
)

Definition at line 951 of file float.c.

952{
953 if (float8_gt(a, b))
954 return 1;
955 if (float8_lt(a, b))
956 return -1;
957 return 0;
958}

References a, b, float8_gt(), and float8_lt().

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

◆ float8_combine()

Datum float8_combine ( PG_FUNCTION_ARGS  )

Definition at line 2998 of file float.c.

2999{
3004 float8 N1,
3005 Sx1,
3006 Sxx1,
3007 N2,
3008 Sx2,
3009 Sxx2,
3010 tmp,
3011 N,
3012 Sx,
3013 Sxx;
3014
3015 transvalues1 = check_float8_array(transarray1, "float8_combine", 3);
3016 transvalues2 = check_float8_array(transarray2, "float8_combine", 3);
3017
3018 N1 = transvalues1[0];
3019 Sx1 = transvalues1[1];
3020 Sxx1 = transvalues1[2];
3021
3022 N2 = transvalues2[0];
3023 Sx2 = transvalues2[1];
3024 Sxx2 = transvalues2[2];
3025
3026 /*--------------------
3027 * The transition values combine using a generalization of the
3028 * Youngs-Cramer algorithm as follows:
3029 *
3030 * N = N1 + N2
3031 * Sx = Sx1 + Sx2
3032 * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N;
3033 *
3034 * It's worth handling the special cases N1 = 0 and N2 = 0 separately
3035 * since those cases are trivial, and we then don't need to worry about
3036 * division-by-zero errors in the general case.
3037 *--------------------
3038 */
3039 if (N1 == 0.0)
3040 {
3041 N = N2;
3042 Sx = Sx2;
3043 Sxx = Sxx2;
3044 }
3045 else if (N2 == 0.0)
3046 {
3047 N = N1;
3048 Sx = Sx1;
3049 Sxx = Sxx1;
3050 }
3051 else
3052 {
3053 N = N1 + N2;
3054 Sx = float8_pl(Sx1, Sx2);
3055 tmp = Sx1 / N1 - Sx2 / N2;
3056 Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp * tmp / N;
3057 if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))
3059 }
3060
3061 /*
3062 * If we're invoked as an aggregate, we can cheat and modify our first
3063 * parameter in-place to reduce palloc overhead. Otherwise we construct a
3064 * new array with the updated transition data and return it.
3065 */
3066 if (AggCheckCallContext(fcinfo, NULL))
3067 {
3068 transvalues1[0] = N;
3069 transvalues1[1] = Sx;
3070 transvalues1[2] = Sxx;
3071
3073 }
3074 else
3075 {
3076 Datum transdatums[3];
3078
3082
3084
3086 }
3087}

References AggCheckCallContext(), check_float8_array(), construct_array_builtin(), fb(), float8_pl(), Float8GetDatumFast, float_overflow_error(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_ARRAYTYPE_P, result, and unlikely.

◆ float8_corr()

Datum float8_corr ( PG_FUNCTION_ARGS  )

Definition at line 3858 of file float.c.

3859{
3862 float8 N,
3863 Sxx,
3864 Syy,
3865 Sxy,
3866 product,
3868 result;
3869
3870 transvalues = check_float8_array(transarray, "float8_corr", 8);
3871 N = transvalues[0];
3872 Sxx = transvalues[2];
3873 Syy = transvalues[4];
3874 Sxy = transvalues[5];
3875
3876 /* if N is 0 we should return NULL */
3877 if (N < 1.0)
3879
3880 /* Note that Sxx and Syy are guaranteed to be non-negative */
3881
3882 /* per spec, return NULL for horizontal and vertical lines */
3883 if (Sxx == 0 || Syy == 0)
3885
3886 /*
3887 * The product Sxx * Syy might underflow or overflow. If so, we can
3888 * recover by computing sqrt(Sxx) * sqrt(Syy) instead of sqrt(Sxx * Syy).
3889 * However, the double sqrt() calculation is a bit slower and less
3890 * accurate, so don't do it if we don't have to.
3891 */
3892 product = Sxx * Syy;
3893 if (product == 0 || isinf(product))
3894 sqrtproduct = sqrt(Sxx) * sqrt(Syy);
3895 else
3898
3899 /*
3900 * Despite all these precautions, this formula can yield results outside
3901 * [-1, 1] due to roundoff error. Clamp it to the expected range.
3902 */
3903 if (result < -1)
3904 result = -1;
3905 else if (result > 1)
3906 result = 1;
3907
3909}

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

◆ float8_covar_pop()

Datum float8_covar_pop ( PG_FUNCTION_ARGS  )

Definition at line 3820 of file float.c.

3821{
3824 float8 N,
3825 Sxy;
3826
3827 transvalues = check_float8_array(transarray, "float8_covar_pop", 8);
3828 N = transvalues[0];
3829 Sxy = transvalues[5];
3830
3831 /* if N is 0 we should return NULL */
3832 if (N < 1.0)
3834
3835 PG_RETURN_FLOAT8(Sxy / N);
3836}

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

◆ float8_covar_samp()

Datum float8_covar_samp ( PG_FUNCTION_ARGS  )

Definition at line 3839 of file float.c.

3840{
3843 float8 N,
3844 Sxy;
3845
3846 transvalues = check_float8_array(transarray, "float8_covar_samp", 8);
3847 N = transvalues[0];
3848 Sxy = transvalues[5];
3849
3850 /* if N is <= 1 we should return NULL */
3851 if (N < 2.0)
3853
3854 PG_RETURN_FLOAT8(Sxy / (N - 1.0));
3855}

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

◆ float8_regr_accum()

Datum float8_regr_accum ( PG_FUNCTION_ARGS  )

Definition at line 3395 of file float.c.

3396{
3401 float8 N,
3402 Sx,
3403 Sxx,
3404 Sy,
3405 Syy,
3406 Sxy,
3407 commonX,
3408 commonY,
3409 tmpX,
3410 tmpY,
3411 scale;
3412
3413 transvalues = check_float8_array(transarray, "float8_regr_accum", 8);
3414 N = transvalues[0];
3415 Sx = transvalues[1];
3416 Sxx = transvalues[2];
3417 Sy = transvalues[3];
3418 Syy = transvalues[4];
3419 Sxy = transvalues[5];
3420 commonX = transvalues[6];
3421 commonY = transvalues[7];
3422
3423 /*
3424 * Use the Youngs-Cramer algorithm to incorporate the new values into the
3425 * transition values.
3426 */
3427 N += 1.0;
3428 Sx += newvalX;
3429 Sy += newvalY;
3430 if (transvalues[0] > 0.0)
3431 {
3432 /*
3433 * Check to see if we have seen distinct inputs. We can use a test
3434 * that's a bit cheaper than float8_ne() because if commonX is already
3435 * NaN, it does not matter whether the != test returns true or not.
3436 */
3437 if (newvalX != commonX || isnan(newvalX))
3439 if (newvalY != commonY || isnan(newvalY))
3441
3442 tmpX = newvalX * N - Sx;
3443 tmpY = newvalY * N - Sy;
3444 scale = 1.0 / (N * transvalues[0]);
3445
3446 /*
3447 * If we have not seen distinct inputs, then Sxx, Syy, and/or Sxy
3448 * should remain zero (since Sx's exact value would be N * commonX,
3449 * etc). Updating them would just create the possibility of injecting
3450 * roundoff error, and we need exact zero results so that the final
3451 * functions will return NULL in the right cases.
3452 */
3453 if (isnan(commonX))
3454 Sxx += tmpX * tmpX * scale;
3455 if (isnan(commonY))
3456 Syy += tmpY * tmpY * scale;
3457 if (isnan(commonX) && isnan(commonY))
3458 Sxy += tmpX * tmpY * scale;
3459
3460 /*
3461 * Overflow check. We only report an overflow error when finite
3462 * inputs lead to infinite results. Note also that Sxx, Syy and Sxy
3463 * should be NaN if any of the relevant inputs are infinite, so we
3464 * intentionally prevent them from becoming infinite.
3465 */
3466 if (isinf(Sx) || isinf(Sxx) || isinf(Sy) || isinf(Syy) || isinf(Sxy))
3467 {
3468 if (((isinf(Sx) || isinf(Sxx)) &&
3469 !isinf(transvalues[1]) && !isinf(newvalX)) ||
3470 ((isinf(Sy) || isinf(Syy)) &&
3471 !isinf(transvalues[3]) && !isinf(newvalY)) ||
3472 (isinf(Sxy) &&
3473 !isinf(transvalues[1]) && !isinf(newvalX) &&
3474 !isinf(transvalues[3]) && !isinf(newvalY)))
3476
3477 if (isinf(Sxx))
3478 Sxx = get_float8_nan();
3479 if (isinf(Syy))
3480 Syy = get_float8_nan();
3481 if (isinf(Sxy))
3482 Sxy = get_float8_nan();
3483 }
3484 }
3485 else
3486 {
3487 /*
3488 * At the first input, we normally can leave Sxx et al as 0. However,
3489 * if the first input is Inf or NaN, we'd better force the dependent
3490 * sums to NaN; otherwise we will falsely report variance zero when
3491 * there are no more inputs.
3492 */
3493 if (isnan(newvalX) || isinf(newvalX))
3494 Sxx = Sxy = get_float8_nan();
3495 if (isnan(newvalY) || isinf(newvalY))
3496 Syy = Sxy = get_float8_nan();
3497
3498 commonX = newvalX;
3499 commonY = newvalY;
3500 }
3501
3502 /*
3503 * If we're invoked as an aggregate, we can cheat and modify our first
3504 * parameter in-place to reduce palloc overhead. Otherwise we construct a
3505 * new array with the updated transition data and return it.
3506 */
3507 if (AggCheckCallContext(fcinfo, NULL))
3508 {
3509 transvalues[0] = N;
3510 transvalues[1] = Sx;
3511 transvalues[2] = Sxx;
3512 transvalues[3] = Sy;
3513 transvalues[4] = Syy;
3514 transvalues[5] = Sxy;
3515 transvalues[6] = commonX;
3516 transvalues[7] = commonY;
3517
3519 }
3520 else
3521 {
3522 Datum transdatums[8];
3524
3533
3535
3537 }
3538}
static int scale
Definition pgbench.c:182

References AggCheckCallContext(), check_float8_array(), construct_array_builtin(), fb(), Float8GetDatumFast, float_overflow_error(), get_float8_nan(), PG_GETARG_ARRAYTYPE_P, PG_GETARG_FLOAT8, PG_RETURN_ARRAYTYPE_P, result, and scale.

◆ float8_regr_avgx()

Datum float8_regr_avgx ( PG_FUNCTION_ARGS  )

Definition at line 3770 of file float.c.

3771{
3774 float8 N,
3775 Sx,
3776 commonX;
3777
3778 transvalues = check_float8_array(transarray, "float8_regr_avgx", 8);
3779 N = transvalues[0];
3780 Sx = transvalues[1];
3781 commonX = transvalues[6];
3782
3783 /* if N is 0 we should return NULL */
3784 if (N < 1.0)
3786
3787 /* if all inputs were the same just return that, avoiding roundoff error */
3788 if (!isnan(commonX))
3790
3791 PG_RETURN_FLOAT8(Sx / N);
3792}

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

◆ float8_regr_avgy()

Datum float8_regr_avgy ( PG_FUNCTION_ARGS  )

Definition at line 3795 of file float.c.

3796{
3799 float8 N,
3800 Sy,
3801 commonY;
3802
3803 transvalues = check_float8_array(transarray, "float8_regr_avgy", 8);
3804 N = transvalues[0];
3805 Sy = transvalues[3];
3806 commonY = transvalues[7];
3807
3808 /* if N is 0 we should return NULL */
3809 if (N < 1.0)
3811
3812 /* if all inputs were the same just return that, avoiding roundoff error */
3813 if (!isnan(commonY))
3815
3816 PG_RETURN_FLOAT8(Sy / N);
3817}

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

◆ float8_regr_combine()

Datum float8_regr_combine ( PG_FUNCTION_ARGS  )

Definition at line 3549 of file float.c.

3550{
3555 float8 N1,
3556 Sx1,
3557 Sxx1,
3558 Sy1,
3559 Syy1,
3560 Sxy1,
3561 Cx1,
3562 Cy1,
3563 N2,
3564 Sx2,
3565 Sxx2,
3566 Sy2,
3567 Syy2,
3568 Sxy2,
3569 Cx2,
3570 Cy2,
3571 tmp1,
3572 tmp2,
3573 N,
3574 Sx,
3575 Sxx,
3576 Sy,
3577 Syy,
3578 Sxy,
3579 Cx,
3580 Cy;
3581
3582 transvalues1 = check_float8_array(transarray1, "float8_regr_combine", 8);
3583 transvalues2 = check_float8_array(transarray2, "float8_regr_combine", 8);
3584
3585 N1 = transvalues1[0];
3586 Sx1 = transvalues1[1];
3587 Sxx1 = transvalues1[2];
3588 Sy1 = transvalues1[3];
3589 Syy1 = transvalues1[4];
3590 Sxy1 = transvalues1[5];
3591 Cx1 = transvalues1[6];
3592 Cy1 = transvalues1[7];
3593
3594 N2 = transvalues2[0];
3595 Sx2 = transvalues2[1];
3596 Sxx2 = transvalues2[2];
3597 Sy2 = transvalues2[3];
3598 Syy2 = transvalues2[4];
3599 Sxy2 = transvalues2[5];
3600 Cx2 = transvalues2[6];
3601 Cy2 = transvalues2[7];
3602
3603 /*--------------------
3604 * The transition values combine using a generalization of the
3605 * Youngs-Cramer algorithm as follows:
3606 *
3607 * N = N1 + N2
3608 * Sx = Sx1 + Sx2
3609 * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N
3610 * Sy = Sy1 + Sy2
3611 * Syy = Syy1 + Syy2 + N1 * N2 * (Sy1/N1 - Sy2/N2)^2 / N
3612 * Sxy = Sxy1 + Sxy2 + N1 * N2 * (Sx1/N1 - Sx2/N2) * (Sy1/N1 - Sy2/N2) / N
3613 *
3614 * It's worth handling the special cases N1 = 0 and N2 = 0 separately
3615 * since those cases are trivial, and we then don't need to worry about
3616 * division-by-zero errors in the general case.
3617 *--------------------
3618 */
3619 if (N1 == 0.0)
3620 {
3621 N = N2;
3622 Sx = Sx2;
3623 Sxx = Sxx2;
3624 Sy = Sy2;
3625 Syy = Syy2;
3626 Sxy = Sxy2;
3627 Cx = Cx2;
3628 Cy = Cy2;
3629 }
3630 else if (N2 == 0.0)
3631 {
3632 N = N1;
3633 Sx = Sx1;
3634 Sxx = Sxx1;
3635 Sy = Sy1;
3636 Syy = Syy1;
3637 Sxy = Sxy1;
3638 Cx = Cx1;
3639 Cy = Cy1;
3640 }
3641 else
3642 {
3643 N = N1 + N2;
3644 Sx = float8_pl(Sx1, Sx2);
3645 tmp1 = Sx1 / N1 - Sx2 / N2;
3646 Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp1 * tmp1 / N;
3647 if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))
3649 Sy = float8_pl(Sy1, Sy2);
3650 tmp2 = Sy1 / N1 - Sy2 / N2;
3651 Syy = Syy1 + Syy2 + N1 * N2 * tmp2 * tmp2 / N;
3652 if (unlikely(isinf(Syy)) && !isinf(Syy1) && !isinf(Syy2))
3654 Sxy = Sxy1 + Sxy2 + N1 * N2 * tmp1 * tmp2 / N;
3655 if (unlikely(isinf(Sxy)) && !isinf(Sxy1) && !isinf(Sxy2))
3657 if (float8_eq(Cx1, Cx2))
3658 Cx = Cx1;
3659 else
3660 Cx = get_float8_nan();
3661 if (float8_eq(Cy1, Cy2))
3662 Cy = Cy1;
3663 else
3664 Cy = get_float8_nan();
3665 }
3666
3667 /*
3668 * If we're invoked as an aggregate, we can cheat and modify our first
3669 * parameter in-place to reduce palloc overhead. Otherwise we construct a
3670 * new array with the updated transition data and return it.
3671 */
3672 if (AggCheckCallContext(fcinfo, NULL))
3673 {
3674 transvalues1[0] = N;
3675 transvalues1[1] = Sx;
3676 transvalues1[2] = Sxx;
3677 transvalues1[3] = Sy;
3678 transvalues1[4] = Syy;
3679 transvalues1[5] = Sxy;
3680 transvalues1[6] = Cx;
3681 transvalues1[7] = Cy;
3682
3684 }
3685 else
3686 {
3687 Datum transdatums[8];
3689
3698
3700
3702 }
3703}

References AggCheckCallContext(), check_float8_array(), construct_array_builtin(), fb(), float8_eq(), float8_pl(), Float8GetDatumFast, float_overflow_error(), get_float8_nan(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_ARRAYTYPE_P, result, and unlikely.

◆ float8_regr_intercept()

Datum float8_regr_intercept ( PG_FUNCTION_ARGS  )

Definition at line 3972 of file float.c.

3973{
3976 float8 N,
3977 Sx,
3978 Sxx,
3979 Sy,
3980 Sxy;
3981
3982 transvalues = check_float8_array(transarray, "float8_regr_intercept", 8);
3983 N = transvalues[0];
3984 Sx = transvalues[1];
3985 Sxx = transvalues[2];
3986 Sy = transvalues[3];
3987 Sxy = transvalues[5];
3988
3989 /* if N is 0 we should return NULL */
3990 if (N < 1.0)
3992
3993 /* Note that Sxx is guaranteed to be non-negative */
3994
3995 /* per spec, return NULL for a vertical line */
3996 if (Sxx == 0)
3998
3999 PG_RETURN_FLOAT8((Sy - Sx * Sxy / Sxx) / N);
4000}

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

◆ float8_regr_r2()

Datum float8_regr_r2 ( PG_FUNCTION_ARGS  )

Definition at line 3912 of file float.c.

3913{
3916 float8 N,
3917 Sxx,
3918 Syy,
3919 Sxy;
3920
3921 transvalues = check_float8_array(transarray, "float8_regr_r2", 8);
3922 N = transvalues[0];
3923 Sxx = transvalues[2];
3924 Syy = transvalues[4];
3925 Sxy = transvalues[5];
3926
3927 /* if N is 0 we should return NULL */
3928 if (N < 1.0)
3930
3931 /* Note that Sxx and Syy are guaranteed to be non-negative */
3932
3933 /* per spec, return NULL for a vertical line */
3934 if (Sxx == 0)
3936
3937 /* per spec, return 1.0 for a horizontal line */
3938 if (Syy == 0)
3939 PG_RETURN_FLOAT8(1.0);
3940
3941 PG_RETURN_FLOAT8((Sxy * Sxy) / (Sxx * Syy));
3942}

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

◆ float8_regr_slope()

Datum float8_regr_slope ( PG_FUNCTION_ARGS  )

Definition at line 3945 of file float.c.

3946{
3949 float8 N,
3950 Sxx,
3951 Sxy;
3952
3953 transvalues = check_float8_array(transarray, "float8_regr_slope", 8);
3954 N = transvalues[0];
3955 Sxx = transvalues[2];
3956 Sxy = transvalues[5];
3957
3958 /* if N is 0 we should return NULL */
3959 if (N < 1.0)
3961
3962 /* Note that Sxx is guaranteed to be non-negative */
3963
3964 /* per spec, return NULL for a vertical line */
3965 if (Sxx == 0)
3967
3969}

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

◆ float8_regr_sxx()

Datum float8_regr_sxx ( PG_FUNCTION_ARGS  )

Definition at line 3707 of file float.c.

3708{
3711 float8 N,
3712 Sxx;
3713
3714 transvalues = check_float8_array(transarray, "float8_regr_sxx", 8);
3715 N = transvalues[0];
3716 Sxx = transvalues[2];
3717
3718 /* if N is 0 we should return NULL */
3719 if (N < 1.0)
3721
3722 /* Note that Sxx is guaranteed to be non-negative */
3723
3725}

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

◆ float8_regr_sxy()

Datum float8_regr_sxy ( PG_FUNCTION_ARGS  )

Definition at line 3749 of file float.c.

3750{
3753 float8 N,
3754 Sxy;
3755
3756 transvalues = check_float8_array(transarray, "float8_regr_sxy", 8);
3757 N = transvalues[0];
3758 Sxy = transvalues[5];
3759
3760 /* if N is 0 we should return NULL */
3761 if (N < 1.0)
3763
3764 /* A negative result is valid here */
3765
3767}

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

◆ float8_regr_syy()

Datum float8_regr_syy ( PG_FUNCTION_ARGS  )

Definition at line 3728 of file float.c.

3729{
3732 float8 N,
3733 Syy;
3734
3735 transvalues = check_float8_array(transarray, "float8_regr_syy", 8);
3736 N = transvalues[0];
3737 Syy = transvalues[4];
3738
3739 /* if N is 0 we should return NULL */
3740 if (N < 1.0)
3742
3743 /* Note that Syy is guaranteed to be non-negative */
3744
3746}

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

◆ float8_stddev_pop()

Datum float8_stddev_pop ( PG_FUNCTION_ARGS  )

Definition at line 3318 of file float.c.

3319{
3322 float8 N,
3323 Sxx;
3324
3325 transvalues = check_float8_array(transarray, "float8_stddev_pop", 3);
3326 N = transvalues[0];
3327 /* ignore Sx */
3328 Sxx = transvalues[2];
3329
3330 /* Population stddev is undefined when N is 0, so return NULL */
3331 if (N == 0.0)
3333
3334 /* Note that Sxx is guaranteed to be non-negative */
3335
3337}

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

◆ float8_stddev_samp()

Datum float8_stddev_samp ( PG_FUNCTION_ARGS  )

Definition at line 3340 of file float.c.

3341{
3344 float8 N,
3345 Sxx;
3346
3347 transvalues = check_float8_array(transarray, "float8_stddev_samp", 3);
3348 N = transvalues[0];
3349 /* ignore Sx */
3350 Sxx = transvalues[2];
3351
3352 /* Sample stddev is undefined when N is 0 or 1, so return NULL */
3353 if (N <= 1.0)
3355
3356 /* Note that Sxx is guaranteed to be non-negative */
3357
3358 PG_RETURN_FLOAT8(sqrt(Sxx / (N - 1.0)));
3359}

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

◆ float8_var_pop()

Datum float8_var_pop ( PG_FUNCTION_ARGS  )

Definition at line 3274 of file float.c.

3275{
3278 float8 N,
3279 Sxx;
3280
3281 transvalues = check_float8_array(transarray, "float8_var_pop", 3);
3282 N = transvalues[0];
3283 /* ignore Sx */
3284 Sxx = transvalues[2];
3285
3286 /* Population variance is undefined when N is 0, so return NULL */
3287 if (N == 0.0)
3289
3290 /* Note that Sxx is guaranteed to be non-negative */
3291
3292 PG_RETURN_FLOAT8(Sxx / N);
3293}

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

◆ float8_var_samp()

Datum float8_var_samp ( PG_FUNCTION_ARGS  )

Definition at line 3296 of file float.c.

3297{
3300 float8 N,
3301 Sxx;
3302
3303 transvalues = check_float8_array(transarray, "float8_var_samp", 3);
3304 N = transvalues[0];
3305 /* ignore Sx */
3306 Sxx = transvalues[2];
3307
3308 /* Sample variance is undefined when N is 0 or 1, so return NULL */
3309 if (N <= 1.0)
3311
3312 /* Note that Sxx is guaranteed to be non-negative */
3313
3314 PG_RETURN_FLOAT8(Sxx / (N - 1.0));
3315}

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

◆ float8abs()

Datum float8abs ( PG_FUNCTION_ARGS  )

Definition at line 698 of file float.c.

699{
701
703}

References fb(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

◆ float8div()

Datum float8div ( PG_FUNCTION_ARGS  )

Definition at line 838 of file float.c.

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

◆ float8eq()

Datum float8eq ( PG_FUNCTION_ARGS  )

Definition at line 961 of file float.c.

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

◆ float8ge()

Datum float8ge ( PG_FUNCTION_ARGS  )

Definition at line 1006 of file float.c.

1007{
1010
1012}

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

◆ float8gt()

Datum float8gt ( PG_FUNCTION_ARGS  )

Definition at line 997 of file float.c.

998{
1001
1003}

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

◆ float8in()

Datum float8in ( PG_FUNCTION_ARGS  )

Definition at line 405 of file float.c.

406{
407 char *num = PG_GETARG_CSTRING(0);
408
409 PG_RETURN_FLOAT8(float8in_internal(num, NULL, "double precision", num,
410 fcinfo->context));
411}
float8 float8in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
Definition float.c:436

References fb(), float8in_internal(), PG_GETARG_CSTRING, and PG_RETURN_FLOAT8.

Referenced by numeric_float8().

◆ float8in_internal()

float8 float8in_internal ( char num,
char **  endptr_p,
const char type_name,
const char orig_string,
struct Node escontext 
)

Definition at line 436 of file float.c.

439{
440 double val;
441 char *endptr;
442
443 /* skip leading whitespace */
444 while (*num != '\0' && isspace((unsigned char) *num))
445 num++;
446
447 /*
448 * Check for an empty-string input to begin with, to avoid the vagaries of
449 * strtod() on different platforms.
450 */
451 if (*num == '\0')
452 ereturn(escontext, 0,
454 errmsg("invalid input syntax for type %s: \"%s\"",
455 type_name, orig_string)));
456
457 errno = 0;
458 val = strtod(num, &endptr);
459
460 /* did we not see anything that looks like a double? */
461 if (endptr == num || errno != 0)
462 {
463 int save_errno = errno;
464
465 /*
466 * C99 requires that strtod() accept NaN, [+-]Infinity, and [+-]Inf,
467 * but not all platforms support all of these (and some accept them
468 * but set ERANGE anyway...) Therefore, we check for these inputs
469 * ourselves if strtod() fails.
470 *
471 * Note: C99 also requires hexadecimal input as well as some extended
472 * forms of NaN, but we consider these forms unportable and don't try
473 * to support them. You can use 'em if your strtod() takes 'em.
474 */
475 if (pg_strncasecmp(num, "NaN", 3) == 0)
476 {
478 endptr = num + 3;
479 }
480 else if (pg_strncasecmp(num, "Infinity", 8) == 0)
481 {
483 endptr = num + 8;
484 }
485 else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
486 {
488 endptr = num + 9;
489 }
490 else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
491 {
493 endptr = num + 9;
494 }
495 else if (pg_strncasecmp(num, "inf", 3) == 0)
496 {
498 endptr = num + 3;
499 }
500 else if (pg_strncasecmp(num, "+inf", 4) == 0)
501 {
503 endptr = num + 4;
504 }
505 else if (pg_strncasecmp(num, "-inf", 4) == 0)
506 {
508 endptr = num + 4;
509 }
510 else if (save_errno == ERANGE)
511 {
512 /*
513 * Some platforms return ERANGE for denormalized numbers (those
514 * that are not zero, but are too close to zero to have full
515 * precision). We'd prefer not to throw error for that, so try to
516 * detect whether it's a "real" out-of-range condition by checking
517 * to see if the result is zero or huge.
518 *
519 * On error, we intentionally complain about double precision not
520 * the given type name, and we print only the part of the string
521 * that is the current number.
522 */
523 if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL)
524 {
525 char *errnumber = pstrdup(num);
526
527 errnumber[endptr - num] = '\0';
528 ereturn(escontext, 0,
530 errmsg("\"%s\" is out of range for type double precision",
531 errnumber)));
532 }
533 }
534 else
535 ereturn(escontext, 0,
537 errmsg("invalid input syntax for type %s: \"%s\"",
538 type_name, orig_string)));
539 }
540
541 /* skip trailing whitespace */
542 while (*endptr != '\0' && isspace((unsigned char) *endptr))
543 endptr++;
544
545 /* report stopping point if wanted, else complain if not end of string */
546 if (endptr_p)
547 *endptr_p = endptr;
548 else if (*endptr != '\0')
549 ereturn(escontext, 0,
551 errmsg("invalid input syntax for type %s: \"%s\"",
552 type_name, orig_string)));
553
554 return val;
555}

References ereturn, errcode(), errmsg, fb(), get_float8_infinity(), get_float8_nan(), pg_strncasecmp(), pstrdup(), and val.

Referenced by dependencies_scalar(), executeItemOptUnwrapTarget(), float8in(), and single_decode().

◆ float8larger()

Datum float8larger ( PG_FUNCTION_ARGS  )

Definition at line 728 of file float.c.

729{
733
734 if (float8_gt(arg1, arg2))
735 result = arg1;
736 else
737 result = arg2;
739}

References fb(), float8_gt(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ float8le()

Datum float8le ( PG_FUNCTION_ARGS  )

Definition at line 988 of file float.c.

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

◆ float8lt()

Datum float8lt ( PG_FUNCTION_ARGS  )

Definition at line 979 of file float.c.

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

◆ float8mi()

Datum float8mi ( PG_FUNCTION_ARGS  )

Definition at line 820 of file float.c.

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

◆ float8mul()

Datum float8mul ( PG_FUNCTION_ARGS  )

Definition at line 829 of file float.c.

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

◆ float8ne()

Datum float8ne ( PG_FUNCTION_ARGS  )

Definition at line 970 of file float.c.

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

◆ float8out()

Datum float8out ( PG_FUNCTION_ARGS  )

Definition at line 563 of file float.c.

564{
565 float8 num = PG_GETARG_FLOAT8(0);
566
568}
char * float8out_internal(double num)
Definition float.c:578

References float8out_internal(), PG_GETARG_FLOAT8, and PG_RETURN_CSTRING.

◆ float8out_internal()

char * float8out_internal ( double  num)

Definition at line 578 of file float.c.

579{
580 char *ascii = (char *) palloc(32);
582
583 if (extra_float_digits > 0)
584 {
586 return ascii;
587 }
588
589 (void) pg_strfromd(ascii, 32, ndig, num);
590 return ascii;
591}
int double_to_shortest_decimal_buf(double f, char *result)
Definition d2s.c:1053

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

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

◆ float8pl()

Datum float8pl ( PG_FUNCTION_ARGS  )

Definition at line 811 of file float.c.

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

◆ float8recv()

Datum float8recv ( PG_FUNCTION_ARGS  )

Definition at line 597 of file float.c.

598{
600
602}
float8 pq_getmsgfloat8(StringInfo msg)
Definition pqformat.c:487

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

◆ float8send()

Datum float8send ( PG_FUNCTION_ARGS  )

Definition at line 608 of file float.c.

609{
610 float8 num = PG_GETARG_FLOAT8(0);
612
614 pq_sendfloat8(&buf, num);
616}
void pq_sendfloat8(StringInfo buf, float8 f)
Definition pqformat.c:276

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

◆ float8smaller()

Datum float8smaller ( PG_FUNCTION_ARGS  )

Definition at line 742 of file float.c.

743{
747
748 if (float8_lt(arg1, arg2))
749 result = arg1;
750 else
751 result = arg2;
753}

References fb(), float8_lt(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ float8um()

Datum float8um ( PG_FUNCTION_ARGS  )

Definition at line 710 of file float.c.

711{
714
715 result = -arg1;
717}

References fb(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and result.

◆ float8up()

Datum float8up ( PG_FUNCTION_ARGS  )

Definition at line 720 of file float.c.

721{
723
725}

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

◆ float_overflow_error()

◆ float_overflow_error_ext()

float8 float_overflow_error_ext ( struct Node escontext)

Definition at line 127 of file float.c.

128{
129 ereturn(escontext, 0.0,
131 errmsg("value out of range: overflow"));
132}

References ereturn, errcode(), errmsg, and fb().

Referenced by dtof(), float8_div_safe(), float8_mi_safe(), float8_mul_safe(), and float8_pl_safe().

◆ float_underflow_error()

pg_noinline void float_underflow_error ( void  )

Definition at line 111 of file float.c.

112{
115 errmsg("value out of range: underflow")));
116}

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

Referenced by dcbrt(), dcosh(), dexp(), dgamma(), dlog1(), dlog10(), dpow(), dsqrt(), float4_div(), and float4_mul().

◆ float_underflow_error_ext()

float8 float_underflow_error_ext ( struct Node escontext)

Definition at line 135 of file float.c.

136{
137 ereturn(escontext, 0.0,
139 errmsg("value out of range: underflow"));
140}

References ereturn, errcode(), errmsg, and fb().

Referenced by dtof(), float8_div_safe(), and float8_mul_safe().

◆ float_zero_divide_error()

pg_noinline void float_zero_divide_error ( void  )

Definition at line 119 of file float.c.

120{
123 errmsg("division by zero")));
124}

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

Referenced by float4_div().

◆ float_zero_divide_error_ext()

float8 float_zero_divide_error_ext ( struct Node escontext)

Definition at line 143 of file float.c.

144{
145 ereturn(escontext, 0.0,
147 errmsg("division by zero")));
148}

References ereturn, errcode(), errmsg, and fb().

Referenced by float8_div_safe().

◆ ftod()

Datum ftod ( PG_FUNCTION_ARGS  )

Definition at line 1224 of file float.c.

1225{
1226 float4 num = PG_GETARG_FLOAT4(0);
1227
1228 PG_RETURN_FLOAT8((float8) num);
1229}

References PG_GETARG_FLOAT4, and PG_RETURN_FLOAT8.

◆ ftoi2()

Datum ftoi2 ( PG_FUNCTION_ARGS  )

Definition at line 1354 of file float.c.

1355{
1356 float4 num = PG_GETARG_FLOAT4(0);
1357
1358 /*
1359 * Get rid of any fractional part in the input. This is so we don't fail
1360 * on just-out-of-range values that would round into range. Note
1361 * assumption that rint() will pass through a NaN or Inf unchanged.
1362 */
1363 num = rint(num);
1364
1365 /* Range check */
1366 if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT16(num)))
1367 ereturn(fcinfo->context, (Datum) 0,
1369 errmsg("smallint out of range")));
1370
1371 PG_RETURN_INT16((int16) num);
1372}
#define FLOAT4_FITS_IN_INT16(num)
Definition c.h:1169

References ereturn, errcode(), errmsg, fb(), FLOAT4_FITS_IN_INT16, PG_GETARG_FLOAT4, PG_RETURN_INT16, and unlikely.

◆ ftoi4()

Datum ftoi4 ( PG_FUNCTION_ARGS  )

Definition at line 1329 of file float.c.

1330{
1331 float4 num = PG_GETARG_FLOAT4(0);
1332
1333 /*
1334 * Get rid of any fractional part in the input. This is so we don't fail
1335 * on just-out-of-range values that would round into range. Note
1336 * assumption that rint() will pass through a NaN or Inf unchanged.
1337 */
1338 num = rint(num);
1339
1340 /* Range check */
1341 if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT32(num)))
1342 ereturn(fcinfo->context, (Datum) 0,
1344 errmsg("integer out of range")));
1345
1346 PG_RETURN_INT32((int32) num);
1347}
#define FLOAT4_FITS_IN_INT32(num)
Definition c.h:1171

References ereturn, errcode(), errmsg, fb(), FLOAT4_FITS_IN_INT32, PG_GETARG_FLOAT4, PG_RETURN_INT32, and unlikely.

◆ i2tod()

Datum i2tod ( PG_FUNCTION_ARGS  )

Definition at line 1317 of file float.c.

1318{
1319 int16 num = PG_GETARG_INT16(0);
1320
1321 PG_RETURN_FLOAT8((float8) num);
1322}
#define PG_GETARG_INT16(n)
Definition fmgr.h:271

References PG_GETARG_INT16, and PG_RETURN_FLOAT8.

◆ i2tof()

Datum i2tof ( PG_FUNCTION_ARGS  )

Definition at line 1391 of file float.c.

1392{
1393 int16 num = PG_GETARG_INT16(0);
1394
1395 PG_RETURN_FLOAT4((float4) num);
1396}

References PG_GETARG_INT16, and PG_RETURN_FLOAT4.

◆ i4tod()

Datum i4tod ( PG_FUNCTION_ARGS  )

Definition at line 1305 of file float.c.

1306{
1307 int32 num = PG_GETARG_INT32(0);
1308
1309 PG_RETURN_FLOAT8((float8) num);
1310}
#define PG_GETARG_INT32(n)
Definition fmgr.h:269

References PG_GETARG_INT32, and PG_RETURN_FLOAT8.

◆ i4tof()

Datum i4tof ( PG_FUNCTION_ARGS  )

Definition at line 1379 of file float.c.

1380{
1381 int32 num = PG_GETARG_INT32(0);
1382
1383 PG_RETURN_FLOAT4((float4) num);
1384}

References PG_GETARG_INT32, and PG_RETURN_FLOAT4.

◆ in_range_float4_float8()

Datum in_range_float4_float8 ( PG_FUNCTION_ARGS  )

Definition at line 1144 of file float.c.

1145{
1147 float4 base = PG_GETARG_FLOAT4(1);
1148 float8 offset = PG_GETARG_FLOAT8(2);
1149 bool sub = PG_GETARG_BOOL(3);
1150 bool less = PG_GETARG_BOOL(4);
1151 float8 sum;
1152
1153 /*
1154 * Reject negative or NaN offset. Negative is per spec, and NaN is
1155 * because appropriate semantics for that seem non-obvious.
1156 */
1157 if (isnan(offset) || offset < 0)
1158 ereport(ERROR,
1160 errmsg("invalid preceding or following size in window function")));
1161
1162 /*
1163 * Deal with cases where val and/or base is NaN, following the rule that
1164 * NaN sorts after non-NaN (cf float8_cmp_internal). The offset cannot
1165 * affect the conclusion.
1166 */
1167 if (isnan(val))
1168 {
1169 if (isnan(base))
1170 PG_RETURN_BOOL(true); /* NAN = NAN */
1171 else
1172 PG_RETURN_BOOL(!less); /* NAN > non-NAN */
1173 }
1174 else if (isnan(base))
1175 {
1176 PG_RETURN_BOOL(less); /* non-NAN < NAN */
1177 }
1178
1179 /*
1180 * Deal with cases where both base and offset are infinite, and computing
1181 * base +/- offset would produce NaN. This corresponds to a window frame
1182 * whose boundary infinitely precedes +inf or infinitely follows -inf,
1183 * which is not well-defined. For consistency with other cases involving
1184 * infinities, such as the fact that +inf infinitely follows +inf, we
1185 * choose to assume that +inf infinitely precedes +inf and -inf infinitely
1186 * follows -inf, and therefore that all finite and infinite values are in
1187 * such a window frame.
1188 *
1189 * offset is known positive, so we need only check the sign of base in
1190 * this test.
1191 */
1192 if (isinf(offset) && isinf(base) &&
1193 (sub ? base > 0 : base < 0))
1195
1196 /*
1197 * Otherwise it should be safe to compute base +/- offset. We trust the
1198 * FPU to cope if an input is +/-inf or the true sum would overflow, and
1199 * produce a suitably signed infinity, which will compare properly against
1200 * val whether or not that's infinity.
1201 */
1202 if (sub)
1203 sum = base - offset;
1204 else
1205 sum = base + offset;
1206
1207 if (less)
1208 PG_RETURN_BOOL(val <= sum);
1209 else
1210 PG_RETURN_BOOL(val >= sum);
1211}
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
return true
Definition isn.c:130

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

◆ in_range_float8_float8()

Datum in_range_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 1068 of file float.c.

1069{
1071 float8 base = PG_GETARG_FLOAT8(1);
1072 float8 offset = PG_GETARG_FLOAT8(2);
1073 bool sub = PG_GETARG_BOOL(3);
1074 bool less = PG_GETARG_BOOL(4);
1075 float8 sum;
1076
1077 /*
1078 * Reject negative or NaN offset. Negative is per spec, and NaN is
1079 * because appropriate semantics for that seem non-obvious.
1080 */
1081 if (isnan(offset) || offset < 0)
1082 ereport(ERROR,
1084 errmsg("invalid preceding or following size in window function")));
1085
1086 /*
1087 * Deal with cases where val and/or base is NaN, following the rule that
1088 * NaN sorts after non-NaN (cf float8_cmp_internal). The offset cannot
1089 * affect the conclusion.
1090 */
1091 if (isnan(val))
1092 {
1093 if (isnan(base))
1094 PG_RETURN_BOOL(true); /* NAN = NAN */
1095 else
1096 PG_RETURN_BOOL(!less); /* NAN > non-NAN */
1097 }
1098 else if (isnan(base))
1099 {
1100 PG_RETURN_BOOL(less); /* non-NAN < NAN */
1101 }
1102
1103 /*
1104 * Deal with cases where both base and offset are infinite, and computing
1105 * base +/- offset would produce NaN. This corresponds to a window frame
1106 * whose boundary infinitely precedes +inf or infinitely follows -inf,
1107 * which is not well-defined. For consistency with other cases involving
1108 * infinities, such as the fact that +inf infinitely follows +inf, we
1109 * choose to assume that +inf infinitely precedes +inf and -inf infinitely
1110 * follows -inf, and therefore that all finite and infinite values are in
1111 * such a window frame.
1112 *
1113 * offset is known positive, so we need only check the sign of base in
1114 * this test.
1115 */
1116 if (isinf(offset) && isinf(base) &&
1117 (sub ? base > 0 : base < 0))
1119
1120 /*
1121 * Otherwise it should be safe to compute base +/- offset. We trust the
1122 * FPU to cope if an input is +/-inf or the true sum would overflow, and
1123 * produce a suitably signed infinity, which will compare properly against
1124 * val whether or not that's infinity.
1125 */
1126 if (sub)
1127 sum = base - offset;
1128 else
1129 sum = base + offset;
1130
1131 if (less)
1132 PG_RETURN_BOOL(val <= sum);
1133 else
1134 PG_RETURN_BOOL(val >= sum);
1135}

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

◆ init_degree_constants()

static void init_degree_constants ( void  )
static

◆ is_infinite()

int is_infinite ( double  val)

Definition at line 159 of file float.c.

160{
161 int inf = isinf(val);
162
163 if (inf == 0)
164 return 0;
165 else if (val > 0)
166 return 1;
167 else
168 return -1;
169}

References fb(), and val.

◆ radians()

Datum radians ( PG_FUNCTION_ARGS  )

◆ sind_0_to_30()

static double sind_0_to_30 ( double  x)
static

Definition at line 2293 of file float.c.

2294{
2295 volatile float8 sin_x = sin(x * RADIANS_PER_DEGREE);
2296
2297 return (sin_x / sin_30) / 2.0;
2298}

References fb(), RADIANS_PER_DEGREE, sin_30, and x.

Referenced by cosd_q1(), and sind_q1().

◆ sind_q1()

static double sind_q1 ( double  x)
static

Definition at line 2320 of file float.c.

2321{
2322 /*
2323 * Stitch together the sine and cosine functions for the ranges [0, 30]
2324 * and (30, 90]. These guarantee to return exact answers at their
2325 * endpoints, so the overall result is a continuous monotonic function
2326 * that gives exact results when x = 0, 30 and 90 degrees.
2327 */
2328 if (x <= 30.0)
2329 return sind_0_to_30(x);
2330 else
2331 return cosd_0_to_60(90.0 - x);
2332}

References cosd_0_to_60(), sind_0_to_30(), and x.

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

◆ width_bucket_float8()

Datum width_bucket_float8 ( PG_FUNCTION_ARGS  )

Definition at line 4229 of file float.c.

4230{
4231 float8 operand = PG_GETARG_FLOAT8(0);
4234 int32 count = PG_GETARG_INT32(3);
4235 int32 result;
4236
4237 if (count <= 0)
4238 ereport(ERROR,
4240 errmsg("count must be greater than zero")));
4241
4242 if (isnan(bound1) || isnan(bound2))
4243 ereport(ERROR,
4245 errmsg("lower and upper bounds cannot be NaN")));
4246
4247 if (isinf(bound1) || isinf(bound2))
4248 ereport(ERROR,
4250 errmsg("lower and upper bounds must be finite")));
4251
4252 if (bound1 < bound2)
4253 {
4254 if (isnan(operand) || operand >= bound2)
4255 {
4256 if (pg_add_s32_overflow(count, 1, &result))
4257 ereport(ERROR,
4259 errmsg("integer out of range")));
4260 }
4261 else if (operand < bound1)
4262 result = 0;
4263 else
4264 {
4265 if (!isinf(bound2 - bound1))
4266 {
4267 /* The quotient is surely in [0,1], so this can't overflow */
4268 result = count * ((operand - bound1) / (bound2 - bound1));
4269 }
4270 else
4271 {
4272 /*
4273 * We get here if bound2 - bound1 overflows DBL_MAX. Since
4274 * both bounds are finite, their difference can't exceed twice
4275 * DBL_MAX; so we can perform the computation without overflow
4276 * by dividing all the inputs by 2. That should be exact too,
4277 * except in the case where a very small operand underflows to
4278 * zero, which would have negligible impact on the result
4279 * given such large bounds.
4280 */
4281 result = count * ((operand / 2 - bound1 / 2) / (bound2 / 2 - bound1 / 2));
4282 }
4283 /* The quotient could round to 1.0, which would be a lie */
4284 if (result >= count)
4285 result = count - 1;
4286 /* Having done that, we can add 1 without fear of overflow */
4287 result++;
4288 }
4289 }
4290 else if (bound1 > bound2)
4291 {
4292 if (isnan(operand) || operand > bound1)
4293 result = 0;
4294 else if (operand <= bound2)
4295 {
4296 if (pg_add_s32_overflow(count, 1, &result))
4297 ereport(ERROR,
4299 errmsg("integer out of range")));
4300 }
4301 else
4302 {
4303 if (!isinf(bound1 - bound2))
4304 result = count * ((bound1 - operand) / (bound1 - bound2));
4305 else
4306 result = count * ((bound1 / 2 - operand / 2) / (bound1 / 2 - bound2 / 2));
4307 if (result >= count)
4308 result = count - 1;
4309 result++;
4310 }
4311 }
4312 else
4313 {
4314 ereport(ERROR,
4316 errmsg("lower bound cannot equal upper bound")));
4317 result = 0; /* keep the compiler quiet */
4318 }
4319
4321}
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition int.h:151

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

Variable Documentation

◆ acos_0_5

float8 acos_0_5 = 0
static

Definition at line 64 of file float.c.

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

◆ asin_0_5

float8 asin_0_5 = 0
static

Definition at line 63 of file float.c.

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

◆ atan_1_0

float8 atan_1_0 = 0
static

Definition at line 65 of file float.c.

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

◆ cot_45

float8 cot_45 = 0
static

Definition at line 67 of file float.c.

Referenced by dcotd(), and init_degree_constants().

◆ degree_c_forty_five

float8 degree_c_forty_five = 45.0

Definition at line 84 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_one

float8 degree_c_one = 1.0

Definition at line 87 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_one_half

float8 degree_c_one_half = 0.5

Definition at line 86 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_sixty

float8 degree_c_sixty = 60.0

Definition at line 85 of file float.c.

Referenced by init_degree_constants().

◆ degree_c_thirty

float8 degree_c_thirty = 30.0

Definition at line 83 of file float.c.

Referenced by init_degree_constants().

◆ degree_consts_set

bool degree_consts_set = false
static

Definition at line 60 of file float.c.

Referenced by init_degree_constants().

◆ extra_float_digits

int extra_float_digits = 1

Definition at line 57 of file float.c.

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

◆ one_minus_cos_60

float8 one_minus_cos_60 = 0
static

Definition at line 62 of file float.c.

Referenced by cosd_0_to_60(), and init_degree_constants().

◆ sin_30

float8 sin_30 = 0
static

Definition at line 61 of file float.c.

Referenced by init_degree_constants(), and sind_0_to_30().

◆ tan_45

float8 tan_45 = 0
static

Definition at line 66 of file float.c.

Referenced by dtand(), and init_degree_constants().