bugGNUstep - Bugs: bug #38640, GSScanDouble needs improvement

Group
 
 

bug #38640: GSScanDouble needs improvement

Submitter:  Larry Campbell <lcampbel>
Submitted:  Sun 31 Mar 2013 05:51:51 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 10 Apr 2013 10:07:07 PM UTC, comment #2: 

The main reason we can't use strtod is that its behavior is locale dependent, and we need locale independence here.

However, it was possible to make GSScanDouble more accurate ...

Richard Frith-Macdonald <CaS>
Group Member
Sun 31 Mar 2013 05:55:40 PM UTC, comment #1: 

More info:


We occasionally see things like this in the fpconfigloader log and in configuration change confirmation emails:

2012-06-26 16:12:51.402 fpconfigloader[15552]   Property "www" changed:
2012-06-26 16:12:51.402 fpconfigloader[15552]     loadImbalanceFactor changed: "1.9" => "1.9"

which is harmless but annoying. This turns out to be because the load imbalance factor comes from the portal as an integer string, "90", which is converted as follows:

[self setLoadImbalanceFactor:[NSNumber numberWithDouble:(((double)[[soap_property objectForKey:@"loadImbalanceFactor"] unsignedIntValue])/100.0) + 1.0]];

more concisely summarized as, essentially:

        x = 90 / 100.0 + 1.0;

which is 1.9, but that can't be represented exactly, and actually results in 1.8999999999999999.

The problem is that -[NSString doubleValue], which is used by FPFile.m when parsing stored dynamic config files, ends up calling GSScanDouble in NSScanner.m, which does not use atof or strtod, instead using its own home-grown parser that returns:

        1.9000000000000001

Larry Campbell <lcampbel>
Sun 31 Mar 2013 05:51:51 PM UTC, original submission:  

Is there any particular reason why GSScanDouble doesn't just use strtod? It produces slightly different results from strtod, which causes annoying problems when numbers that are expected to be equal turn out not to be.

Larry Campbell <lcampbel>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

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 lcampbel (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
    2013-04-10 CaS StatusNone Fixed
        Open/ClosedOpen Closed
        SummaryGSScanDouble should use strtod GSScanDouble needs improvement

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code