flaming.codes
flaming.codes

Reputation: 119

Negative 0 in CGPoint's x or y value

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

Answers (1)

user3581248
user3581248

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

Related Questions