In bltVecMath.c the test for underflow in vector expr calculations produces unexpected behaviour, an error "floating-point value too small to represent" . If the number is "too small to represent", the calculation should simply return a zero. This is the default tcl behaviour, and when blt vector offers a different set of internal rules, that's disorienting. I came across it when calculating a sum of a few Gaussian lines, exp(-x^2). If I specify the x vector to be too wide, or the standard deviation too small, the rapid decay of the exponential should simply yield zeros far away from the center. Instead, it errors out, and I need to add unnecessary error checking, which completely defeats the elegance of the vector expr calculations of BLT.
package require BLT
namespace import ::blt::*
vector create x
::x seq 25 30 1
puts "\n\ttclsh underflow with y = exp(-x**2)\n"
# tcl [expr ...] returns zeros for x>27
for {set i 0} {$i < [::x length]} {incr i} {
puts [format "%.2f --> %.3e" $::x($i) [expr exp(-($::x($i)**2))] ]
}
puts "\n\tblt underflow with y = exp(-x^2)\n"
vector create y
# this works fine
::x seq 25 27 1
puts "$::x(:) -->"
::y expr {exp(-(::x ^ 2))}
puts $::y(:)
# this crashes out with "floating-point value too small to represent"
::x seq 25 28 1
puts "$::x(:) -->"
::y expr {exp(-(::x ^ 2))}
puts $::y(:)
Tested under Ubuntu 20.04, tcl 8.6, blt 2.5.3, but the same code is present in all available versions, including 2.4.7z.
Just updated the code from this site, compiled and verified that the same behaviour is seen in the current version (3.0? 4.0?) of BLT:
I agree that the behavior should be the same as TCL.
I'll make the changes.
--gah
On 7/5/22 13:17, Edward Sternin wrote:
Related
Bugs: #159