1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-31 17:02:12 +03:00

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
This commit is contained in:
Tom Lane
2020-07-22 19:19:44 -04:00
parent 9e108984fb
commit a57d312a77
12 changed files with 2252 additions and 381 deletions

View File

@@ -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 != '-')
{

File diff suppressed because it is too large Load Diff