swift - 为什么 Swift 报告 CGFloat.pi.significand 恰好是 pi/2?

标签 swift cgfloat mantissa

运行 Xcode 11.3

为什么 pi 的有效成分等于 pi/2?

print(CGFloat.pi.significand == CGFloat.pi/2).   // true

我期望有效值等于尾数。我错过了什么吗?

最佳答案

我们声明significand如下。

let magnitude = x.significand * F.radix ** x.exponent

我假设pi = 3.14 .

所以pi = 1.57 * 2 <sup>1</sup>哪里1.57significand .

如果我们将两边除以 2,您将得到 pi/2 = 1.57 .

换句话说pi/2 = pi.significand 。 (这是一种特殊情况)。

根据apple documentation ,

The significand is frequently also called the mantissa, but significand is the preferred terminology in the IEEE 754 specification, to allay confusion with the use of mantissa for the fractional part of a logarithm.

更新

正如 @Ptit 所提到的,2 到 4 之间的所有数字都满足参数 number/2 = number.significand .

关于swift - 为什么 Swift 报告 CGFloat.pi.significand 恰好是 pi/2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71686732/

相关文章:

ios - SwiftUI - 如何添加按钮作为导航标题?

ios - Swift - 将函数分配给工具栏按钮项

swift - 对类型推断背后机制的猜测

ios - 为什么 CGFloat 会补足有效数字?

c++ - 如何计算尾数位数?

matlab - 在 Matlab 中如何使用科学记数法(尾数和指数)中的变量?

time - 着色器时间统一 -clock_gettime 被截断

ios - 使用 Reactive Cocoa swift 验证文本字段

NSNumber floatValue 不等于 NSNumber 值

string - 在 Swift 中将 CGFloat 转换为字符串