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

810 {
811  if (float4_gt(a, b))
812  return 1;
813  if (float4_lt(a, b))
814  return -1;
815  return 0;
816 }
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:79
void float_underflow_error(void) pg_attribute_noreturn()
Definition: float.c:87
void float_zero_divide_error(void) pg_attribute_noreturn()
Definition: float.c:95

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

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

904 {
905  if (float8_gt(a, b))
906  return 1;
907  if (float8_lt(a, b))
908  return -1;
909  return 0;
910 }
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 388 of file float.c.

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

531 {
532  char *ascii = (char *) palloc(32);
533  int ndig = DBL_DIG + extra_float_digits;
534 
535  if (extra_float_digits > 0)
536  {
538  return ascii;
539  }
540 
541  (void) pg_strfromd(ascii, 32, ndig, num);
542  return ascii;
543 }
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 79 of file float.c.

80 {
81  ereport(ERROR,
82  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
83  errmsg("value out of range: overflow")));
84 }
#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 87 of file float.c.

88 {
89  ereport(ERROR,
90  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
91  errmsg("value out of range: underflow")));
92 }

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

96 {
97  ereport(ERROR,
98  (errcode(ERRCODE_DIVISION_BY_ZERO),
99  errmsg("division by zero")));
100 }

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

112 {
113  int inf = isinf(val);
114 
115  if (inf == 0)
116  return 0;
117  else if (val > 0)
118  return 1;
119  else
120  return -1;
121 }

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