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, struct Node *escontext)
 
float4 float4in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
 
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.

Function Documentation

◆ float4_cmp_internal()

int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 817 of file float.c.

818 {
819  if (float4_gt(a, b))
820  return 1;
821  if (float4_lt(a, b))
822  return -1;
823  return 0;
824 }
static bool float4_lt(const float4 val1, const float4 val2)
Definition: float.h:286
static bool float4_gt(const float4 val1, const float4 val2)
Definition: float.h:310
int b
Definition: isn.c:70
int a
Definition: isn.c:69

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

Referenced by btfloat4cmp(), and btfloat4fastcmp().

◆ float4_div()

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

Definition at line 222 of file float.h.

223 {
224  float4 result;
225 
226  if (unlikely(val2 == 0.0f) && !isnan(val1))
228  result = val1 / val2;
229  if (unlikely(isinf(result)) && !isinf(val1))
231  if (unlikely(result == 0.0f) && val1 != 0.0f && !isinf(val2))
233 
234  return result;
235 }
#define unlikely(x)
Definition: c.h:311
float float4
Definition: c.h:629
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:87
void float_underflow_error(void) pg_attribute_noreturn()
Definition: float.c:95
void float_zero_divide_error(void) pg_attribute_noreturn()
Definition: float.c:103

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

Referenced by float4div(), and g_box_consider_split().

◆ float4_eq()

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

Definition at line 262 of file float.h.

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

Referenced by float4eq().

◆ float4_ge()

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

Definition at line 322 of file float.h.

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

Referenced by float4ge().

◆ float4_gt()

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

Definition at line 310 of file float.h.

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

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

◆ float4_le()

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

Definition at line 298 of file float.h.

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

Referenced by float4le().

◆ float4_lt()

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

Definition at line 286 of file float.h.

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

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

◆ float4_max()

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

Definition at line 346 of file float.h.

347 {
348  return float4_gt(val1, val2) ? val1 : val2;
349 }

References float4_gt().

◆ float4_mi()

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

Definition at line 170 of file float.h.

171 {
172  float4 result;
173 
174  result = val1 - val2;
175  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
177 
178  return result;
179 }

References float_overflow_error(), and unlikely.

Referenced by float4mi().

◆ float4_min()

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

Definition at line 334 of file float.h.

335 {
336  return float4_lt(val1, val2) ? val1 : val2;
337 }

References float4_lt().

◆ float4_mul()

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

Definition at line 194 of file float.h.

195 {
196  float4 result;
197 
198  result = val1 * val2;
199  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
201  if (unlikely(result == 0.0f) && val1 != 0.0f && val2 != 0.0f)
203 
204  return result;
205 }

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

Referenced by float4mul().

◆ float4_ne()

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

Definition at line 274 of file float.h.

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

Referenced by float4ne().

◆ float4_pl()

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

Definition at line 146 of file float.h.

147 {
148  float4 result;
149 
150  result = val1 + val2;
151  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
153 
154  return result;
155 }

References float_overflow_error(), and unlikely.

Referenced by float4pl().

◆ float4in_internal()

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

Definition at line 184 of file float.c.

