Tcl Source Code

View Ticket
Login
Ticket UUID: 664775
Title: execute-7.30 fails on SGI
Type: Bug Created on: 2003-01-09 00:19:05
Submitter: dgp Assigned to: msofer
Subsystem: 47. Bytecode Compiler Severity:
Priority: 5 Medium Last modified: 2003-02-19 21:42:42
Status: Closed Closed by: msofer
Resolution: Fixed Closed on: 2003-02-19 14:42:42
Version: obsolete: 8.4.1
Description:
==== execute-7.30 Wide int handling in function call FAILED
==== Contents of test case:

    set x 0x12345687123456
    incr x
    expr {sin($x) == sin(double($x))}

---- Result was:
floating-point value too small to represent
---- Result should have been (exact matching):
1
---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
==== execute-7.30 FAILED

There are several problems here.

First note that sin(x) == sin (x + 2*pi), so in order to 
compute the sin() of a value you need to know its
precision at a scale considerably less than 2*pi.

For large numbers, differences of 2*pi can get lost
in the low order bits of the floating point rep, or not
represented at all.  Taking the sin() of such imprecise
numbers is essentially meaningless.

For this reason, on the SGI platform, for any x > 2^50,
sin(x) returns 0, and errno is set to ERANGE.

In the test above, x > 2^50.  If all that is needed for
this
test is a wide int argument, then replacing x with some
value less than 2^50, but greater than 2^31 (thus wide)
should fix the test.

It is unfortunate that the SGI sin() function raises ERANGE
in this circumstance, I think it would make more sense
to raise EDOM.  Anyhow, the combination of ERANGE and
value == 0 gets interpreted by Tcl in TclExprFloatError()
as a floating point underflow ("floating-point value
too small
to represent"), but that's not accurate in this case. 
Would
be nice to get a better error message for this.
User Comments:
dkf added on 2003-02-19 21:11:19:
Logged In: YES 
user_id=79902

Really, for the purposes of what the test is testing, we
could (and, so it seems, should) use log() instead of sin().
The actual value returned doesn't matter in this case since
it is just checking explicit vs. implicit wide-to-double
conversions.