奇怪的行为与stringWithFormat浮法

(lldb) po [NSString stringWithFormat:@"%.1f", 0.01] (id) $21 = 0x003a2560 19991592471028323832250853378750414848.0 (lldb) po [NSString stringWithFormat:@"%.1f", 0.1] (id) $22 = 0x0de92240 -0.0 

有没有人了解这里的行为? 我在设备上运行。

这是lldb的一个bug。 如果你在gdb尝试同样的东西,它可以正常工作。 我怀疑lldb只是传递参数的低32位。 0.01以及它打印的数字的IEEE表示如下:

 47ae147b3778df69 = 19991592471028323832250853378750414848.00 3f847ae147ae147b = 0.01 

请注意,0.01的低32位与另一个数的高32位相匹配。

这个bug也发生在printf

 (lldb) expr (void)printf("%.1f\n", 0.01) 19991592257096858016910903319197646848.0 <no result> 

这不会发生+[NSNumber numberWithDouble:]

 (lldb) po [NSNumber numberWithDouble:0.01] (id) $3 = 0x0fe81390 0.01 

所以我怀疑这个bug是由lldb处理可变参数函数造成的。

您可以在LLVM bugzilla和/或Apple的bug记者(又名rdar)上打开一个错误报告。