用目标c进行计算

时间:2021-12-14 17:09:53

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.

我需要一个变量= 6700000 ^ 2 *(a - b)(2 + sinf(a)+ s正(b)),在a和b之间的浮点数7 - 7所示。我需要浮点数能给我的所有精度。

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?

a应该是哪种数据类型?sinf是得到a和b的最佳精度的合适函数吗?a和b应该是弧度还是角度?


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?

我犯了一个错误当我表达,正确的表达是c = 67000000 ^ 2 *(a - b)(2 + sinf(a)+ sinf(b))和c。我的问题是“一个”和“b”漂浮,漂浮他们传递给我,他们真的是坐标(经度和纬度)这不是我担心的…我担心的是,在使用sinf时,我是否会失去精度?和哪种类型c应该我不要失去精度造成使用长双变量d存储多个不同的和c变量和d返回给我是零,它不应该(应该是1或2)所以我充电器时我正在失去一些精度计算c包裹……我用c表示双重…是不是我在计算c的时候失去了一些精度?

Thank you very much for your help.

非常感谢你的帮助。

3 个解决方案

#1


1  

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.

不要使用浮点数,如果你不需要担心内存问题,你应该使用双精度浮点数。记住把sinf()换成sin()然后用弧度。

#2


3  

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

我不能告诉您float是否适合您的应用程序。如果需要更精确,请使用double,然后使用sin()代替sinf()。

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

标准三角函数以弧度表示角度,如果您阅读相关的文档就会发现这一点。

#3


0  

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.

如果您想要在不滚动自己的类型的情况下获得最佳的精度,您应该使用double而不是float。在这种情况下,你可以用sin(3)根据手册页,你应该用弧度来传递参数。

#1


1  

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.

不要使用浮点数,如果你不需要担心内存问题,你应该使用双精度浮点数。记住把sinf()换成sin()然后用弧度。

#2


3  

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

我不能告诉您float是否适合您的应用程序。如果需要更精确,请使用double,然后使用sin()代替sinf()。

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

标准三角函数以弧度表示角度,如果您阅读相关的文档就会发现这一点。

#3


0  

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.

如果您想要在不滚动自己的类型的情况下获得最佳的精度,您应该使用double而不是float。在这种情况下,你可以用sin(3)根据手册页,你应该用弧度来传递参数。