mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Expose internal function for converting int64 to numeric
Existing callers had to take complicated detours via DirectFunctionCall1(). This simplifies a lot of code. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/42b73d2d-da12-ba9f-570a-420e0cce19d9@phystech.edu
This commit is contained in:
@@ -6070,10 +6070,8 @@ numeric_to_number(PG_FUNCTION_ARGS)
|
||||
if (IS_MULTI(&Num))
|
||||
{
|
||||
Numeric x;
|
||||
Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(10)));
|
||||
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(-Num.multi)));
|
||||
Numeric a = int64_to_numeric(10);
|
||||
Numeric b = int64_to_numeric(-Num.multi);
|
||||
|
||||
x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
|
||||
NumericGetDatum(a),
|
||||
@@ -6162,10 +6160,8 @@ numeric_to_char(PG_FUNCTION_ARGS)
|
||||
|
||||
if (IS_MULTI(&Num))
|
||||
{
|
||||
Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(10)));
|
||||
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(Num.multi)));
|
||||
Numeric a = int64_to_numeric(10);
|
||||
Numeric b = int64_to_numeric(Num.multi);
|
||||
|
||||
x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
|
||||
NumericGetDatum(a),
|
||||
@@ -6339,11 +6335,8 @@ int8_to_char(PG_FUNCTION_ARGS)
|
||||
else if (IS_EEEE(&Num))
|
||||
{
|
||||
/* to avoid loss of precision, must go via numeric not float8 */
|
||||
Numeric val;
|
||||
|
||||
val = DatumGetNumeric(DirectFunctionCall1(int8_numeric,
|
||||
Int64GetDatum(value)));
|
||||
orgnum = numeric_out_sci(val, Num.post);
|
||||
orgnum = numeric_out_sci(int64_to_numeric(value),
|
||||
Num.post);
|
||||
|
||||
/*
|
||||
* numeric_out_sci() does not emit a sign for positive numbers. We
|
||||
|
||||
Reference in New Issue
Block a user