Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time.time() returns int rather than float #3125

Closed
Flameeyes opened this issue Jul 6, 2020 · 3 comments
Closed

time.time() returns int rather than float #3125

Flameeyes opened this issue Jul 6, 2020 · 3 comments
Labels
bug cpython api modules from cpython
Milestone

Comments

@Flameeyes
Copy link

Flameeyes commented Jul 6, 2020

In CPython 3.8 time.time() returns a floating point value. In CircuitPython 5.3 on Feather M4 and M0, it returns int (or rather a long integer).

time.monotonic() returns float though.

@Flameeyes
Copy link
Author

It appears this is behind a #define:

STATIC mp_obj_t mod_time_time(void) {
#if MICROPY_PY_BUILTINS_FLOAT
    struct timeval tv;
    gettimeofday(&tv, NULL);
    mp_float_t val = tv.tv_sec + (mp_float_t)tv.tv_usec / 1000000;
    return mp_obj_new_float(val);
#else
    return mp_obj_new_int((mp_int_t)time(NULL));
#endif
}

@dhalbert
Copy link
Collaborator

dhalbert commented Jul 6, 2020

STATIC mp_obj_t mod_time_time(void) {

This is only in ports/unix/modtime.c. The erroneous code returning an int is in
shared-bindings/time/__init__.c.

We do assume all CircuitPython impls have floats (but not longints).

@tannewt tannewt added bug cpython api modules from cpython labels Jul 13, 2020
@tannewt tannewt modified the milestones: 7.0.0, Long term Jul 13, 2020
@dhalbert
Copy link
Collaborator

A similar issue recently came up in adafruit/Adafruit_CircuitPython_datetime#29 and adafruit/Adafruit_CircuitPython_datetime#30. It is better to use an int because the precision of the 30-bit floats is so limited. I think we will not fix this for the reasons given in adafruit/Adafruit_CircuitPython_datetime#30.

@dhalbert dhalbert closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cpython api modules from cpython
Projects
None yet
Development

No branches or pull requests

3 participants