简体   繁体   中英

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*(ab)(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.

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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM