Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2017-02-01
22:24 • Ticket [d0f7ba56f0] INST_EQ first-argument NaN shortcut is too aggressive st... artifact: d5fe72d12c user: aspect
15:00 • Closed ticket [d0f7ba56f0]. artifact: 1961c40141 user: jan.nijtmans
14:56
Fix [d0f7ba56f0e8f93b7efb5b09ebc30a824bdd577a|d0f7ba56f0]: INST_EQ first-argument NaN shortcut is to... check-in: d98193fd0e user: jan.nijtmans tags: novem
14:55
Fix [d0f7ba56f0e8f93b7efb5b09ebc30a824bdd577a|d0f7ba56f0]: INST_EQ first-argument NaN shortcut is to... check-in: c63d2eba50 user: jan.nijtmans tags: trunk
14:53
Fix [d0f7ba56f0e8f93b7efb5b09ebc30a824bdd577a|d0f7ba56f0]: INST_EQ first-argument NaN shortcut is to... check-in: 391ad1092f user: jan.nijtmans tags: core-8-6-branch
14:42
Fix [d0f7ba56f0e8f93b7efb5b09ebc30a824bdd577a|d0f7ba56f0]: INST_EQ first-argument NaN shortcut is to... check-in: 5c78fe98ba user: jan.nijtmans tags: core-8-5-branch
2017-01-28
03:12 • New ticket [d0f7ba56f0] INST_EQ first-argument NaN shortcut is too aggressive</i... artifact: 379a054346 user: aspect

INST_EQ first-argument NaN shortcut is too aggressive

Closed / Fixedd0f7ba56f0e8f93b7efb5b09ebc30a824bdd577aCreated 10 years agoUpdated 10 years ago
Descriptionplain2017-01-28 03:12:33
In the TIP#451 discussion on tcl-core it was shown that NaN is != to all strings, when provided as the first argument to ==/!=/>/</>=/<=.

The cause seems to be that case INST_EQ in tclExecute.c shortcuts too quickly when type1 == TCL_NUMBER_NAN.  It should check that value2Ptr can be coerced to a number first.

% set x "nan"
% set y "gran"
% expr {$x > $y} ;# expect 1
0
% expr {$x < $y} ;# expect 0
0
% expr {$y > $x} ;# expect 0
0
% expr {$y < $x} ;# expect 1
1

This is contrary to expr(n) "when all arguments to the operator allow numeric interpretations".

Fixing this should probably consider the [pyk-emptystring] branch, which touches the same place to speed up a common case of comparison with "".
Referenced by4
jan.nijtmansplain2017-02-01 15:00:28
Thanks for the bug report, and the clear test-case. Fixed now on all active branches.

The [pyk-emptystring] branch looks good to me. Since it's not a behavior change, only an optimization, I see no problem merging it to trunk. If anyone else reading this objects to that, please speak up! But ... it's unrelated to this issue.
aspectplain2017-02-01 22:24:23
Nice fix, Jan!  I was somehow entranced by all the gotos and didn't see such a way to make the code both more clear and correct.

Thanks!
Log in (anonymous is fine) to add a comment.