[issue39484] time_ns() and time() cannot be compared on windows

STINNER Victor report at bugs.python.org
Mon Feb 3 09:47:56 EST 2020


STINNER Victor <vstinner at python.org> added the comment:

I'm not sure which kind of problem you are trying to solve here. time.time() does lose precision because it uses the float type. Comparing time.time() and time.time_ns() tricky because of that. If you care of nanosecond precision, avoid float whenever possible and only store time as integer.

I'm not sure how to compat time.time() float with time.time_ns(). Maybe math.isclose() can help.

I don't think that Python is wrong here, time.time() and time.time_ns() work are expected, and I don't think that time.time() result can be magically more accurate: 1580301619906185300 nanoseconds (int) cannot be stored exactly as floating point number of seconds.

I suggest to only document in time.time() is less accurate than time.time_ns().

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39484>
_______________________________________


More information about the Python-bugs-list mailing list