Incorrect NSDecimalNumber conversion to int, long, long long
| Originator: | gwendal.roue | ||
| Number: | rdar://18661697 | Date Originated: | 10/15/2014 |
| Status: | Open | Resolved: | |
| Product: | iOS | Product Version: | 8.0.2 |
| Classification: | Data loss | Reproducible: | Always |
Summary: For some values of NSDecimalNumber, the intValue, longValue and longLongValue methods return incorrect results. Steps to Reproduce: Take this number for example: (lldb) po [[NSDecimalNumber decimalNumberWithString:@"227233333333333333333333333333333333324"] decimalNumberByMultiplyingByPowerOf10:-33] 227233.333333333333333333333333333333324 Let's take its double value: (lldb) p (double)[[[NSDecimalNumber decimalNumberWithString:@"227233333333333333333333333333333333324"] decimalNumberByMultiplyingByPowerOf10:-33] doubleValue] (double) $17 = 227233.33333333334 So far, so good. Let's take its longLongValue, on iOS simulator: (lldb) p (long long)[[[NSDecimalNumber decimalNumberWithString:@"227233333333333333333333333333333333324"] decimalNumberByMultiplyingByPowerOf10:-33] longLongValue] (long long) $14 = 0 <- incorrect Let's take its intValue: (lldb) p (long long)[[[NSDecimalNumber decimalNumberWithString:@"227233333333333333333333333333333333324"] decimalNumberByMultiplyingByPowerOf10:-33] intValue] (long long) $15 = 21475063713 <- incorrect Expected Results: The intValue, longValue and longLongValue methods should return 227233 Actual Results: The intValue, longValue and longLongValue methods return incorrect values. Version: iPad 2 running iOS8.0.2 (12A405), iOS Simulator running iOS8.0 (12A365), XCode Version 6.0.1 (6A317) Notes: Configuration: iPad 2 running iOS8.0.2 (12A405), iOS Simulator running iOS8.0 (12A365), XCode Version 6.0.1 (6A317)
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!