bugGNUstep - Bugs: bug #43722, Parsing of strings to double can...

Group
 
 

bug #43722: Parsing of strings to double can produce erroneous results

Submitter:  Sam Thompson <sthompso>
Submitted:  Fri 28 Nov 2014 05:19:30 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  In Test
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 02 Dec 2014 10:43:41 AM UTC, comment #2: 

Fantastic, thanks.

After applying the change, the provided test code now generates the following output, which looks correct:

String 50.6468746467461646 -> doubleValue = 50.646874646746163
String 50.64687464674616461 -> doubleValue = 50.646874646746163
String 0.646874646746164616898211 -> doubleValue = 0.64687464674616468
String 502.6468746467461646 -> doubleValue = 502.6468746467462
String 502.646874646746164 -> doubleValue = 502.6468746467462



Sam Thompson <sthompso>
Sat 29 Nov 2014 11:04:52 AM UTC, comment #1: 

Thanks ... I have made a change which should have fixed that in trunk now ... please give it a try and let me know how it looks.

Richard Frith-Macdonald <CaS>
Group Member
Fri 28 Nov 2014 05:19:30 PM UTC, original submission:  

When parsing strings representing decimals to doubles, for example via the use of [NSString doubleValue], the results can be completely incorrect if there are a large number of significant digits and there is a non-zero integer part.

Take the following examples, which are generated as stdout from the attached code in DoubleValueTest.m:
String 50.6468746467461646 -> doubleValue = 50.646874646746163
String 50.64687464674616461 -> doubleValue = 7.6972016867461646          *
String 0.646874646746164616898211 -> doubleValue = 0.64687464674616457
String 502.6468746467461646 -> doubleValue = 73.150145046746161          *
String 502.646874646746164 -> doubleValue = 502.6468746467462

With the example "0.646874646746164616898211", there are high number of significant digits, but the double value resulting from the parse at least resembles the string representation, I suspect there's truncation of the decimals.  However, with the example "50.64687464674616461", it has less significant digits but the resulting double from the parse does not even closely represent the string representation.


GNUStep version: 1.24.6
Platform: Windows
GCC: 4.7.2

Sam Thompson <sthompso>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #32567:  DoubleValueTest.m added by sthompso (1KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by sthompso (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-11-29 CaS StatusNone Fixed
        Open/ClosedOpen In Test
    2014-11-28 sthompso Attached File- Added DoubleValueTest.m, #32567

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code