C# 目标c因为sin返回的结果不同
我需要你在操作系统开发方面的帮助。我将C#应用程序转换为Objective-C。iOS返回不同的结果: 在iOS中的结果:C# 目标c因为sin返回的结果不同,c#,ios,objective-c,math,C#,Ios,Objective C,Math,我需要你在操作系统开发方面的帮助。我将C#应用程序转换为Objective-C。iOS返回不同的结果: 在iOS中的结果: gety:-0.000048 标题x:-0.000087 iOS源代码: double rlatitude1 = [self toRadians:startLocation.latitude]; double rlongitude1 = [self toRadians:startLocation.longitude]; double rlatitude2 = [self
gety:-0.000048
标题x:-0.000087 iOS源代码:
double rlatitude1 = [self toRadians:startLocation.latitude];
double rlongitude1 = [self toRadians:startLocation.longitude];
double rlatitude2 = [self toRadians:endLocation.latitude];
double rlongitude2 = [self toRadians:endLocation.longitude];
double y = sin(rlongitude2- rlongitude1) * cos(rlatitude2);
NSLog([NSString stringWithFormat:@"GetHeading y: %f",y]);
double x = cos(rlatitude1) * sin(rlatitude2) - sin(rlatitude1) * cos(rlatitude2) * cos(rlongitude2 - rlongitude1);
NSLog([NSString stringWithFormat:@"GetHeading x: %f",x]);
iOS圆环代码:
+(double) toRadians:(double) degree
{
double retVal = (degree * 0.0174532925);
NSLog([NSString stringWithFormat:@"toRadians: %f",retVal]);
return retVal;
}
FYI-不要将
stringWithFormat
与NSLog
一起使用,这是多余的。只需执行:NSLog(@“GetHeading y:%f”,y)
。y
的结果相同<代码>-0.000048和-4.8E-05
是相同的数字。使用断点检查retVal的值,而使用%f打印它可能会将其转换为用于打印的浮点,并将0.0174532925
替换为M_PI/180
。将NSLogs中的%f
替换为.15e
。