Duck
Duck

Reputation: 36003

iOS - differences between results

I have this discrepancy between two values that have to be the same...

#define degreesToRadian(x) (M_PI * x / 180.0f)

... 
CGFloat angle = -3.0f;
CGFloat beta = degreesToRadian(90.0f - fabsf(angle));

CGFloat delta = (90.0f - fabsf(angle)) * M_PI /180.0f;

at this point I get beta = 282.72 and delta = 1.51 ?

Both values have to be the same!

why is that?

Upvotes: 0

Views: 83

Answers (1)

Paul R
Paul R

Reputation: 213110

Your macro is broken - change:

#define degreesToRadian(x) (M_PI * x / 180.0f)

to:

#define degreesToRadian(x) (M_PI * (x) / 180.0f)

NB: this is yet another example of why you should not use the preprocessor for this kind of thing. C and Objective C have had inline functions for 20 years now - you should make use of them.

Upvotes: 1

Related Questions