objective-c - Cocoa:尾数和指数为 0 的 NSDecimalNumber

标签 objective-c cocoa exponent nsdecimalnumber mantissa

从数学上讲,任何指数为 0 的数字都应该等于 1(我的数学补习研究向我保证)。

但是这段代码产生 5:

[NSDecimalNumber decimalNumberWithMantissa:5 exponent:0 isNegative:NO]

这是计算机编程中的标准吗——可以相信在未来的 Cocoa 版本中不会被“纠正”?

最佳答案

您可能还没有阅读documentation for decimalNumberWithMantissa:exponent:isNegative:

指数与尾数的 10 倍数有关。

您必须了解尾数是点右侧的值。

数字标准化后的值如下:18.23 = 0.1823x10^2 --> 尾数 == 1823,指数 == 2

看看它如何使用。

Discussion

The arguments express a number in a kind of scientific notation that requires the mantissa to be an integer. So, for example, if the number to be represented is –12.345, it is expressed as 12345x10^–3—mantissa is 12345; exponent is –3; and isNegative is YES, as illustrated by the following example.

NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithMantissa:12345

                                           exponent:-3

                                           isNegative:YES];

干杯,
VFN

PS:查看维基百科上的文章:浮点运算标准 (IEEE 754 - 2008)。

关于objective-c - Cocoa:尾数和指数为 0 的 NSDecimalNumber,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2056411/

相关文章:

java - 自定义数学函数与提供的数学函数?

javascript - Javascript中非整数幂的负数

ios - 如何检查 UIButton 上文本的颜色?

macos - 我可以通过编程判断 Spotlight 是否已启用吗?

objective-c - NSString stringWithFormat 中的 `size_t`

java - Java Biginteger 在 pow 中的最大值

ios - dequeueReusableCellWithIdentifier 创建重复的 UITableviewcell

ios - Cocos2d 中的无限水平滚动

objective-c - 在 switch block 中实例化新对象 - 为什么会失败?

objective-c - 回应二传手