减去 2 个不同的双打结果为零
我正在构建一个基于 loc 的应用程序,使用 CLLocationManager 和 locationManager:didUpdateToLocation: fromLocation: 我正在尝试确定用户是否已移动到足以触发某些其他处理。 我正在使用双变量。我很久以前就学会了不要将双精度数等同起来,而是将增量与阈值进行比较。我将绝对值(旧 - 新)与 0.0005f 的增量进行比较,
但是此代码...
double latDelta = abs(theConsumer.latLong.clLocation.coordinate.latitude - newLocation.coordinate.latitude);
double lonDelta = abs(theConsumer.latLong.clLocation.coordinate.longitude - newLocation.coordinate.longitude);
NSString *fooBar = [NSString stringWithFormat:
@"???Delta LAT: abs(current (%f) - new (%f)) = delta %f.",
theConsumer.latLong.clLocation.coordinate.latitude,
newLocation.coordinate.latitude,
latDelta];
产生此输出:增量为零。
GPSLogger.m:(26)> GPSLOG:GPS:39.4425-北,77.8132-西/n MeterAccuracyFormat 0
GPSLogger.m:(26)> GPSLOG:找到新坐标:纬度:39.442494 经度:-77.813175 DataModel.m:(197)>距离地点:710.517020 DataModel.m:(199)>得到了 Delta > 0.000500 DataModel.m:(214)> Delta LAT:abs(当前 (39.440120) - 新 (39.442494)) = delta 0.000000。
数字已经满溢了吗?有没有更好的方法来做到这一点(即有效的方法)?
谢谢。
I'm building a loc-based app, using CLLocationManager and locationManager:didUpdateToLocation: fromLocation:
I'm trying to determine if the user has moved enough to trigger some other processing.
I'm using double variables. I learned long ago not to equate doubles, but to compare the delta to a threshold. I compare the abs( old - new ) to a delta of 0.0005f
But this code...
double latDelta = abs(theConsumer.latLong.clLocation.coordinate.latitude - newLocation.coordinate.latitude);
double lonDelta = abs(theConsumer.latLong.clLocation.coordinate.longitude - newLocation.coordinate.longitude);
NSString *fooBar = [NSString stringWithFormat:
@"???Delta LAT: abs(current (%f) - new (%f)) = delta %f.",
theConsumer.latLong.clLocation.coordinate.latitude,
newLocation.coordinate.latitude,
latDelta];
yields this output: delta is zero.
GPSLogger.m:(26)> GPSLOG: GPS: 39.4425- North, 77.8132- West/n MeterAccuracyFormat 0
GPSLogger.m:(26)> GPSLOG:New Coordinates found: Lat:39.442494 Lon:-77.813175
DataModel.m:(197)> DistanceFromLoc: 710.517020
DataModel.m:(199)> Got a delta > 0.000500
DataModel.m:(214)> Delta LAT: abs(current (39.440120) - new (39.442494)) = delta 0.000000.
Are the numbers overflowing? Is there a better way to do this (i.e. one that works)?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
abs()
返回一个int
;你想要fabs()
。(您还可以在 iOS/OS X 上使用
ABS()
宏,它返回一个类型为参数类型的值。)abs()
returns anint
; you wantfabs()
.(You can also use the
ABS()
macro on iOS/OS X which returns a value whose type is the type of the argument.)