Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[string is double "0x5"] bug?

Closed / Invalid3600057fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 12 years ago
Descriptionplain2013-01-09 08:42:24
I suppose, "0x5" cannot be a valid double, but it is accepted by "string is double".
% string is double "0x5"
1

But "lsearch" does not like it:
% lsearch -exact -real {0x5 2} 2
expected floating-point number but got "0x5"

("-real" means practically  "-double"?)
dkf Ticket [3600057fff]: 6 changes [History diff]2013-08-25 01:21:53
dkfhtml2013-09-05 08:46:35

Confirmed on 8.4 through 8.6, and this is definitely “unexpected”.

dkfhtml2013-09-08 14:09:46

Ugh, the source contains the dreaded comment:

/* TODO */
The functionality is outright missing.

dkfhtml2013-09-08 14:50:33

That should be all fixed now, assuming that I've not made any silly errors. (I've added a fair few tests.)

dgpplain2013-09-08 15:38:59
Whoa! Whoa! Whoa!

What's this?

[string is double] is the script form of
Tcl_GetDoubleFromObj().  Why are you narrowing
its domain? Without discussion?

The /* TODO */ comment is troubling yes, but with
no indication what the one writing it thought still
needed to be done, I'm not seeing the case for this.

(And on the eve of a (patch!) release, coincident with
attempts to prep for the conference, it's quite
disturbing to me.)
dkfhtml2013-09-08 23:43:24

In that case you take responsibility for getting it in. Assigned to you; if you assign back to me, I'll just commit the code to the main branch.

The issue is exactly that the code is not the same as Tcl_GetDoubleFromObj in that it allows “0x5” and “0o5” through despite these not being allowed in a real call to that function (which is what lsearch -real and lsort -real use internally). There is also (pre-patch) no test case that checks whether the domains of what is accepted and what rejected is reasonable in these edge cases.

The one downside is that string is double 0x5 returned 1 in 8.4 too. I'm guessing that that was always an oversight.

dgpplain2013-09-09 12:58:17
[string is double 0x5] == 1 is intended correct behavior.

Tcl_GetDoubleFromObj() should also succeed on "0x5" input.

In a brief round of testing that's what I see happening.

I have not been able to reproduce the ticket's claim
about 

lsearch -exact -real {0x5 2} 2

raising an error.

I'll probe a bit more, but this is looking like
an Invalid ticket.  If the OP is reading and can
add info about the Tcl release or other platform
or environment details where we might reproduce the
[lsearch] error, that could help.
dgpplain2013-09-09 13:07:56
The -real option for [lsearch] arrived in Tcl 8.4:

% info patch
8.4.0
% lsearch -exact -real {0x5 2} 2
1

(Combining -exact and -real is strange. but there it is)

The ticket claims about [lsearch] just are not correct
as far as I can tell.

The consistent rule implemented by Tcl is that all 
integers are doubles.  That is, the double "equivalent"
can be determined and used.  This is in the sense of
[string is double] as well as Tcl_GetDoubleFromObj().

("equivalent" can be rather loosely interpreted.  All large
enough bignum integers are equivalent to the double value "Inf")
dkf Ticket [3600057fff]: 3 changes [History diff]2013-09-27 10:42:38
dgp Closed ticket [3600057fff]. [History diff]2015-01-26 20:27:37
Log in (anonymous is fine) to add a comment.