From a57d312a7706321d850faa048a562a0c0c01b835 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 22 Jul 2020 19:19:44 -0400 Subject: Support infinity and -infinity in the numeric data type. Add infinities that behave the same as they do in the floating-point data types. Aside from any intrinsic usefulness these may have, this closes an important gap in our ability to convert floating values to numeric and/or replace float-based APIs with numeric. The new values are represented by bit patterns that were formerly not used (although old code probably would take them for NaNs). So there shouldn't be any pg_upgrade hazard. Patch by me, reviewed by Dean Rasheed and Andrew Gierth Discussion: https://postgr.es/m/606717.1591924582@sss.pgh.pa.us --- src/backend/utils/adt/formatting.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/backend/utils/adt/formatting.c') diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index 16768b28c30..66264381366 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -6129,9 +6129,12 @@ numeric_to_char(PG_FUNCTION_ARGS) /* * numeric_out_sci() does not emit a sign for positive numbers. We * need to add a space in this case so that positive and negative - * numbers are aligned. We also have to do the right thing for NaN. + * numbers are aligned. Also must check for NaN/infinity cases, which + * we handle the same way as in float8_to_char. */ - if (strcmp(orgnum, "NaN") == 0) + if (strcmp(orgnum, "NaN") == 0 || + strcmp(orgnum, "Infinity") == 0 || + strcmp(orgnum, "-Infinity") == 0) { /* * Allow 6 characters for the leading sign, the decimal point, @@ -6346,7 +6349,7 @@ int8_to_char(PG_FUNCTION_ARGS) /* * numeric_out_sci() does not emit a sign for positive numbers. We * need to add a space in this case so that positive and negative - * numbers are aligned. We don't have to worry about NaN here. + * numbers are aligned. We don't have to worry about NaN/inf here. */ if (*orgnum != '-') { -- cgit v1.2.3