Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-11-10
13:56 • Closed ticket [85ce4bf928]: binary format R Inf stores FLT_MAX plus 7 othe... artifact: 0d0318ebc8 user: jan.nijtmans
2022-11-05
10:08
Fix for [85ce4bf928]: binary format R Inf] stores FLT_MAX check-in: 48706a2425 user: jan.nijtmans tags: core-8-branch
2022-11-02
15:06 • Ticket [85ce4bf928] binary format R Inf stores FLT_MAX status still Open w... artifact: 93e86f2f9a user: jan.nijtmans
15:00
Proposed fix for [85ce4bf928]: Fix for problems with storing Inf with [binary format R] closed check-in: 20959e0da2 user: jan.nijtmans tags: bug-85ce4bf928
2016-11-10
13:01 • Ticket [85ce4bf928] binary format R Inf stores FLT_MAX status still Open w... artifact: c56e1999c0 user: aspect
2015-05-16
05:51 • Ticket [1670783fff] binary man page missing Inf/NaN ref status still Open wi... artifact: c3ee43e2b2 user: dkf
2015-05-15
22:17 • Ticket [85ce4bf928] binary format R Inf stores FLT_MAX status still Open w... artifact: 7bd484521b user: dkf
22:14
[85ce4bf928] Fix for problems with storing Inf with [binary format R]. check-in: 21866fab39 user: dkf tags: bug-85ce4bf928
2015-03-17
12:01 • Ticket [85ce4bf928] binary format R Inf stores FLT_MAX status still Open w... artifact: d9e89537bb user: dkf
2015-02-20
23:02 • Ticket [85ce4bf928]: 4 changes artifact: 6a072f6b9e user: anonymous
23:00 • Add attachment aspect-binary-float-inf.fbun to ticket [85ce4bf928cd9a40... artifact: d63c3c2716 user: anonymous
2015-02-04
18:18 • Ticket [85ce4bf928] binary format R Inf stores FLT_MAX status still Open w... artifact: 6e6905b4e2 user: dgp
18:14 • Ticket [85ce4bf928]: 4 changes artifact: b87cfdf45c user: dgp
18:10 • Ticket [85ce4bf928]: 4 changes artifact: 035c4feada user: dgp
18:03 • Ticket [85ce4bf928]: 4 changes artifact: d1f53302e6 user: dgp
15:43 • Ticket [85ce4bf928]: 4 changes artifact: b1718f14da user: dgp
15:21 • Ticket [85ce4bf928]: 4 changes artifact: 089b6e5d66 user: dgp
15:15 • Ticket [85ce4bf928]: 4 changes artifact: 8616f05c52 user: dgp
15:12 • Ticket [85ce4bf928]: 4 changes artifact: ee2071a2ce user: dgp
2015-02-02
08:21 • New ticket [85ce4bf928]. artifact: 26ff2520d3 user: anonymous

[binary format R Inf] stores FLT_MAX

Closed / Fixed85ce4bf928cd9a40064aa5b36e7033184dd5379aCreated 12 years agoUpdated 4 years ago
Descriptionplain2015-02-02 08:21:54
% 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.
Referenced by4
  • 48706a2425Fix for [85ce4bf928]: binary format R Inf] stores FLT_MAX check-in2022-11-05 10:08:36
  • 20959e0da2Proposed fix for [85ce4bf928]: Fix for problems with storing Inf with [binary format R] check-in2022-11-02 15:00:38
  • c3ee43e2b2Ticket [1670783fff] binary man page missing Inf/NaN ref status still Open with 4 other changes ticket2015-05-16 05:51:19
  • 21866fab39[85ce4bf928] Fix for problems with storing Inf with [binary format R]. check-in2015-05-15 22:14:32
dgpplain2015-02-04 15:12:30
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
dgpplain2015-02-04 15:15:50
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
dgpplain2015-02-04 15:21:35
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
dgpplain2015-02-04 15:43:29
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
dgpplain2015-02-04 18:03:16
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
dgpplain2015-02-04 18:10:28
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
dgpplain2015-02-04 18:14:59
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
dgpplain2015-02-04 18:18:08
The patch changes the expected result of
existing tests in the test suite, so I'd
prefer to have a review from kbk.
anonymous (claiming to be aspect)plain2015-02-20 23:02:20
fossil bundle attached to this ticket.
dkf Ticket [85ce4bf928]: 3 changes [History diff]2015-03-17 12:01:32
dkfwiki2015-05-15 22:17:16

Imported as branch bug-85ce4bf928 (see [21866fab39])

aspectplain2016-11-10 13:01:19
As another data point, the same is not true of doubles:

% binary scan [binary format q Inf] q x
1
% set x
Inf
jan.nijtmanswiki2022-11-02 15:06:58

Rebased to core-8-branch: [20959e0da2451a45]

jan.nijtmanswiki2022-11-10 13:56:50

Fixed [here]. Since it depends on C99, the fix will not be in 8.6, but in 8.7

Log in (anonymous is fine) to add a comment.