bugGNUstep - Bugs: bug #38640, GSScanDouble needs improvement


You are not allowed to post comments on this tracker with your current authentication level.

bug #38640: GSScanDouble needs improvement

Submitted by:  Larry Campbell <lcampbel>
Submitted on:  Sun 31 Mar 2013 05:51:51 PM UTC  
Category: Base/FoundationSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

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>
Project 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:


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>


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 10 Apr 2013 10:07:07 PM UTCCaSStatusNone=>Fixed
      SummaryGSScanDouble should use strtod=>GSScanDouble needs improvement

    Back to the top

    Powered by Savane 3.1-cleanup1