NSString doubleValue returns 0.0 when it cant understand a floating point number

Originator:jeremytregunna
Number:rdar://11258810 Date Originated:16-Apr-2012 03:50 PM
Status:Behaves correctly Resolved:Yes
Product:iPhone SDK Product Version:All
Classification:Serious Bug Reproducible:Always
 
16-Apr-2012 03:50 PM Jeremy Tregunna:
Summary:
When passing the -doubleValue message to an NSString which does not contain a floating point representation, the value 0.0 is always returned. This is documented, but it is buggy behaviour. This hinders to some degree simple validation of input fields, as bad input can return 0.0 which is a valid representation as well. It is not possible to detect this case simply without introducing a number formatter. I believe this to be in error.

Steps to Reproduce:
1. Create an NSString without a floating point representation in it, such as @"foo"
2. Pass this string instance the doubleValue message.

Expected Results:
I expect the result of -doubleValue to return NAN in this case.

Actual Results:
The return value will be 0.0.

Regression:
None.

Notes:


16-Apr-2012 03:50 PM Jeremy Tregunna:
'DumbNSStringBehaviour.zip' was successfully uploaded

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!