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

pg_noreturn void float_overflow_error (void)
 
pg_noreturn void float_underflow_error (void)
 
pg_noreturn void float_zero_divide_error (void)
 
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 816 of file float.c.

817{
818 if (float4_gt(a, b))
819 return 1;
820 if (float4_lt(a, b))
821 return -1;
822 return 0;
823}
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:71
int a
Definition: isn.c:70

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:347
float float4
Definition: c.h:600
pg_noreturn void float_overflow_error(void)
Definition: float.c:86
pg_noreturn void float_underflow_error(void)
Definition: float.c:94
pg_noreturn void float_zero_divide_error(void)
Definition: float.c:102

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

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

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

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

398{
399 double val;
400 char *endptr;
401
402 /* skip leading whitespace */
403 while (*num != '\0' && isspace((unsigned char) *num))
404 num++;
405
406 /*
407 * Check for an empty-string input to begin with, to avoid the vagaries of
408 * strtod() on different platforms.
409 */
410 if (*num == '\0')
411 ereturn(escontext, 0,
412 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
413 errmsg("invalid input syntax for type %s: \"%s\"",
414 type_name, orig_string)));
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 {
437 endptr = num + 3;
438 }
439 else if (pg_strncasecmp(num, "Infinity", 8) == 0)
440 {
442 endptr = num + 8;
443 }
444 else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
445 {
447 endptr = num + 9;
448 }
449 else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
450 {
452 endptr = num + 9;
453 }
454 else if (pg_strncasecmp(num, "inf", 3) == 0)
455 {
457 endptr = num + 3;
458 }
459 else if (pg_strncasecmp(num, "+inf", 4) == 0)
460 {
462 endptr = num + 4;
463 }
464 else if (pg_strncasecmp(num, "-inf", 4) == 0)
465 {
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';
487 ereturn(escontext, 0,
488 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
489 errmsg("\"%s\" is out of range for type double precision",
490 errnumber)));
491 }
492 }
493 else
494 ereturn(escontext, 0,
495 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
496 errmsg("invalid input syntax for type %s: \"%s\"",
497 type_name, orig_string)));
498 }
499
500 /* skip trailing whitespace */
501 while (*endptr != '\0' && isspace((unsigned char) *endptr))
502 endptr++;
503
504 /* report stopping point if wanted, else complain if not end of string */
505 if (endptr_p)
506 *endptr_p = endptr;
507 else if (*endptr != '\0')
508 ereturn(escontext, 0,
509 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
510 errmsg("invalid input syntax for type %s: \"%s\"",
511 type_name, orig_string)));
512
513 return val;
514}
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 537 of file float.c.

538{
539 char *ascii = (char *) palloc(32);
540 int ndig = DBL_DIG + extra_float_digits;
541
542 if (extra_float_digits > 0)
543 {
545 return ascii;
546 }
547
548 (void) pg_strfromd(ascii, 32, ndig, num);
549 return ascii;
550}
int double_to_shortest_decimal_buf(double f, char *result)
Definition: d2s.c:1053
int extra_float_digits
Definition: float.c:40
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:1321

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

pg_noreturn void float_overflow_error ( void  )

◆ float_underflow_error()

pg_noreturn void float_underflow_error ( void  )

Definition at line 94 of file float.c.

95{
97 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
98 errmsg("value out of range: underflow")));
99}

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

pg_noreturn void float_zero_divide_error ( void  )

Definition at line 102 of file float.c.

103{
105 (errcode(ERRCODE_DIVISION_BY_ZERO),
106 errmsg("division by zero")));
107}

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

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

References val.

Variable Documentation

◆ extra_float_digits

PGDLLIMPORT int extra_float_digits
extern

Definition at line 40 of file float.c.

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