discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Bug in [NSScanner scanDouble:]


From: Fred Kiefer
Subject: Re: Bug in [NSScanner scanDouble:]
Date: Tue, 29 Dec 2020 10:32:09 +0100

Looks like the code of GSScanDouble and [NSScanner scanDouble:] differ a lot. 
Both are in the file NSScanner.m and it looks like the function has been 
corrected over the years to handle different cases a lot better. The NSScanner 
code is just a straight forward number scanning as you would expect.

The easiest solution would be to reuse GSScanDouble by scanning in a buffer all 
the characters for the double value and calling the function on that value 
(handling _decimal by replacing it with a dot). But somehow this feels like the 
wrong way around. The code in NSScanner should have the correct implementation 
and GSScanDouble should  just call that. This solution would require to 
allocate and free an NSScanner object, and I am pretty sure that Richard 
wouldn’t like the extra time spend on that. I rather leave it to him to decide 
which way to go.

Fred

> Am 28.12.2020 um 23:27 schrieb Douglas Simons 
> <Doug.Simons@eggplantsoftware.com>:
> 
> Hi, sorry for posting a bug report here, but I seem to have lost my 
> credentials for accessing the bug tracker.
> 
> The scanDouble: method of NSScanner is adding a tiny fraction to the value 
> scanned (at least on Windows).
> 
> NSScanner *scanner = [NSScanner scannerWithString:@“197319600.000000”];
> double val = 0.0;
> [scanner scanDouble:&val];
> NSLog(@"scanDouble got: %.9f", val);
> // results in val having the value 197319600.00000012
> 
> Note that NSString’s doubleValue method doesn’t have this problem, so I’m 
> using that to work around this problem for now.
> 
> Thanks!
> 
> Doug




reply via email to

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