187 {
188  float val;
189  char *endptr;
190 
191  /*
192  * endptr points to the first character _after_ the sequence we recognized
193  * as a valid floating point number. orig_string points to the original
194  * input string.
195  */
196 
197  /* skip leading whitespace */
198  while (*num != '\0' && isspace((unsigned char) *num))
199  num++;
200 
201  /*
202  * Check for an empty-string input to begin with, to avoid the vagaries of
203  * strtod() on different platforms.
204  */
205  if (*num == '\0')
206  ereturn(escontext, 0,
207  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
208  errmsg("invalid input syntax for type %s: \"%s\"",
209  type_name, orig_string)));
210 
211  errno = 0;
212  val = strtof(num, &endptr);
213 
214  /* did we not see anything that looks like a double? */
215  if (endptr == num || errno != 0)
216  {
217  int save_errno = errno;
218 
219  /*
220  * C99 requires that strtof() accept NaN, [+-]Infinity, and [+-]Inf,
221  * but not all platforms support all of these (and some accept them
222  * but set ERANGE anyway...) Therefore, we check for these inputs
223  * ourselves if strtof() fails.
224  *
225  * Note: C99 also requires hexadecimal input as well as some extended
226  * forms of NaN, but we consider these forms unportable and don't try
227  * to support them. You can use 'em if your strtof() takes 'em.
228  */
229  if (pg_strncasecmp(num, "NaN", 3) == 0)
230  {
231  val = get_float4_nan();
232  endptr = num + 3;
233  }
234  else if (pg_strncasecmp(num, "Infinity", 8) == 0)
235  {
237  endptr = num + 8;
238  }
239  else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
240  {
242  endptr = num + 9;
243  }
244  else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
245  {
247  endptr = num + 9;
248  }
249  else if (pg_strncasecmp(num, "inf", 3) == 0)
250  {
252  endptr = num + 3;
253  }
254  else if (pg_strncasecmp(num, "+inf", 4) == 0)
255  {
257  endptr = num + 4;
258  }
259  else if (pg_strncasecmp(num, "-inf", 4) == 0)
260  {
262  endptr = num + 4;
263  }
264  else if (save_errno == ERANGE)
265  {
266  /*
267  * Some platforms return ERANGE for denormalized numbers (those
268  * that are not zero, but are too close to zero to have full
269  * precision). We'd prefer not to throw error for that, so try to
270  * detect whether it's a "real" out-of-range condition by checking
271  * to see if the result is zero or huge.
272  */
273  if (val == 0.0 ||
274 #if !defined(HUGE_VALF)
275  isinf(val)
276 #else
277  (val >= HUGE_VALF || val <= -HUGE_VALF)
278 #endif
279  )
280  {
281  /* see comments in float8in_internal for rationale */
282  char *errnumber = pstrdup(num);
283 
284  errnumber[endptr - num] = '\0';
285 
286  ereturn(escontext, 0,
287  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
288  errmsg("\"%s\" is out of range for type real",
289  errnumber)));
290  }
291  }
292  else
293  ereturn(escontext, 0,
294  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
295  errmsg("invalid input syntax for type %s: \"%s\"",
296  type_name, orig_string)));
297  }
298 
299  /* skip trailing whitespace */
300  while (*endptr != '\0' && isspace((unsigned char) *endptr))
301  endptr++;
302 
303  /* report stopping point if wanted, else complain if not end of string */
304  if (endptr_p)
305  *endptr_p = endptr;
306  else if (*endptr != '\0')
307  ereturn(escontext, 0,
308  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
309  errmsg("invalid input syntax for type %s: \"%s\"",
310  type_name, orig_string)));
311 
312  return val;
313 }
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereturn(context, dummy_value,...)
Definition: elog.h:276
static float4 get_float4_infinity(void)
Definition: float.h:74
static float4 get_float4_nan(void)
Definition: float.h:111
long val
Definition: informix.c:670
char * pstrdup(const char *in)
Definition: mcxt.c:1696
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69

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

Referenced by float4in().

◆ float8_cmp_internal()

int float8_cmp_internal ( float8  a,
float8  b 
)

Definition at line 911 of file float.c.

912 {
913  if (float8_gt(a, b))
914  return 1;
915  if (float8_lt(a, b))
916  return -1;
917  return 0;
918 }
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:292
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:316

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

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

◆ float8_div()

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

Definition at line 238 of file float.h.

239 {
240  float8 result;
241 
242  if (unlikely(val2 == 0.0) && !isnan(val1))
244  result = val1 / val2;
245  if (unlikely(isinf(result)) && !isinf(val1))
247  if (unlikely(result == 0.0) && val1 != 0.0 && !isinf(val2))
249 
250  return result;
251 }
double float8
Definition: c.h:630

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

Referenced by box_circle(), box_cn(), cash_div_float8(), 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().

◆ float8_eq()

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

Definition at line 268 of file float.h.

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

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

◆ float8_ge()

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

Definition at line 328 of file float.h.

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

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

◆ float8_gt()

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

Definition at line 316 of file float.h.

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

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

◆ float8_le()

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

Definition at line 304 of file float.h.

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

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

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

353 {
354  return float8_gt(val1, val2) ? val1 : val2;
355 }

References float8_gt().

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

◆ float8_mi()

◆ float8_min()

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

Definition at line 340 of file float.h.

341 {
342  return float8_lt(val1, val2) ? val1 : val2;
343 }

References float8_lt().

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

◆ float8_mul()

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

Definition at line 208 of file float.h.

