Skip to content
Tcl Source Code View Ticket
Login

View Ticket

'Inf' not understood in expr

Closed / Fixed218000ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 24 years ago
Descriptionplain2000-10-26 00:51:50
OriginalBugID: 680 Bug
Version: 8.0p2
SubmitDate: '1998-09-23'
LastModified: '1999-09-15'
Severity: LOW
Status: Closed
Submitter: welch
ChangedBy: hobbs
OS: All
OSVersion: NA
Machine: NA
FixedDate: '2000-10-25'
FixedInVersion: NA
ClosedDate: '1999-09-15'


I've got a program that returns the floating point number HUGE_VAL to
Tcl.  Unfortunately, libc represents this as "Inf" which Tcl cannot convert
back into a floating point number.

Here's an example:
  - "$myobj" is an instance of a class I've created
  - "$myobj hugeVal" just returns the defined constant HUGE_VAL
  - "$myobj setIt" tries to convert the parameter via Tcl_GetDouble

% $myobj hugeVal
Inf
% set val [$myobj hugeVal]
Inf
% set a [expr $val / 10]
syntax error in expression "Inf / 10"
% $myobj setIt $val
expected floating-point number but got "Inf"


The actual code for the "hugeVal" function looks like:

    case 32: {        // double hugeVal(void)
        double _retcode;

        if (_argc != 2) {
            _interp->result = "wrong # args";
            return TCL_ERROR;
        }
        _retcode = HUGE_VAL;

        sprintf(_interp->result,"%f",_retcode);
    } break;


                                          Brian
                                 ( [email protected] )


The problem is that sprintf does the interp here, converting
it to a regular string "Inf".  Code like this should benefit
from Tcl_Obj's, where it needn't be stored as a string. 
-- 09/15/1999 hobbs
welch Closed ticket [218000ffff]. [History diff]2000-10-26 08:12:11
dgp Ticket [218000ffff]: 5 changes [History diff]2001-04-16 20:52:08
nobodyplain2001-08-10 19:51:32
Logged In: NO 

I wanted to add some thing more to this.
If test case like this.

tcl> set a INF
tcl>if{($a == "*")} {
}

It's giving floating-point value too large.
Please comment on this.

This is only on HPUX platform only.
dgp Open ticket [218000ffff]. [History diff]2001-08-10 23:16:00
dgpplain2001-08-10 23:16:01
Logged In: YES 
user_id=80530

Re-opening this so we can address the
new HPUX comment.  Need to examine
cross-platform inconsistency of [expr]
-- probably due to inconsistency of
strtod() or something similar.
dgp Ticket [218000ffff]: 2 changes [History diff]2001-08-10 23:16:29
msofer Ticket [218000ffff]: 2 changes [History diff]2001-08-14 21:04:37
hobbsplain2002-02-26 05:16:36
Logged In: YES 
user_id=72656

SuSE 7.3 build of 2002-02-25 8.4 build also gives:

% expr {"INF"}
floating-point value too large to represent

That actually seems correct to me in some sense.
dgpplain2002-02-26 07:08:56
Logged In: YES 
user_id=80530

This is weird though:

% set a INF
INF
% expr {$a + 1}
can't use floating-point value as operand of "+"
dgpplain2002-07-06 03:47:38
Logged In: YES 
user_id=80530

Error message is improved now:

% set a Inf
Inf
% expr {$a + 1}
floating-point value too large to represent

The original report has a better error message now too:

% expr $a + 1
syntax error in expression "Inf + 1": variable references
require preceding $

so there appears to be a consistency here.

Open issues:
1) Is this consitency cross-platform?
2) Is documentation sufficient?
dkfplain2002-07-06 05:35:22
Logged In: YES 
user_id=79902

Hmm.  The expression parser probably doesn't know about Inf
(or NaN either.)
dgpplain2002-07-22 07:54:12
Logged In: YES 
user_id=80530


another data point on this:

Tcl is not consistent in
treating Inf and Nan:

% expr {"nan"}
domain error: argument not in valid range
% expr {nan}
domain error: argument not in valid range
% expr {"inf"}
floating-point value too large to represent
% expr {inf}
syntax error in expression "inf"

The difference is due to line 1555 of
tclParseExpr.c which specially looks for
'n' or 'N' to give strtod() a chance to
claim it.  

It would be more consistent to either
check for 'i' and 'I" there as well, or to
check for none of them.

Given the original report here, the better
choice is probably to check for both
so that all string reps of doubles generated
by Tcl get recognized by Tcl as string reps
of doubles with [expr] without quoting.
dkfplain2002-07-22 16:15:39
Logged In: YES 
user_id=79902

% expr {inf + 1}
syntax error in expression "inf + 1": variable references
require preceding $
% expr {nan + 1}
domain error: argument not in valid range
% set i inf; expr {$i + 1}
can't use floating-point value as operand of "+"
% set n nan; expr {$n + 1}
domain error: argument not in valid range
% info patch
8.4b2
% parray tcl_platform
tcl_platform(byteOrder) = bigEndian
tcl_platform(machine)   = sun4u
tcl_platform(os)        = SunOS
tcl_platform(osVersion) = 5.8
tcl_platform(platform)  = unix
tcl_platform(user)      = fellowsd
tcl_platform(wordSize)  = 4
dkf Closed ticket [218000ffff]. [History diff]2002-07-22 17:04:58
Log in (anonymous is fine) to add a comment.