PostgreSQL Source Code  git master
float.h File Reference
#include <math.h>
Include dependency graph for float.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define M_PI   3.14159265358979323846
 
#define RADIANS_PER_DEGREE   0.0174532925199432957692
 

Functions

int is_infinite (float8 val)
 
float8 float8in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string)
 
float8 float8in_internal_opt_error (char *num, char **endptr_p, const char *type_name, const char *orig_string, bool *have_error)
 
char * float8out_internal (float8 num)
 
int float4_cmp_internal (float4 a, float4 b)
 
int float8_cmp_internal (float8 a, float8 b)
 
static float4 get_float4_infinity (void)
 
static float8 get_float8_infinity (void)
 
static float4 get_float4_nan (void)
 
static float8 get_float8_nan (void)
 
static void check_float4_val (const float4 val, const bool inf_is_valid, const bool zero_is_valid)
 
static void check_float8_val (const float8 val, const bool inf_is_valid, const bool zero_is_valid)
 
static float4 float4_pl (const float4 val1, const float4 val2)
 
static float8 float8_pl (const float8 val1, const float8 val2)
 
static float4 float4_mi (const float4 val1, const float4 val2)
 
static float8 float8_mi (const float8 val1, const float8 val2)
 
static float4 float4_mul (const float4 val1, const float4 val2)
 
static float8 float8_mul (const float8 val1, const float8 val2)
 
static float4 float4_div (const float4 val1, const float4 val2)
 
static float8 float8_div (const float8 val1, const float8 val2)
 
static bool float4_eq (const float4 val1, const float4 val2)
 
static bool float8_eq (const float8 val1, const float8 val2)
 
static bool float4_ne (const float4 val1, const float4 val2)
 
static bool float8_ne (const float8 val1, const float8 val2)
 
static bool float4_lt (const float4 val1, const float4 val2)
 
static bool float8_lt (const float8 val1, const float8 val2)
 
static bool float4_le (const float4 val1, const float4 val2)
 
static bool float8_le (const float8 val1, const float8 val2)
 
static bool float4_gt (const float4 val1, const float4 val2)
 
static bool float8_gt (const float8 val1, const float8 val2)
 
static bool float4_ge (const float4 val1, const float4 val2)
 
static bool float8_ge (const float8 val1, const float8 val2)
 
static float4 float4_min (const float4 val1, const float4 val2)
 
static float8 float8_min (const float8 val1, const float8 val2)
 
static float4 float4_max (const float4 val1, const float4 val2)
 
static float8 float8_max (const float8 val1, const float8 val2)
 

Variables

PGDLLIMPORT int extra_float_digits
 

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 22 of file float.h.

◆ RADIANS_PER_DEGREE

#define RADIANS_PER_DEGREE   0.0174532925199432957692

Definition at line 26 of file float.h.

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

Function Documentation

◆ check_float4_val()

static void check_float4_val ( const float4  val,
const bool  inf_is_valid,
const bool  zero_is_valid 
)
inlinestatic

Definition at line 136 of file float.h.

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

Referenced by dtof(), float4_div(), float4_mi(), float4_mul(), and float4_pl().

138 {
139  if (!inf_is_valid && unlikely(isinf(val)))
140  ereport(ERROR,
141  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
142  errmsg("value out of range: overflow")));
143 
144  if (!zero_is_valid && unlikely(val == 0.0))
145  ereport(ERROR,
146  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
147  errmsg("value out of range: underflow")));
148 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208
long val
Definition: informix.c:684

◆ check_float8_val()

static void check_float8_val ( const float8  val,
const bool  inf_is_valid,
const bool  zero_is_valid 
)
inlinestatic

Definition at line 151 of file float.h.

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

