timecode = Timecode("30000/1001", "09:06:40;28")
float_roundtrip = Timecode("30000/1001", start_seconds=timecode.float)
print(float_roundtrip) # 09:06:40;27
Confusion about construction from floats is common enough that in the past the generally incorrect solution of simply rounding up has been proposed:
#22
It's especially unfortunate when it comes from floats produced by the library itself though. Since these issues are inherent to floating point arithmetic, what do you think about modifying/removing the .float getter in favor of e.g. a Decimal representation? That results in expected behavior for the above snippet. Users can unwrap the Decimal into a float at their own peril, but then it should be less surprising when they encounter strange behavior.
@property
def float(self) -> float:
"""Return the seconds as float.
Returns:
float: The seconds as float.
"""
return Decimal(self.frames) / Decimal(self._int_framerate)
There may also still be the need to use the fractional frame representation when available (#36). Happy to send a PR.
Confusion about construction from floats is common enough that in the past the generally incorrect solution of simply rounding up has been proposed:
#22
It's especially unfortunate when it comes from floats produced by the library itself though. Since these issues are inherent to floating point arithmetic, what do you think about modifying/removing the
.floatgetter in favor of e.g. aDecimalrepresentation? That results in expected behavior for the above snippet. Users can unwrap the Decimal into a float at their own peril, but then it should be less surprising when they encounter strange behavior.There may also still be the need to use the fractional frame representation when available (#36).Happy to send a PR.