bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Sam Thompson
Subject: [bug #43722] Parsing of strings to double can produce erroneous results
Date: Fri, 28 Nov 2014 17:19:31 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36

URL:
  <http://savannah.gnu.org/bugs/?43722>

                 Summary: Parsing of strings to double can produce erroneous
results
                 Project: GNUstep
            Submitted by: sthompso
            Submitted on: Fri 28 Nov 2014 05:19:30 PM GMT
                Category: Base/Foundation
                Severity: 3 - Normal
              Item Group: Bug
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

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




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Fri 28 Nov 2014 05:19:30 PM GMT  Name: DoubleValueTest.m  Size: 1kB  
By: sthompso

<http://savannah.gnu.org/bugs/download.php?file_id=32567>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?43722>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]