Referenced by dacos(), dacosd(), dacosh(), dasin(), dasind(), dasinh(), datan(), datan2(), datan2d(), datand(), datanh(), dcbrt(), dcos(), dcosd(), dcosh(), dcot(), dcotd(), dexp(), dlog1(), dlog10(), dpow(), dsin(), dsind(), dsinh(), dsqrt(), dtan(), dtand(), dtanh(), float8_combine(), float8_div(), float8_mi(), float8_mul(), float8_pl(), float8_regr_combine(), and pg_hypot().

153 {
154  if (!inf_is_valid && unlikely(isinf(val)))
155  ereport(ERROR,
156  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
157  errmsg("value out of range: overflow")));
158 
159  if (!zero_is_valid && unlikely(val == 0.0))
160  ereport(ERROR,
161  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
162  errmsg("value out of range: underflow")));
163 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define unlikely(x)
Definition: c.h:208
long val
Definition: informix.c:684

◆ float4_cmp_internal()

int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 825 of file float.c.

References float4_gt(), and float4_lt().

Referenced by btfloat4cmp(), and btfloat4fastcmp().

826 {
827  if (float4_gt(a, b))
828  return 1;
829  if (float4_lt(a, b))
830  return -1;
831  return 0;
832 }
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:332
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:308

◆ float4_div()

static float4 float4_div ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 244 of file float.h.

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

Referenced by float4div(), and g_box_consider_split().

