Re: Have I found an interval arithmetic bug?

From: Zhihong Yu <zyu(at)yugabyte(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, John W Higgins <wishdev(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Have I found an interval arithmetic bug?
Date: 2021-04-03 02:53:35
Message-ID: CALNJ-vTCW_Ot1jpz+o-HXYRso1XwOZHmOMYSD6AeWqObszFtNw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Bruce:
In src/interfaces/ecpg/pgtypeslib/interval.c, how about the following
places ?

Around line 158:
case 'Y':
tm->tm_year += val;
tm->tm_mon += (fval * MONTHS_PER_YEAR);

Around line 194:
tm->tm_year += val;
tm->tm_mon += (fval * MONTHS_PER_YEAR);

Is rint() needed for these two cases ?

Cheers

On Fri, Apr 2, 2021 at 7:21 PM Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> On Fri, Apr 2, 2021 at 07:06:08PM -0700, Zhihong Yu wrote:
> > Hi,
> > The mix of interval and comparison with float is not easy to interpret.
> See the
> > following (I got 0.0833 since the result for interval '0.3 years' +
> interval
> > '0.4 years' - ... query was 1 month and 1/12 ~= 0.0833).
> >
> > yugabyte=# select 0.3 * '1 year'::interval + 0.4 * '1 year'::interval -
> 0.7 *
> > '1 year'::interval = '0.0833 year'::interval;
> > ?column?
> > ----------
> > f
> >
> > As long as Bruce's patch makes improvements over the current behavior, I
> think
> > that's fine.
>
> I wish I could figure out how to improve it any futher. What is odd is
> that I have never seen this reported as a problem before. I plan to
> apply this early next week for PG 14.
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
> EDB https://enterprisedb.com
>
> If only the physical world exists, free will is an illusion.
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2021-04-03 03:00:12 Re: Have I found an interval arithmetic bug?
Previous Message Bruce Momjian 2021-04-03 02:21:26 Re: Have I found an interval arithmetic bug?

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2021-04-03 02:55:16 Re: Making wait events a bit more efficient
Previous Message Michael Paquier 2021-04-03 02:47:49 Re: [PATCH] Implement motd for PostgreSQL