Skip to content
Tcl Source Code View Ticket
Login

View Ticket

expr operator precedence

Closed / Invalid218243ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:54:59
OriginalBugID: 2813 Bug
Version: 8.2
SubmitDate: '1999-09-16'
LastModified: '1999-09-16'
Severity: MED
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
OS: Linux-Red Hat
Machine: Other
FixedDate: '2000-10-25'
ClosedDate: '1999-09-16'


Name:
John Ellson

ReproducibleScript:
expr -2^2
    expr -2^2+2^2
    expr 2^2-2^2
    expr 2^-2^2

ObservedBehavior:
according to tcl:
    
      -2^2 = -4
      -2^2+2^2 = -8
       2^2-2^2 = 0
       2^-2^2 = -2

DesiredBehavior:
according to matlab
    
      -2^2 = -4
      -2^2+2^2 = 0
       2^2-2^2 = 0
       2^-2^2 = 0.0625
    
    according to perl:
    
      bash>> perl -e '$x=-2**2;print "$x\n";'
      -4
      bash>> perl -e '$x=-2**2+2**2;print "$x\n";'
      0
      bash>> perl -e '$x=+2**2-2**2;print "$x\n";'
      0
      bash>> perl -e '$x=+2**-2**2;print "$x\n";'
      0.0625



The user was confusing the Tcl bitwise XOR (^) with the power
function (expr pow(base,exp)). 
-- 09/16/1999 hobbs
welch Closed ticket [218243ffff]. [History diff]2000-10-26 08:17:55
dgp Ticket [218243ffff]: 4 changes [History diff]2001-04-19 02:32:56
Log in (anonymous is fine) to add a comment.