diff options
author | Bruce Momjian <bruce@momjian.us> | 2005-07-20 03:50:24 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2005-07-20 03:50:24 +0000 |
commit | 826604f9e61c233c4229a3eb4d1ee3945691ee1b (patch) | |
tree | fcd99f32749776c311c1b0f7d34c2fd1ee10e5c9 /src/backend/utils/adt/timestamp.c | |
parent | ca76df425bddc050d83546a7a137d7621491ebaa (diff) | |
download | postgresql-826604f9e61c233c4229a3eb4d1ee3945691ee1b.tar.gz postgresql-826604f9e61c233c4229a3eb4d1ee3945691ee1b.zip |
Fix interval division and multiplication, before:
test=> select '4 months'::interval / 5;
?column?
---------------
1 mon -6 days
(1 row)
after:
test=> select '4 months'::interval / 5;
?column?
----------
24 days
(1 row)
The problem was the use of rint() to round, and then find the remainder,
causing the negative values.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 74f40af7836..be86884205a 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.132 2005/07/12 16:04:58 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.133 2005/07/20 03:50:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -2201,7 +2201,7 @@ interval_mul(PG_FUNCTION_ARGS) result->time += (months - result->month) * INT64CONST(30) * USECS_PER_DAY; #else - result->month = rint(months); + result->month = (int)months; result->time = JROUND(span1->time * factor); /* evaluate fractional months as 30 days */ result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY); @@ -2246,7 +2246,7 @@ interval_div(PG_FUNCTION_ARGS) INT64CONST(30) * USECS_PER_DAY) / factor; #else months = span->month / factor; - result->month = rint(months); + result->month = (int)months; result->time = JROUND(span->time / factor); /* evaluate fractional months as 30 days */ result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY); |