Skip to content

Commit

Permalink
Fix bug 578b7e273c03. -- Round computed end value to match precision …
Browse files Browse the repository at this point in the history
…of given arguments.
  • Loading branch information
bgriffin42 committed Feb 15, 2024
1 parent 861c7f3 commit 05c7cce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion generic/tclArithSeries.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,12 @@ TclNewArithSeriesObj(

if (!endObj) {
if (useDoubles) {
// Compute precision based on given command argument values
int precision = maxPrecision(dstart,len,dstep);
dend = dstart + (dstep * (len-1));
end = dend;
// Make computed end value match argument(s) precision
dend = ArithRound(dend, precision);
end = dend;
} else {
end = start + (step * (len-1));
dend = end;
Expand Down
19 changes: 19 additions & 0 deletions tests/lseq.test
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,25 @@ test lseq-bug-54329e39c7 {does not cause memory bloat} -constraints {
expr {[string match *purify* [tcl::build-info]] || ($postmem - $premem < 10) ? 1 : ($postmem - $premem)}
} -result 1

test lseq-bug-578b7e273c03-1 {Arithmetic Series Objects get wrong precision when end value is not specified} -body {
set bl [expr {2.8 in [lseq 0 count 100 by .1]}]
lappend bl [expr {2.8 in [lseq 0 count 200 by .1]}]
lappend bl [expr {0.28 in [lseq 0 count 100 by .01]}]
lappend bl [expr {0.28 in [lseq 0 count 200 by .01]}]
lappend bl [expr {0.286 in [lseq 0 count 100 by .011]}]
lappend bl [expr {0.286 in [lseq 0 count 200 by .011]}]
} -result {1 1 1 1 1 1}

test lseq-bug-578b7e273c03-2 {Arithmetic Series Objects get wrong precision when end value is not specified} -body {
set ll [llength [lseq 0 count 100 by .1]]
lappend ll [llength [lseq 0 count 200 by .1]]
lappend ll [llength [lseq 0 count 100 by .01]]
lappend ll [llength [lseq 0 count 200 by .01]]
lappend ll [llength [lseq 0 count 100 by .011]]
lappend ll [llength [lseq 0 count 200 by .011]]
} -result {100 200 100 200 100 200}


# cleanup
::tcltest::cleanupTests

Expand Down

0 comments on commit 05c7cce

Please sign in to comment.