File: float8out_unit.h

package info (click to toggle)
postgresql-unit 7.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,540 kB
  • sloc: sql: 1,768; ansic: 1,334; lex: 358; yacc: 140; perl: 100; makefile: 40; sh: 25
file content (34 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (4)
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;
}