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

int and time.time() and precision #56

Closed
Cabalist opened this issue Nov 24, 2015 · 2 comments
Closed

int and time.time() and precision #56

Cabalist opened this issue Nov 24, 2015 · 2 comments
Labels

Comments

@Cabalist
Copy link
Contributor

Out of curiosity why is time cast as an int in your code?

Examples:

roughly L2009 in mycodo.py

while last_ht_reading > int(time.time()):
        time.sleep(0.25)

or

roughly L2038 in mycodo.py

last_ht_reading = int(time.time()) + 2

time.time() returns a float normally and python will add and compare ints and floats without issue.

It produce inexact results in timers as well.

Consider time.time() is 1448345968.99. Converted to an int that is 1448345968. It takes one time.sleep(0.25) to become 1448345969.

Now consider time.time() is 1448345968.01. Again converted to an int that is 1448345968. But it takes 4 time.sleep(0.25) to become 1448345969.

Your readings from the sensors could take ± .75 seconds here. Floats would alleviate the precision issue.

Just curious. :)

@kizniche
Copy link
Owner

Good question!

I went through all instances and can see no reason to do it. I suppose I may have had a problem in the past with it being a float, then never stopped casting it as an int for some reason.

@Cabalist
Copy link
Contributor Author

This seems to be fixed. Closing my issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants