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

void float_overflow_error (void) pg_attribute_noreturn()
 
void float_underflow_error (void) pg_attribute_noreturn()
 
void float_zero_divide_error (void) pg_attribute_noreturn()
 
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 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

◆ float4_cmp_internal()

int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 844 of file float.c.

References float4_gt(), and float4_lt().

Referenced by btfloat4cmp(), and btfloat4fastcmp().

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

◆ float4_div()

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

Definition at line 221 of file float.h.

References float_overflow_error(), float_underflow_error(), float_zero_divide_error(), and unlikely.

Referenced by float4div(), and g_box_consider_split().

222 {
223  float4 result;
224 
225  if (unlikely(val2 == 0.0f))
227  result = val1 / val2;
228  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
230  if (unlikely(result == 0.0f) && val1 != 0.0f)
232 
233  return result;
234 }
void float_zero_divide_error(void) pg_attribute_noreturn()
Definition: float.c:100
float float4
Definition: c.h:490
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:84
void float_underflow_error(void) pg_attribute_noreturn()
Definition: float.c:92
#define unlikely(x)
Definition: c.h:206

◆ float4_eq()

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

Definition at line 261 of file float.h.

Referenced by float4eq().

262 {
263  return isnan(val1) ? isnan(val2) : !isnan(val2) && val1 == val2;
264 }

◆ float4_ge()

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

Definition at line 321 of file float.h.

Referenced by float4ge().

322 {
323  return isnan(val1) || (!isnan(val2) && val1 >= val2);
324 }

◆ float4_gt()

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

Definition at line 309 of file float.h.

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

310 {
311  return !isnan(val2) && (isnan(val1) || val1 > val2);
312 }

◆ float4_le()

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

Definition at line 297 of file float.h.

Referenced by float4le().

298 {
299  return isnan(val2) || (!isnan(val1) && val1 <= val2);
300 }

◆ float4_lt()

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

Definition at line 285 of file float.h.

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

286 {
287  return !isnan(val1) && (isnan(val2) || val1 < val2);
288 }

◆ float4_max()

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

Definition at line 345 of file float.h.

References float4_gt().

346 {
347  return float4_gt(val1, val2) ? val1 : val2;
348 }
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:309

◆ float4_mi()

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

Definition at line 169 of file float.h.

References float_overflow_error(), and unlikely.

Referenced by float4mi().

170 {
171  float4 result;
172 
173  result = val1 - val2;
174  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
176 
177  return result;
178 }
float float4
Definition: c.h:490
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ float4_min()

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

Definition at line 333 of file float.h.

References float4_lt().

334 {
335  return float4_lt(val1, val2) ? val1 : val2;
336 }
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:285

◆ float4_mul()

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

Definition at line 193 of file float.h.

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

Referenced by float4mul().

194 {
195  float4 result;
196 
197  result = val1 * val2;
198  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
200  if (unlikely(result == 0.0f) && val1 != 0.0f && val2 != 0.0f)
202 
203  return result;
204 }
float float4
Definition: c.h:490
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:84
void float_underflow_error(void) pg_attribute_noreturn()
Definition: float.c:92
#define unlikely(x)
Definition: c.h:206

◆ float4_ne()

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

Definition at line 273 of file float.h.

Referenced by float4ne().

274 {
275  return isnan(val1) ? !isnan(val2) : isnan(val2) || val1 != val2;
276 }

◆ float4_pl()

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

Definition at line 145 of file float.h.

References float_overflow_error(), and unlikely.

Referenced by float4pl().

146 {
147  float4 result;
148 
149  result = val1 + val2;
150  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
152 
153  return result;
154 }
float float4
Definition: c.h:490
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ float8_cmp_internal()

int float8_cmp_internal ( float8  a,
float8  b 
)

Definition at line 938 of file float.c.

References float8_gt(), and float8_lt().

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

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

◆ float8_div()

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

Definition at line 237 of file float.h.

References float_overflow_error(), float_underflow_error(), float_zero_divide_error(), and unlikely.

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

238 {
239  float8 result;
240 
241  if (unlikely(val2 == 0.0))
243  result = val1 / val2;
244  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
246  if (unlikely(result == 0.0) && val1 != 0.0)
248 
249  return result;
250 }
void float_zero_divide_error(void) pg_attribute_noreturn()
Definition: float.c:100
double float8
Definition: c.h:491
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:84
void float_underflow_error(void) pg_attribute_noreturn()
Definition: float.c:92
#define unlikely(x)
Definition: c.h:206

◆ float8_eq()

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

Definition at line 267 of file float.h.

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

268 {
269  return isnan(val1) ? isnan(val2) : !isnan(val2) && val1 == val2;
270 }

◆ float8_ge()

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

Definition at line 327 of file float.h.

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

328 {
329  return isnan(val1) || (!isnan(val2) && val1 >= val2);
330 }

◆ float8_gt()

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

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

316 {
317  return !isnan(val2) && (isnan(val1) || val1 > val2);
318 }

◆ float8_le()

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

Definition at line 303 of file float.h.

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

304 {
305  return isnan(val2) || (!isnan(val1) && val1 <= val2);
306 }

◆ 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 351 of file float.h.

References float8_gt().

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

352 {
353  return float8_gt(val1, val2) ? val1 : val2;
354 }
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315

◆ 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 339 of file float.h.

References float8_lt().

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

340 {
341  return float8_lt(val1, val2) ? val1 : val2;
342 }
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291

◆ float8_mul()

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

Definition at line 207 of file float.h.

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

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

208 {
209  float8 result;
210 
211  result = val1 * val2;
212  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
214  if (unlikely(result == 0.0) && val1 != 0.0 && val2 != 0.0)
216 
217  return result;
218 }
double float8
Definition: c.h:491
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:84
void float_underflow_error(void) pg_attribute_noreturn()
Definition: float.c:92
#define unlikely(x)
Definition: c.h:206

◆ float8_ne()

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

Definition at line 279 of file float.h.

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

280 {
281  return isnan(val1) ? !isnan(val2) : isnan(val2) || val1 != val2;
282 }

◆ float8_pl()

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

Definition at line 157 of file float.h.

References float_overflow_error(), and unlikely.

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

158 {
159  float8 result;
160 
161  result = val1 + val2;
162  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
164 
165  return result;
166 }
double float8
Definition: c.h:491
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:84
#define unlikely(x)
Definition: c.h:206

◆ float8in_internal()

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

Definition at line 537 of file float.c.

References float8in_internal_opt_error().

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

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

◆ float8in_internal_opt_error()

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

Definition at line 391 of file float.c.

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

Referenced by executeItemOptUnwrapTarget(), and float8in_internal().

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

◆ float8out_internal()

char* float8out_internal ( float8  num)

Definition at line 565 of file float.c.

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

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

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

◆ float_overflow_error()

void float_overflow_error ( void  )

Definition at line 84 of file float.c.

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

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

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

◆ float_underflow_error()

void float_underflow_error ( void  )

Definition at line 92 of file float.c.

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

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

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

◆ float_zero_divide_error()

void float_zero_divide_error ( void  )

Definition at line 100 of file float.c.

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

Referenced by float4_div(), and float8_div().

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

◆ get_float4_infinity()

static float4 get_float4_infinity ( void  )
inlinestatic

Definition at line 73 of file float.h.

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

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

◆ get_float4_nan()

static float4 get_float4_nan ( void  )
inlinestatic

Definition at line 110 of file float.h.

Referenced by float4in(), and numeric_float4().

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

◆ get_float8_infinity()

static float8 get_float8_infinity ( void  )
inlinestatic

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

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

◆ get_float8_nan()

static float8 get_float8_nan ( void  )
inlinestatic

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

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

◆ is_infinite()

int is_infinite ( float8  val)

Definition at line 116 of file float.c.

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

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