Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 26ff2520d31873da87484e07bde183576915e459
Ticket: 85ce4bf928cd9a40064aa5b36e7033184dd5379a
[binary format R Inf] stores FLT_MAX
User & Date: anonymous on 2015-02-02 08:21:54
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    % binary scan [binary format R Inf] R x
    % set x
    3.4028234663852886e+38
    
    This is FLT_MAX - see the bit pattern described near the bottom of http://wiki.tcl.tk/41088
    
    The issue seems to be the test at http://core.tcl.tk/tcl/artifact/fee105a45aaf25a3?ln=1915-1917
    
    By my reading, the condition should become:
    
        if (!isinf(dvalue) && (fabs(dvalue) > (double)FLT_MAX))
    
    In the chat, kbk adds:
    
    If the float64 is less than FLT_MAX + 1/2 ulp, then it's not a 'true' overflow, and it should [binary format] to FLT_MAX. Greater than that, and it should be Inf.
    
    Exact FLT_MAX + 1/2 ulp should round to FLT_MAX (round to even).
    
    I have implemented a fix in http://chiselapp.com/user/aspect/repository/tcl/timeline?r=aspect-binary-float-inf
    
    The first checkin http://chiselapp.com/user/aspect/repository/tcl/ci/f4d7334db9 corrects behaviour for Inf/-Inf only, and adds some tests.
    
    Following checkins follow kbk's advice (I hope!) to correct out-of-range rounding behaviour, but with some questionable aspects:
    
      * c99 reliance for INFINITY
      * FLT_MAX+1/2ulp is calculated with an expression I don't entirely trust
      * changes results (!!) of some existing tests which expect rounding to FLT_MAX
    
    The included tests should be complete, but those in the 3rd checkin don't conform to conventions of their neighbours.
    
    Another way to create FLT_MAX+1/2ulp for comparison would be as follows, though I can't vouch for its portability.
    
        /* smallest double that should round to +Inf */
        double flt_min_inf {} {
            uint64_t bits = 0x47effffff0000001;
            return *(double*)&bits;
        }
    
        /* largest double that should round to FLT_MAX */
        double flt_max_dbl {} {
            uint64_t bits = 0x47effffff0000000;
            return *(double*)&bits;
        }
    
    Let me know if there's anything I can do to make this patch easier to consume.
    
  5. foundin changed to: "8.6.3"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "cb02a4a25e8da92f2790bc307bf01ef24ce6053e"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "48. Number Handling"
  15. title changed to: "[binary format R Inf] stores FLT_MAX"
  16. type changed to: "Bug"