Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-05-30
19:34 • Closed ticket [960210ffff]: expr {"Nan"} plus 7 other changes artifact: 450bd205fe user: dkf
2004-05-28
20:04 • Ticket [960210ffff]: 4 changes artifact: a8cade835e user: dkf
18:30 • Ticket [960210ffff]: 4 changes artifact: 0bc4da66e7 user: ferrieux
18:10 • Ticket [960210ffff]: 4 changes artifact: 0b5bc1b768 user: nobody
2004-05-26
05:31 • Ticket [960210ffff]: 4 changes artifact: f7239f7e90 user: dkf
04:46 • Ticket [960210ffff]: 1 change artifact: a117de2d74 user: msofer
03:32 • Ticket [960210ffff]: 4 changes artifact: 807079cc28 user: dgp
2004-05-25
22:34 • Ticket [960210ffff]: 4 changes artifact: 7fe12eed2f user: ferrieux
15:21 • New ticket [960210ffff]. artifact: a556f8d122 user: nobody

expr {"Nan"}

Closed / Out of Date960210ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2004-05-25 15:21:00
The expr command, when given the literal string "Nan"
(quotes included), tries to convert Nan to a number and
 yields the error:

     domain error: argument not in valid range

Clearly, what's inside quotes is not expr's business,
it shouldn't open that box !

Also notice that this strange behavior is insensitive
to whitespace, but it to other characters:

   expr {"Nan xyz"}

works correctly.
ferrieuxplain2004-05-25 22:34:34
Logged In: YES 
user_id=496139

This was me (sorry I hadn't logged in).
Maybe one useful detail:

The same problem arises if the Nan results from an evaluation:

proc foobar {} {return Nan}
expr {[foobar]}

So we can reinterpret this as: "expr systematically tries to
convert its final result to a number". This is at odds with
Tcl's lazy conversion spirit, and definitely a bug !

-Alex
dgpplain2004-05-26 03:32:49
Logged In: YES 
user_id=80530

be sure to reconcile any
changes here with Bug 218000
msofer Ticket [960210ffff]: 1 change [History diff]2004-05-26 04:46:54
dkfplain2004-05-26 05:31:31
Logged In: YES 
user_id=79902

Tcl's NaN handling is an utter mess.  But [expr] is (IIRC)
defined to be aggressive about trying to convert its result
into numeric form.
nobodyplain2004-05-28 18:10:18
Logged In: NO 

sorry, i couldn't logged in

i tried this command but not foumd any error in it as it 
printing "Nan"
ferrieuxplain2004-05-28 18:30:37
Logged In: YES 
user_id=496139

Look at the header: I tried this on 8.3.5.
So please give the [info patchlevel] where you no longer
have the bug.
I'd like to know the critical version where this was fixed.
Any idea, frome those who know expr's changelog by heart ?

-Alex
dkfplain2004-05-28 20:04:20
Logged In: YES 
user_id=79902

8.4 had a bit of work in this area, but it turns out that
many platform libc's aren't good here.  :^(
dkfplain2004-05-30 19:34:33
Logged In: YES 
user_id=79902

The expr.n manual page states that:
"If an operand does not have one of the integer formats
given above, then it is treated as a floating-point number
if that is possible."

Thus, [expr] is correct to regard "Nan" as a float, and is
at least not vastly wrong in regarding that as a domain
error (because that's what generates NaN values normally.) 
8.4 should be a bit better at handling this.
Log in (anonymous is fine) to add a comment.