Truncation/rounding error in strftime(x, 'unixepoch')

Stefan Brüns <[email protected]>
Newsgroups gmane.comp.db.sqlite.general
Message-ID <10147612.b21rinHY2O@pebbles>
Hi,

some time ago there was an error reported when running the testsuite on ix86, 
in the date.test/date-2.2c-*.

The error happens as a string like 1237962480.003 gets parsed and rounded to 
1237962480.002999... and is later truncated to 1237962480.002.

The rounding error happend in date.c:parseModifier(...):
p->iJD = (sqlite3_int64)r;

i.e. the double r is truncated by casting it to int.

Doing the following change fixes the error on ix86, and lets the testsuites
pass on i586, x86_64, aarch64, ppc64le, ...

- p->iJD = (sqlite3_int64)r;
+ p->iJD = (sqlite3_int64)(r + 0.5);

Also compare with date.c:setRawDateNumber(...), where rounding is already 
applied:

p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);

Kind regards,

Stefan

-- 
Stefan Brüns  /  Bergstraße 21  /  52062 Aachen
home: +49 241 53809034     mobile: +49 151 50412019

_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
signature.asc (application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE-----

iF0EABECAB0WIQSwWRWIpJbl0W4DemNvf0o9jP6qUwUCXiHNRwAKCRBvf0o9jP6q
U3pSAJ4u3EEScgtqk93nsSSE7ZhlVCwYugCcDPt7CWgVurPgezUnPe9SVrZbDdo=
=9+kO
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.