CGPoint 的 x 或 y 值中的负 0

Negative 0 in CGPoint's x or y value

当 CGPoint 变量的零 x 或 y 值与 -1 相乘时,结果值为 -0。这是有意为之的行为吗?

我觉得这很奇怪,我花了很长时间才弄明白。我在 Xcode 8.3.2.

中使用 Swift 3.1

CGPoint 的xy 是CGFloats,这意味着它们是浮点标量值。而在浮点运算中,零也有符号,因此将它乘以负值会得到符号相反的零。

如需进一步阅读,您可以查看以下内容: https://developer.apple.com/reference/swift/floatingpointclassification https://en.wikipedia.org/wiki/Signed_zero