Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2005-05-11
02:07 • Ticket [532537ffff] Buggy Windows strtod() ? status still Closed with 2 othe... artifact: 1d7a8db2cd user: kennykb
02:07 • Ticket [532537ffff]: 5 changes artifact: df786ea60b user: kennykb
02:07 • Closed ticket [532537ffff]. artifact: b02b9d00b6 user: kennykb
2005-01-25
23:03 • Ticket [532537ffff]: 4 changes artifact: 61909bd2e6 user: kennykb
22:20 • Ticket [532537ffff]: 5 changes artifact: dca0fc4363 user: kennykb
2003-11-13
08:53 • Ticket [532537ffff]: 1 change artifact: 81069b7fef user: dgp
2002-03-25
20:09 • Ticket [532537ffff]: 4 changes artifact: d232206deb user: beric
17:51 • Open ticket [532537ffff]. artifact: 5a953a357a user: dkf
15:16 • Ticket [532537ffff]: 4 changes artifact: 378f268af7 user: beric
2002-03-23
07:09 • Pending ticket [532537ffff]. artifact: fb3f308700 user: hobbs
2002-03-20
16:03 • New ticket [532537ffff]. artifact: 158b1677bf user: nobody

Buggy Windows strtod() ?

Closed / Fixed532537ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 22 years ago
Descriptionplain2002-03-20 16:03:35
Try following script under Window NT:

proc testDouble {} {
    set a0 [expr {double(2.63624325102e-308)}]
    set b  [expr {double(0.19024736769)}]
    set a  $a0

    set count 30
    while {[incr count -1] > 0} {
        # just make a lose its double repr
        # string length $a
        puts "a = $a"
        set a [expr {$a*$b}]
    }
}

a is decreasing until 0.0.

Now uncomment the [string length] line, and try it
again. This gives the error message:
  can't use non-numeric string as operand of "*"
(Is it possible to have "floating-point value too
small to represent" ?)

This work fine under Linux. Can I conclude that my
Windows NT strtod() is buggy ?
hobbsplain2002-03-23 07:09:12
Logged In: YES 
user_id=72656

perhaps ... but I get the following on Win2K with a VC++6 
compiled 8.3.4 (ActiveTcl 8.3.4.2):

(tkcon) 50 % testDouble
a = 2.63624325102e-308
a = 5.01538339097e-309
a = 9.54163488088e-310
a = 1.81527091955e-310
a = 3.45350514088e-311
a = 6.57020262356e-312
a = 1.24996375432e-312
a = 2.37802313969e-313
a = 4.52412642615e-314
a = 8.60703143633e-315
a = 1.63746507553e-315
a = 3.1152341918e-316
a = 5.92665091618e-317
a = 1.12752993739e-317
a = 2.14509469586e-318
a = 4.08098223465e-319
a = 7.76374755875e-320
a = 1.47725628107e-320
a = 2.81123352484e-321
a = 5.33590897509e-322
a = 1.03753785627e-322
a = 1.97626258336e-323
a = 4.94065645841e-324
a = 0.0
a = 0.0
a = 0.0
a = 0.0
a = 0.0
a = 0.0
bericplain2002-03-25 15:16:29
Logged In: YES 
user_id=493507

Have you uncommented the [string length] line ?

% expr {double(4.94065645841e-324)}
floating-point value too small to represent
% expr {double(5.92665091618e-317)}
floating-point value too small to represent

with both AS 8.3.4.1 and 8.4a4 compiled with VC6
on two NT 4 station.
dkfplain2002-03-25 17:51:20
Logged In: YES 
user_id=79902

Can duplicate this in 8.3.4 under Solaris/SPARC as long as I
remember to uncomment the [string length] (which acts as a
complete destroyer of the double rep, as it converts to the
wide-character internal rep)
bericplain2002-03-25 20:09:07
Logged In: YES 
user_id=493507

Being surprised to found in <float.h>
#define DBL_MIN 2.2250738585072014e-308
I have tried a c code declaring two double:
  2.63624325102e-308
  5.01538339097e-309
It compile on both windows and linux, linux strtod()
works with both string repr, windows (VC6) fails with
errno == ERANGE for the second.

The following page show that doubles have normalized
and denormalized representation:
 http://babbage.cs.qc.edu/courses/cs341/IEEE-
754references.html
DBL_MIN is the minimum normalized double.

It looks like windows's strtod() doesn't work on
denormalized double, whereas linux does.
dgp Ticket [532537ffff]: 1 change [History diff]2003-11-13 08:53:17
kennykbplain2005-01-25 22:20:42
Logged In: YES 
user_id=99768

This problem is in the scope of TIP #132 -
 assigning it to myself.

The fix may be as simple as including 
strtod.obj in COMPAT_OBJS, depending on
whether compat/strtod.c has the same bug.
But depending on the native C library in this
area has proven to be a mistake; FP conversion
bugs have been recurrent.
kennykbplain2005-01-25 23:03:32
Logged In: YES 
user_id=99768

Nope, compat/strtod.c doesn't do denormals either - and it
fails silently,
which is worse.

% expr 2e-308
1.9999999999999998e-308
% expr 2.63624325102e-308
0.0

So we'll need to bite the bullet, fix this in compat/, and
promote the
fix to generic/.  I did *not* need to hear this, but I'm not
really surprised.
kennykb Closed ticket [532537ffff]. [History diff]2005-05-11 02:07:17
kennykbplain2005-05-11 02:07:18
Logged In: YES 
user_id=99768

The changes that implement TIP #132 fix this problem as a side
effect, so I'm going to close this out as "fixed in 8.5". 
An 8.4
backport is probably not worth the effort.
kennykb Ticket [532537ffff]: 2 changes [History diff]2005-05-11 02:07:19
Log in (anonymous is fine) to add a comment.