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

816 {
817  if (float4_gt(a, b))
818  return 1;
819  if (float4_lt(a, b))
820  return -1;
821  return 0;
822 }
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:295
float float4
Definition: c.h:613
void float_overflow_error(void) pg_attribute_noreturn()
Definition: float.c:85
void float_underflow_error(void) pg_attribute_noreturn()
Definition: float.c:93
void float_zero_divide_error(void) pg_attribute_noreturn()
Definition: float.c:101

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

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

910 {
911  if (float8_gt(a, b))
912  return 1;
913  if (float8_lt(a, b))
914  return -1;
915  return 0;
916 }
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:614

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

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

◆ 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 394 of file float.c.

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

537 {
538  char *ascii = (char *) palloc(32);
539  int ndig = DBL_DIG + extra_float_digits;
540 
541  if (extra_float_digits > 0)
542  {
544  return ascii;
545  }
546 
547  (void) pg_strfromd(ascii, 32, ndig, num);
548  return ascii;
549 }
int double_to_shortest_decimal_buf(double f, char *result)
Definition: d2s.c:1053
int extra_float_digits
Definition: float.c:43
void * palloc(Size size)
Definition: mcxt.c:1226
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 85 of file float.c.

86 {
87  ereport(ERROR,
88  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
89  errmsg("value out of range: overflow")));
90 }
#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 93 of file float.c.

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

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

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

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(), 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 117 of file float.c.

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

References val.

Variable Documentation

◆ extra_float_digits

PGDLLIMPORT int extra_float_digits
extern

Definition at line 43 of file float.c.

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