#3926 tcl::mathfunc commands and non-canonical string reps

obsolete: 8.5.1
closed-fixed
5
2008-03-10
2008-02-14
Zbigniew
No

A "live example":

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

...above explains the problem. But, as the others mentioned already:

% expr {abs(-0)}
0

...works fine.

Discussion

  • Don Porter

    Don Porter - 2008-02-14

    Logged In: YES
    user_id=80530
    Originator: NO

    % foreach c [info commands tcl::mathfunc::*] {
    catch {$c 0} a
    catch {$c -0} b
    if {$a ne $b} {puts $c}
    }
    ::tcl::mathfunc::round
    ::tcl::mathfunc::abs
    ::tcl::mathfunc::entier
    ::tcl::mathfunc::min
    ::tcl::mathfunc::max

    These are the five mathfunc commands
    that return surprising, if not simply
    wrong, answers when passed -0.

     
  • Don Porter

    Don Porter - 2008-02-14
    • summary: A bug in ::tcl::mathfunc::abs --> tcl::mathfunc commands and -0
     
  • Don Porter

    Don Porter - 2008-02-14

    Logged In: YES
    user_id=80530
    Originator: NO

    The general issue is whether mathfunc
    commands can, unlike [expr], return
    non-canonical string reps:

    % tcl::mathfunc::abs 0x0
    0x0
    % expr abs(0x0)
    0
    % tcl::mathfunc::abs 1.2345678901234567890123456789
    1.2345678901234567890123456789
    % expr abs(1.2345678901234567890123456789)
    1.2345678901234567

     
  • Don Porter

    Don Porter - 2008-02-14
    • summary: tcl::mathfunc commands and -0 --> tcl::mathfunc commands and non-canonical string reps
     
  • Don Porter

    Don Porter - 2008-02-14

    Logged In: YES
    user_id=80530
    Originator: NO

    Since tcl::mathfunc commands are
    general Tcl commands, and programmers
    are invited to create their own, there's
    no systemic way to address this.

    We can certainly follow a practice
    with our own built-in commands that
    they return canonical strings only, if
    we wish. Is it useful to do so?

     
  • Don Porter

    Don Porter - 2008-02-14

    Logged In: YES
    user_id=80530
    Originator: NO

    dgp I think the max and min implementations we have are good. Actually returning one of the arguments seems like a positive thing.
    dgp The docs for them might be enhanced a bit.
    dgp not "greatest value", but "first argument not less than any other argument"

    % namespace path tcl::mathfunc
    % max 0x1 1
    0x1
    % max 1 0x1
    1

     
  • Don Porter

    Don Porter - 2008-03-10

    Logged In: YES
    user_id=80530
    Originator: NO

    The [abs] results are the greatest concern.
    They can leak into [expr] results as well:

    % expr {abs(-1e-323)}
    1e-323
    % expr {abs(-1e-324)}
    -0.0

     
  • Don Porter

    Don Porter - 2008-03-10

    Logged In: YES
    user_id=80530
    Originator: NO

    Committed fix for abs().
    For now, I consider other issues
    raised here to be "not a bug".

     
  • Don Porter

    Don Porter - 2008-03-10
    • status: open --> closed-fixed
     
  • Nobody/Anonymous

    Logged In: NO

    Where is the patch?

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks