Hi Peter,

On Thu, 3 Dec 2026 at 06:06, Peter Eisentraut <[email protected]> wrote:
> I have found several cases where a variable or C function argument was
> declared as an integer but should be a floating-point type, or vice
> versa.  See attached patches.  I think most of these are harmless in
> practice.

Regarding 0005 (ecpg dt2time): agreed, it doesn't change behaviour.
But seeing an explicit double to int64 cast, that truncates,
which can lose a microsecond.  The backend does the same thing in
DecodeDateTime() (at the dt2time() call), so it is easy to
show from SQL.  For example, 0.7 of a day is exactly 16:48:00, but:

SELECT 'J2451187.7'::timestamp;
 1999-01-08 16:47:59.999999

SELECT 'J2451187'::timestamp + '0.7 day'::interval;
 1999-01-08 16:48:00

SELECT '0.7 day'::interval;
 16:48:00

Both paths start from the same double:
0.7 * USECS_PER_DAY = 60479999999.99999.  The interval code
(AdjustFractMicroseconds()) rounds it, while the Julian-day code
truncates it.

Applying the interval code's idea to the Julian-day path would be
something like:

    time = rint(time * USECS_PER_DAY);
    dt2time((Timestamp) time, ...);

Unlike 0005, that changes results, although towards the correct answer.
Is that worth exploring (on a separate thread)?

Regards,
Dave Sharpe


Reply via email to