Re: More math - must be bug(?)



At 2008-02-14 09:09AM, "ZB" wrote:
tclsh8.5 [~/tmp]set a -0
-0
tclsh8.5 [~/tmp]puts [::tcl::mathfunc::int $a]
0
tclsh8.5 [~/tmp]puts [::tcl::mathfunc::abs $a]
-0
tclsh8.5 [~/tmp]puts [::tcl::mathfunc::abs $a]
-0

As you can see, "int" does the operation "absolute value" properly - when
"abs" does not?

I think you've found a bug in ::tcl::mathfunc::abs. File it on the Tcl
bug tracker at sourceforge
http://sourceforge.net/tracker/?atid=110894&group_id=10894&func=browse

Note that when you use expr, result is correct:
% expr {abs(-0)}
0

I see in the expr docS that when Tcl sees:
expr {sin($x+$y)}
it actually does
tcl::mathfunc::sin [expr {$x+$y}]

expr still processes the function arguments (!)

so we see the error:
% ::tcl::mathfunc::abs -0
-0

BUT
% expr {-0}
0

Therefore, as a workaround, you should wrap your mathfunc arguments in
expr:
set abs [::tcl::mathfunc::abs [expr {$a}]]

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
.