Skip to content
Tcl Source Code View Ticket
Login

View Ticket

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.