Mppl
Mppl

Reputation: 961

Making a calculation in objective c

I need a variable a = 6700000^2 * (a - b) (2 + sinf(a)+ s inf(b)), where a and b are floats between -7 to 7. I need all the precision that floats can give me.

Which data type should a be? Is the sinf the proper function to get the best precision out of a and b? And should a and b be in radians or degrees?


Well I Made a mistake when I posted the expression, the correct expression is c=67000000^2*(a-b)(2+sinf(a)+sinf(b)) and my problem is with c ."a" and "b" are floats and they are passed to me as floats, they really are coordinates (latitude and longitude) so thats not my concern... My concern is when using sinf on them do I lose any precision? And which type should c be so I don't lose precision cause I'm using a long double variable d to store a sum of multiple different c variables and d is returned to me as being zero and it shouldn't (sould be about 1 or 2 )so I was gessing I was losing some precision when calculating the c parcels...I was using c as being a double...can it be that I am losing some precision when calculating c?

Thank you very much for your help.

Upvotes: 3

Views: 270

Answers (3)

dgund
dgund

Reputation: 3467

Instead of using float, you should use a double if you want no worries in regards to memory. Remember to then change sinf() to sin() and use radians.

Upvotes: 1

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272802

I can't tell you whether float is good enough for your application. If you need more precision, use double, and then use sin() instead of sinf().

The standard trig functions take angles in radians, as you'll discover if you read the relevant documentation.

Upvotes: 3

Carl Norum
Carl Norum

Reputation: 225262

If you want the best precision without rolling your own types, you should use double rather than float. In that case, you can just use sin(3). According to the man page, you should pass the argument in radians.

Upvotes: 0

Related Questions