mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Fix bug I introduced in recent rewrite of NUMERIC code: numeric to
integer conversions gave the wrong answer for values with stripped trailing zeroes, such as 10000000.
This commit is contained in:
parent
b89140a7ec
commit
cdb8a844e6
@ -14,7 +14,7 @@
|
|||||||
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
|
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.61 2003/05/12 23:08:50 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.62 2003/07/03 19:41:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2983,6 +2983,7 @@ numericvar_to_int8(NumericVar *var, int64 *result)
|
|||||||
{
|
{
|
||||||
NumericDigit *digits;
|
NumericDigit *digits;
|
||||||
int ndigits;
|
int ndigits;
|
||||||
|
int weight;
|
||||||
int i;
|
int i;
|
||||||
int64 val,
|
int64 val,
|
||||||
oldval;
|
oldval;
|
||||||
@ -3000,14 +3001,22 @@ numericvar_to_int8(NumericVar *var, int64 *result)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For input like 10000000000, we must treat stripped digits as real.
|
||||||
|
* So the loop assumes there are weight+1 digits before the decimal point.
|
||||||
|
*/
|
||||||
|
weight = var->weight;
|
||||||
|
Assert(weight >= 0 && ndigits <= weight+1);
|
||||||
|
|
||||||
/* Construct the result */
|
/* Construct the result */
|
||||||
digits = var->digits;
|
digits = var->digits;
|
||||||
neg = (var->sign == NUMERIC_NEG);
|
neg = (var->sign == NUMERIC_NEG);
|
||||||
val = digits[0];
|
val = digits[0];
|
||||||
for (i = 1; i < ndigits; i++)
|
for (i = 1; i <= weight; i++)
|
||||||
{
|
{
|
||||||
oldval = val;
|
oldval = val;
|
||||||
val *= NBASE;
|
val *= NBASE;
|
||||||
|
if (i < ndigits)
|
||||||
val += digits[i];
|
val += digits[i];
|
||||||
/*
|
/*
|
||||||
* The overflow check is a bit tricky because we want to accept
|
* The overflow check is a bit tricky because we want to accept
|
||||||
|
Loading…
x
Reference in New Issue
Block a user