user7865437
user7865437

Reputation: 812

implicit conversion shortens 64 bit to 32 bit

Can someone explain why this causes the error stated in the title?

CGFloat dx = fabs(lastPoint.x - currentPoint.x);

Thanks

Upvotes: 2

Views: 3417

Answers (2)

Jean-Denis Muys
Jean-Denis Muys

Reputation: 6852

A better answer is to use #include <tgmath.h>. That header defines "adaptive" functions that call the correct function on whichever parameter size.

With that header included, you can simply call fabs without getting that warning (nor worrying about loss of precision caused by the use of the wrong function).

Upvotes: 2

Justin Spahr-Summers
Justin Spahr-Summers

Reputation: 16973

fabs() returns a double (64-bit), but CGFloat is defined to be a float (32-bit). It's generally harmless – I personally would even disable the compiler warning, as performing calculations using double values is typically at least as fast as using float values.

Upvotes: 3

Related Questions