math: revised timestamp calculations around epsilon

This commit is contained in:
itsmattkc
2022-05-29 11:13:05 -07:00
parent bbf6f8f9f9
commit 29908f2d8b
3 changed files with 33 additions and 3 deletions
+12 -2
View File
@@ -304,14 +304,24 @@ int64_t Timecode::time_to_timestamp(const double &time, const rational &timebase
return 0;
}
const double eps = 0.000000000001;
switch (floor) {
case kRound:
default:
return qRound64(d);
case kFloor:
return qFloor(d);
if (d > qCeil(d)-eps) {
return qCeil(d);
} else {
return qFloor(d);
}
case kCeil:
return qCeil(d);
if (d < qFloor(d)+eps) {
return qFloor(d);
} else {
return qCeil(d);
}
}
}