Tcl Library Source Code

View Ticket
Login
Ticket UUID: 1123327
Title: histograms do not handle negative reals correctly.
Type: Bug Version: None
Submitter: sqrly Created on: 2005-02-15 19:06:34
Subsystem: counter Assigned To: welch
Priority: 5 Medium Severity:
Status: Open Last Modified: 2005-02-15 19:06:34
Resolution: None Closed By:
    Closed on:
Description:
When I do this: 
::counter::init h -hist 10
::counter::count h 9.1
::counter::count h -9.2

I end up with bin 0 incremented twice.  I should have
incremented bin -1 once and bin 0 once.

proc ::counter::count is incorrect.  This fixes
(counter.tcl) that problem. 

-hist {
        upvar #0 counter::H-$tag histogram
set bucket [expr int([expr floor([expr {$delta /
$counter(bucketsize)}])])]
        if {![info exists histogram($bucket)]} {
            set histogram($bucket) 0
        }
        incr histogram($bucket)

The problem is that int(-0.9) == 0 and int(0.9) == 0


The html output is also incorrect as the labels are off
by one.  I simply subtracted one in proc
histHtmlDisplayBarChart

    #set x [expr {$i * $counter(bucketsize) *
$counter(mult)}]
    set x [expr {($i-1) * $counter(bucketsize) *
$counter(mult)}]



There are still problems with the -skip option