245 {
246  float4 result;
247 
248  if (val2 == 0.0f)
249  ereport(ERROR,
250  (errcode(ERRCODE_DIVISION_BY_ZERO),
251  errmsg("division by zero")));
252 
253  result = val1 / val2;
254  check_float4_val(result, isinf(val1) || isinf(val2), val1 == 0.0f);
255 
256  return result;
257 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
static void check_float4_val(const float4 val, const bool inf_is_valid, const bool zero_is_valid)
Definition: float.h:136
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:141
float float4
Definition: c.h:491
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ float4_eq()

static bool float4_eq ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 284 of file float.h.

Referenced by float4eq().

285 {
286  return isnan(val1) ? isnan(val2) : !isnan(val2) && val1 == val2;
287 }

◆ float4_ge()

static bool float4_ge ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 344 of file float.h.

Referenced by float4ge().

345 {
346  return isnan(val1) || (!isnan(val2) && val1 >= val2);
347 }

◆ float4_gt()

static bool float4_gt ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 332 of file float.h.

Referenced by float4_cmp_internal(), float4_max(), float4gt(), and float4larger().

333 {
334  return !isnan(val2) && (isnan(val1) || val1 > val2);
335 }

◆ float4_le()

static bool float4_le ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 320 of file float.h.

Referenced by float4le().

321 {
322  return isnan(val2) || (!isnan(val1) && val1 <= val2);
323 }

◆ float4_lt()

static bool float4_lt ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 308 of file float.h.

Referenced by float4_cmp_internal(), float4_min(), float4lt(), and float4smaller().

309 {
310  return !isnan(val1) && (isnan(val2) || val1 < val2);
311 }

◆ float4_max()

static float4 float4_max ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 368 of file float.h.

References float4_gt().

369 {
370  return float4_gt(val1, val2) ? val1 : val2;
371 }
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:332

◆ float4_mi()

static float4 float4_mi ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 198 of file float.h.

References check_float4_val(), and isinf().

Referenced by float4mi().

199 {
200  float4 result;
201 
202  result = val1 - val2;
203  check_float4_val(result, isinf(val1) || isinf(val2), true);
204 
205  return result;
206 }
static void check_float4_val(const float4 val, const bool inf_is_valid, const bool zero_is_valid)
Definition: float.h:136
int isinf(double x)
float float4
Definition: c.h:491

◆ float4_min()

static float4 float4_min ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 356 of file float.h.

References float4_lt().

357 {
358  return float4_lt(val1, val2) ? val1 : val2;
359 }
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:308

◆ float4_mul()

static float4 float4_mul ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 220 of file float.h.

References check_float4_val(), and isinf().

Referenced by float4mul().

221 {
222  float4 result;
223 
224  result = val1 * val2;
225  check_float4_val(result, isinf(val1) || isinf(val2),
226  val1 == 0.0f || val2 == 0.0f);
227 
228  return result;
229 }
static void check_float4_val(const float4 val, const bool inf_is_valid, const bool zero_is_valid)
Definition: float.h:136
int isinf(double x)
float float4
Definition: c.h:491

◆ float4_ne()

static bool float4_ne ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 296 of file float.h.

Referenced by float4ne().

297 {
298  return isnan(val1) ? !isnan(val2) : isnan(val2) || val1 != val2;
299 }

◆ float4_pl()

static float4 float4_pl ( const float4  val1,
const float4  val2 
)
inlinestatic

Definition at line 176 of file float.h.

References check_float4_val(), and isinf().

Referenced by float4pl().

177 {
178  float4 result;
179 
180  result = val1 + val2;
181  check_float4_val(result, isinf(val1) || isinf(val2), true);
182 
183  return result;
184 }
static void check_float4_val(const float4 val, const bool inf_is_valid, const bool zero_is_valid)
Definition: float.h:136
int isinf(double x)
float float4
Definition: c.h:491

◆ float8_cmp_internal()

int float8_cmp_internal ( float8  a,
float8  b 
)

Definition at line 919 of file float.c.

References float8_gt(), and float8_lt().

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

920 {
921  if (float8_gt(a, b))
922  return 1;
923  if (float8_lt(a, b))
924  return -1;
925  return 0;
926 }
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:338

◆ float8_div()

static float8 float8_div ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 260 of file float.h.

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

Referenced by box_circle(), box_cn(), circle_box(), circle_div_pt(), circle_poly(), degrees(), float48div(), float84div(), float8div(), g_box_consider_split(), line_distance(), line_eq(), line_interpt_line(), line_invsl(), line_perp(), line_sl(), lseg_center(), lseg_inside_poly(), path_area(), point_div_point(), point_invsl(), point_sl(), and poly_to_circle().

261 {
262  float8 result;
263 
264  if (val2 == 0.0)
265  ereport(ERROR,
266  (errcode(ERRCODE_DIVISION_BY_ZERO),
267  errmsg("division by zero")));
268 
269  result = val1 / val2;
270  check_float8_val(result, isinf(val1) || isinf(val2), val1 == 0.0);
271 
272  return result;
273 }
int errcode(int sqlerrcode)
Definition: elog.c:608
static void check_float8_val(const float8 val, const bool inf_is_valid, const bool zero_is_valid)
Definition: float.h:151
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:492
int isinf(double x)
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ float8_eq()

static bool float8_eq ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 290 of file float.h.

Referenced by float48eq(), float84eq(), float8eq(), gist_box_picksplit(), gist_box_same(), line_eq(), and point_eq_point().

291 {
292  return isnan(val1) ? isnan(val2) : !isnan(val2) && val1 == val2;
293 }

◆ float8_ge()

static bool float8_ge ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 350 of file float.h.

Referenced by float48ge(), float84ge(), float8ge(), and gist_box_picksplit().

351 {
352  return isnan(val1) || (!isnan(val2) && val1 >= val2);
353 }

◆ float8_gt()

static bool float8_gt ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 338 of file float.h.

Referenced by adjustBox(), box_construct(), float48gt(), float84gt(), float8_cmp_internal(), float8_max(), float8gt(), float8larger(), gist_box_picksplit(), and make_bound_box().

339 {
340  return !isnan(val2) && (isnan(val1) || val1 > val2);
341 }

◆ float8_le()

static bool float8_le ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 326 of file float.h.

Referenced by float48le(), float84le(), float8le(), gist_box_picksplit(), and size_box().

327 {
328  return isnan(val2) || (!isnan(val1) && val1 <= val2);
329 }

◆ float8_lt()

static bool float8_lt ( const float8  val1,
const float8  val2 
)
inlinestatic

◆ float8_max()

static float8 float8_max ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 374 of file float.h.

References float8_gt().

Referenced by box_interpt_lseg(), box_intersect(), boxes_bound_box(), path_inter(), and rt_box_union().

375 {
376  return float8_gt(val1, val2) ? val1 : val2;
377 }
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:338

◆ float8_mi()

static float8 float8_mi ( const float8  val1,
const float8  val2 
)
inlinestatic

◆ float8_min()

static float8 float8_min ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 362 of file float.h.

References float8_lt().

Referenced by box_interpt_lseg(), box_intersect(), boxes_bound_box(), path_inter(), and rt_box_union().

363 {
364  return float8_lt(val1, val2) ? val1 : val2;
365 }
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314

◆ float8_mul()

static float8 float8_mul ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 232 of file float.h.

References check_float8_val(), and isinf().

Referenced by box_ar(), circle_ar(), circle_diameter(), circle_mul_pt(), circle_poly(), float48mul(), float84mul(), float8mul(), line_construct(), line_contain_point(), line_distance(), line_eq(), line_interpt_line(), line_perp(), lseg_crossing(), path_area(), point_div_point(), point_mul_point(), radians(), and size_box().

233 {
234  float8 result;
235 
236  result = val1 * val2;
237  check_float8_val(result, isinf(val1) || isinf(val2),
238  val1 == 0.0 || val2 == 0.0);
239 
240  return result;
241 }
static void check_float8_val(const float8 val, const bool inf_is_valid, const bool zero_is_valid)
Definition: float.h:151
double float8
Definition: c.h:492
int isinf(double x)

◆ float8_ne()

static bool float8_ne ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 302 of file float.h.

Referenced by float48ne(), float84ne(), and float8ne().

303 {
304  return isnan(val1) ? !isnan(val2) : isnan(val2) || val1 != val2;
305 }

◆ float8_pl()

static float8 float8_pl ( const float8  val1,
const float8  val2 
)
inlinestatic

Definition at line 187 of file float.h.

References check_float8_val(), and isinf().

Referenced by box_circle(), box_cn(), circle_above(), circle_below(), circle_box(), circle_distance(), circle_left(), circle_overbelow(), circle_overlap(), circle_overleft(), circle_poly(), circle_right(), float48pl(), float84pl(), float8_combine(), float8_regr_combine(), float8pl(), gist_circle_compress(), gist_circle_consistent(), line_contain_point(), line_interpt_line(), lseg_center(), lseg_inside_poly(), on_ppath(), path_area(), path_length(), point_add_point(), point_div_point(), point_mul_point(), and poly_to_circle().

188 {
189  float8 result;
190 
191  result = val1 + val2;
192  check_float8_val(result, isinf(val1) || isinf(val2), true);
193 
194  return result;
195 }
static void check_float8_val(const float8 val, const bool inf_is_valid, const bool zero_is_valid)
Definition: float.h:151
double float8
Definition: c.h:492
int isinf(double x)

◆ float8in_internal()

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

Definition at line 518 of file float.c.

References float8in_internal_opt_error().

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

520 {
521  return float8in_internal_opt_error(num, endptr_p, type_name,
522  orig_string, NULL);
523 }
double float8in_internal_opt_error(char *num, char **endptr_p, const char *type_name, const char *orig_string, bool *have_error)
Definition: float.c:372

◆ float8in_internal_opt_error()

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

Definition at line 372 of file float.c.

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

Referenced by executeItemOptUnwrapTarget(), and float8in_internal().

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

◆ float8out_internal()

char* float8out_internal ( float8  num)

Definition at line 546 of file float.c.

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

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

547 {
548  char *ascii = (char *) palloc(32);
549  int ndig = DBL_DIG + extra_float_digits;
550 
551  if (extra_float_digits > 0)
552  {
553  double_to_shortest_decimal_buf(num, ascii);
554  return ascii;
555  }
556 
557  (void) pg_strfromd(ascii, 32, ndig, num);
558  return ascii;
559 }
Datum ascii(PG_FUNCTION_ARGS)
int pg_strfromd(char *str, size_t count, int precision, double value)
Definition: snprintf.c:1265
int extra_float_digits
Definition: float.c:42
int double_to_shortest_decimal_buf(double f, char *result)
Definition: d2s.c:1053
void * palloc(Size size)
Definition: mcxt.c:949

◆ get_float4_infinity()

static float4 get_float4_infinity ( void  )
inlinestatic

Definition at line 70 of file float.h.

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

71 {
72 #ifdef INFINITY
73  /* C99 standard way */
74  return (float4) INFINITY;
75 #else
76 #ifdef _MSC_VER
77 #pragma warning(default:4756)
78 #endif
79 
80  /*
81  * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
82  * largest normal float8. We assume forcing an overflow will get us a
83  * true infinity.
84  */
85  return (float4) (HUGE_VAL * HUGE_VAL);
86 #endif
87 }
float float4
Definition: c.h:491

◆ get_float4_nan()

static float4 get_float4_nan ( void  )
inlinestatic

Definition at line 107 of file float.h.

Referenced by float4in(), and numeric_float4().

108 {
109 #ifdef NAN
110  /* C99 standard way */
111  return (float4) NAN;
112 #else
113  /* Assume we can get a NAN via zero divide */
114  return (float4) (0.0 / 0.0);
115 #endif
116 }
float float4
Definition: c.h:491

◆ get_float8_infinity()

static float8 get_float8_infinity ( void  )
inlinestatic

Definition at line 90 of file float.h.

Referenced by compute_range_stats(), datanh(), dcosh(), dexp(), dpow(), dsinh(), float8in_internal_opt_error(), gbt_ts_dist(), get_distance(), gistindex_keytest(), initRectBox(), leftmostvalue_float8(), NonFiniteTimestampTzPart(), pg_hypot(), size_box(), spg_kd_inner_consistent(), spg_quad_inner_consistent(), and spgbeginscan().

91 {
92 #ifdef INFINITY
93  /* C99 standard way */
94  return (float8) INFINITY;
95 #else
96 
97  /*
98  * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
99  * largest normal float8. We assume forcing an overflow will get us a
100  * true infinity.
101  */
102  return (float8) (HUGE_VAL * HUGE_VAL);
103 #endif
104 }
double float8
Definition: c.h:492

◆ get_float8_nan()

static float8 get_float8_nan ( void  )
inlinestatic

Definition at line 119 of file float.h.

Referenced by dacos(), dacosd(), dasin(), dasind(), datan(), datan2(), datan2d(), datand(), dcos(), dcosd(), dcot(), dcotd(), dpow(), dsin(), dsind(), dtan(), dtand(), float4_accum(), float8_accum(), float8_regr_accum(), float8in_internal_opt_error(), line_closept_point(), numeric_float8(), numeric_float8_no_overflow(), pg_hypot(), and point_box_distance().

120 {
121  /* (float8) NAN doesn't work on some NetBSD/MIPS releases */
122 #if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__))
123  /* C99 standard way */
124  return (float8) NAN;
125 #else
126  /* Assume we can get a NaN via zero divide */
127  return (float8) (0.0 / 0.0);
128 #endif
129 }
double float8
Definition: c.h:492

◆ is_infinite()

int is_infinite ( float8  val)

Definition at line 97 of file float.c.

References isinf().

98 {
99  int inf = isinf(val);
100 
101  if (inf == 0)
102  return 0;
103  else if (val > 0)
104  return 1;
105  else
106  return -1;
107 }
int isinf(double x)
long val
Definition: informix.c:684

Variable Documentation

◆ extra_float_digits

PGDLLIMPORT int extra_float_digits

Definition at line 42 of file float.c.

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