Reputation: 119
When multiplying a zero x or y value of a CGPoint variable with -1, the resulting value is -0. Is this intended behavior?
I think that's odd, it took me quite some time to find that out. I use Swift 3.1 in Xcode 8.3.2.
Upvotes: 1
Views: 534
Reputation: 1014
CGPoint's x
and y
are CGFloats, which means they are floating point scalar values. And in floating point arithmetic, zero also has a sign, so that multiplying it by a negative value results in a zero with opposite sign.
For further reading you can check these: https://developer.apple.com/reference/swift/floatingpointclassification https://en.wikipedia.org/wiki/Signed_zero
Upvotes: 2