209 {
210  float8 result;
211 
212  result = val1 * val2;
213  if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))
215  if (unlikely(result == 0.0) && val1 != 0.0 && val2 != 0.0)
217 
218  return result;
219 }

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

Referenced by box_ar(), cash_mul_float8(), 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(), make_interval(), path_area(), point_div_point(), point_mul_point(), radians(), and size_box().

◆ float8_ne()

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

Definition at line 280 of file float.h.

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

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

◆ float8_pl()

◆ float8in_internal()

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

Definition at line 396 of file float.c.

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

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

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

◆ float8out_internal()

char* float8out_internal ( float8  num)

Definition at line 538 of file float.c.

539 {
540  char *ascii = (char *) palloc(32);
541  int ndig = DBL_DIG + extra_float_digits;
542 
543  if (extra_float_digits > 0)
544  {
546  return ascii;
547  }
548 
549  (void) pg_strfromd(ascii, 32, ndig, num);
550  return ascii;
551 }
int double_to_shortest_decimal_buf(double f, char *result)
Definition: d2s.c:1053
int extra_float_digits
Definition: float.c:41
void * palloc(Size size)
Definition: mcxt.c:1317
Datum ascii(PG_FUNCTION_ARGS)
int pg_strfromd(char *str, size_t count, int precision, double value)
Definition: snprintf.c:1285

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

◆ float_overflow_error()

void float_overflow_error ( void  )

Definition at line 87 of file float.c.

88 {
89  ereport(ERROR,
90  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
91  errmsg("value out of range: overflow")));
92 }
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149

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

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

◆ float_underflow_error()

void float_underflow_error ( void  )

Definition at line 95 of file float.c.

96 {
97  ereport(ERROR,
98  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
99  errmsg("value out of range: underflow")));
100 }

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

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

◆ float_zero_divide_error()

void float_zero_divide_error ( void  )

Definition at line 103 of file float.c.

104 {
105  ereport(ERROR,
106  (errcode(ERRCODE_DIVISION_BY_ZERO),
107  errmsg("division by zero")));
108 }

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

Referenced by float4_div(), and float8_div().

◆ get_float4_infinity()

static float4 get_float4_infinity ( void  )
inlinestatic

Definition at line 74 of file float.h.

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

Referenced by float4in_internal(), gistpenalty(), leftmostvalue_float4(), numeric_float4(), and range_gist_penalty().

◆ get_float4_nan()

static float4 get_float4_nan ( void  )
inlinestatic

Definition at line 111 of file float.h.

112 {
113 #ifdef NAN
114  /* C99 standard way */
115  return (float4) NAN;
116 #else
117  /* Assume we can get a NAN via zero divide */
118  return (float4) (0.0 / 0.0);
119 #endif
120 }

Referenced by float4in_internal(), and numeric_float4().

◆ get_float8_infinity()

static float8 get_float8_infinity ( void  )
inlinestatic

Definition at line 94 of file float.h.

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

Referenced by brin_minmax_multi_distance_float4(), brin_minmax_multi_distance_float8(), compute_range_stats(), datanh(), dcosh(), dsinh(), float8in_internal(), gbt_ts_dist(), get_distance(), gistindex_keytest(), initRectBox(), leftmostvalue_float8(), line_invsl(), line_sl(), NonFiniteIntervalPart(), NonFiniteTimestampTzPart(), numeric_float8(), pg_hypot(), point_invsl(), point_sl(), size_box(), spg_kd_inner_consistent(), spg_quad_inner_consistent(), and spgbeginscan().

◆ get_float8_nan()

static float8 get_float8_nan ( void  )
inlinestatic

Definition at line 123 of file float.h.

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

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(), hashfloat4(), hashfloat4extended(), hashfloat8(), hashfloat8extended(), line_closept_point(), numeric_float8(), numeric_float8_no_overflow(), pg_hypot(), and point_box_distance().

◆ is_infinite()

int is_infinite ( float8  val)

Definition at line 119 of file float.c.

120 {
121  int inf = isinf(val);
122 
123  if (inf == 0)
124  return 0;
125  else if (val > 0)
126  return 1;
127  else
128  return -1;
129 }

References val.

Variable Documentation

◆ extra_float_digits

PGDLLIMPORT int extra_float_digits
extern

Definition at line 41 of file float.c.

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