Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-03-11
19:07 • Ticket [482db1d796] Wrong result from simple clock arithmetic (`clock add` with ... artifact: 45ef10d1c0 user: sebres
18:45 • Closed ticket [482db1d796]. artifact: 97c0105030 user: sebres
18:37
merge 9.0 (fix for [482db1d796540e68]) check-in: 16f05b6fc9 user: sebres tags: trunk, main
18:36
merge 8.7: fixes [482db1d796540e68], some minor optimizations and another corner cases for a compile... check-in: 57d18c0efc user: sebres tags: core-9-0-branch
17:53
fixes [482db1d796540e68]: local seconds of day shall be always positive, also for negative base (mod... check-in: 27cbd7afc6 user: sebres tags: core-8-branch
17:51
added test coverage for `clock add` with negative base (bug [482db1d796540e68]) check-in: 663f0dad21 user: sebres tags: core-8-branch
17:41 • Ticket [482db1d796] Wrong result from simple clock arithmetic (clock add). s... artifact: d23721255d user: sebres
14:25 • New ticket [482db1d796]. artifact: a8fab71537 user: sbron

Wrong result from simple clock arithmetic (`clock add` with negative base).

Closed / Fixed482db1d796540e6865abdce17e2aa391f3fb88ffCreated 2 years agoUpdated 2 years ago
Descriptionwiki2025-03-11 14:25:38
I observe a wrong result from [clock add -631152000 2372806200 seconds]. This should obviously produce 1741654200 (-631152000 + 2372806200), but it returns 1741567800 instead.
sebreswiki2025-03-11 17:41:13

The reason is a bug by porting [clock add] from Tcl to C - calculating seconds of day localSeconds % SECONDS_PER_DAY on a negative base generates negative result in C (-82800 instead of 3600 as it'd be in Tcl), so after all the seconds of day are wrong and the whole result deviate by one day:

- UTC -631152000 => LOCTM -631148400 % 86400 == -82800  // C vs.
+ UTC -631152000 => LOCTM -631148400 % 86400 ==   3600  ## Tcl
Fixing it now for 8.7+, add coverage, etc...

sebreswiki2025-03-11 18:45:47

Basically fixed in [27cbd7afc65a5c79], but found more places for a compiler "fix" (signed-mod operation with potentially negative dividend), so added more corrections in [e33fcd57b0397d45] (including few code simplifications and normalizations).

Test coverage is added too, so I close the ticket as fixed for now.

sebres Ticket [482db1d796]: 4 changes [History diff]2025-03-11 19:07:40
Log in (anonymous is fine) to add a comment.