|
2001-04-16
| ||
| 22:57 | • Ticket [218045ffff] % operator gives incorrect answer. status still Closed ... artifact: 2d7ad4ea4e user: dgp | |
|
2000-10-26
| ||
| 08:13 | • Closed ticket [218045ffff]. artifact: c6fd29bd7c user: welch | |
| 00:52 | • New ticket [218045ffff]. artifact: 995e2537b1 user: nobody | |
% operator gives incorrect answer.
Closed / Fixed218045ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:52:32
OriginalBugID: 1384 Bug
Version: 8.0.3
SubmitDate: '1999-03-02'
LastModified: '1999-08-07'
Severity: MED
Status: Closed
Submitter: pat
ChangedBy: hobbs
OS: HP-UX
OSVersion: 10.20
Machine: Other
FixedDate: '2000-10-25'
ClosedDate: '1999-08-07'
Name:
Bob Fletcher
Extensions:
expect
CustomShell:
None
ReproducibleScript:
#!/bin/sh
# the next line restarts using wish exec wish "$0" "$@"
for {set i -10} {$i <= 10} {incr i} {
set x $i
puts "i $i [expr {$i%10}] $x [expr {fmod($x,10.)}]"
}
exit
ObservedBehavior:
This is the cl8.03 output for this expr % test.
i -10 0 -10 0.0
i -9 1 -9 -9.0
i -8 2 -8 -8.0
i -7 3 -7 -7.0
i -6 4 -6 -6.0
i -5 5 -5 -5.0
i -4 6 -4 -4.0
i -3 7 -3 -3.0
i -2 8 -2 -2.0
i -1 9 -1 -1.0
i 0 0 0 0.0
i 1 1 1 1.0
i 2 2 2 2.0
i 3 3 3 3.0
i 4 4 4 4.0
i 5 5 5 5.0
i 6 6 6 6.0
i 7 7 7 7.0
i 8 8 8 8.0
i 9 9 9 9.0
i 10 0 10 0.0
This is the output from a similar f77 code.
i -10 0 -10.0 .0
i -9 -9 -9.0 -9.0
i -8 -8 -8.0 -8.0
i -7 -7 -7.0 -7.0
i -6 -6 -6.0 -6.0
i -5 -5 -5.0 -5.0
i -4 -4 -4.0 -4.0
i -3 -3 -3.0 -3.0
i -2 -2 -2.0 -2.0
i -1 -1 -1.0 -1.0
i 0 0 .0 .0
i 1 1 1.0 1.0
i 2 2 2.0 2.0
i 3 3 3.0 3.0
i 4 4 4.0 4.0
i 5 5 5.0 5.0
i 6 6 6.0 6.0
i 7 7 7.0 7.0
i 8 8 8.0 8.0
i 9 9 9.0 9.0
i 10 0 10.0 .0
The tcl expr command gives, for negative numbers, gives different answers than the tcl floating point fmod command, and different answers from f77/C.
We would expect % to give the same answer as fmod, when the floating point is equivalent to an int.
DesiredBehavior:
We would expect % to give the same answer as fmod, when the floating point is equivalent to an int.
Note the comments in tclExecute.c:
case INST_MOD:
/*
* This code is tricky: C doesn't guarantee much about
* the quotient or remainder, but Tcl does. The
* remainder always has the same sign as the divisor and
* a smaller absolute value.
*/
K&R states specfically (p41, 2nd ed) that the sign of the
result for % is machine-dependent for negative operands.
Thus Tcl only formalizes this with a more strict definition.
-- 08/07/1999 hobbs
welch Closed ticket [218045ffff].
[History diff]2000-10-26 08:13:43
dgp Ticket [218045ffff]: 3 changes
[History diff]2001-04-16 22:57:44
Log in (anonymous is fine) to add a comment.