Skip to content

Commit ead6b57

Browse files
committed
Use smaller epsilon on recent Python releases
1 parent 588fd66 commit ead6b57

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

timecode/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,20 @@ def float(self) -> float:
877877
epsilon = 1e-10 # This is much smaller than 1/framerate for any reasonable framerate
878878
return time_value + epsilon
879879

880+
if sys.version_info >= (3, 9):
881+
# Python 3.9+ supports math.nextafter, which we can use
882+
# to shift the float by the smallest possible amount
883+
@property
884+
def float(self) -> float:
885+
"""Return the seconds as float.
886+
887+
Returns:
888+
float: The seconds as float.
889+
"""
890+
import math
891+
time_value = float(self.frames) / float(self._int_framerate)
892+
return math.nextafter(time_value, math.inf)
893+
880894

881895
class TimecodeError(Exception):
882896
"""Raised when an error occurred in timecode calculation."""

0 commit comments

Comments
 (0)