我正在编写具有那段代码的应用程序,其中 t->tick 是浮动的:
usleep(1000);
t->tick = t->tick + 0.001;
printf("tick is %f, firing time is %f\n", t->tick, t->firing_time);
我发现usleep有错误?:
tick is 0.313000, firing time is 2.000000
tick is 0.314000, firing time is 2.000000
tick is 0.314999, firing time is 2.000000
tick is 0.315999, firing time is 2.000000
如何摆脱该错误?