-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfloat8out_unit.h
More file actions
34 lines (28 loc) · 773 Bytes
/
float8out_unit.h
File metadata and controls
34 lines (28 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* minimal version of PG 9.6's float8out_internal function for use in 9.4 and 9.5 */
/* With the adaption of ryn in PG 12, it is now used for all versions */
#define MAXDOUBLEWIDTH 128
extern int extra_float_digits;
static char *
float8out_unit(double num)
{
char *ascii = (char *) palloc(MAXDOUBLEWIDTH + 1);
int extradigits =
#if PG_VERSION_NUM >= 120000
extra_float_digits == 1 ? 0 : extra_float_digits;
#else
extra_float_digits;
#endif
int ndig = DBL_DIG + extradigits;
if (isnan(num))
return strcpy(ascii, "NaN");
if (!isfinite(num)) {
if (num > 0)
return strcpy(ascii, "Infinity");
else
return strcpy(ascii, "-Infinity");
}
if (ndig < 1)
ndig = 1;
snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num);
return ascii;
}