|
2008-05-12
| ||
| 05:53 | • Closed ticket [1962090fff]: Failure of string and expr commands plus 7 other... artifact: 5da35c942f user: hobbs | |
|
2008-05-11
| ||
| 22:46 | • New ticket [1962090fff]. artifact: 176c28821b user: nobody | |
Failure of string and expr commands
Closed / Invalid1962090fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 19 years ago
Descriptionplain2008-05-11 22:46:30
I was trying to do some data validation, and ran across the following situation, which the example below demonstrates.
% info patchlevel
8.4.17
% set s "5\n"
5
% string is double -strict $s
1
% expr {$s >= 0.0}
1
The string 's' is clearly not a double since it contains a control character, however the string test for double is returning true, which it should fail. The expr command is even more puzzling since the string is not a number, but the comparison returns true.
IMHO both of these tests should return zero as the string is clearly not a double.
hobbsplain2008-05-12 05:53:04
Logged In: YES user_id=72656 Originator: NO To be clear, this control char is actually in the subspace of whitespace characters, which have more lenient handling at the C level. It is no different than " 5 ", which is 5 as a number to strtod. BTW, the comparison <= is dangerous because it can do string comparisons, but you will see that it is a valid "integer" by doing + 1 as well.
Log in (anonymous is fine) to add a comment.