浮点变量值为1.000000和1.0常量比较相等吗?
答案是不相等,这涉及是精确度的问题,并且这样的比较很费时间,最好不要这样比较。只需要两者差的绝对值低于一定的值就认为相等就可以了。
NSLog(@"progress = %lf, !self.buffered:%d, (progress == 1.0):%d",progress, !self.buffered, (progress == 1.0)); self.progress = progress; //如果缓冲完了,拖动进度条不需要重新显示缓冲条 if (!self.buffered) { if (fabs(1.0 - progress) <= 0.001) { self.buffered = YES; [self.vpToolsView.activityIndicator stopAnimating]; self.vpToolsView.activityIndicator.hidden = YES; } [self.vpToolsView.bufferPV setProgress:progress]; } NSLog(@"yon = %@",self.buffered ? @"yes" : @"no");
打印日志
2021-04-30 14:28:10.086136+0800 光予露家长端[19904:3336931] progress = 1.000000, !self.buffered:1, (progress == 1.0):0