Skip to content

redo time.monotonic() to avoid double precision #343

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

Merged
merged 2 commits into from
Oct 17, 2017

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Oct 17, 2017

Gains back 3044 bytes! Framebuf would now fit in non-Express, with 56 bytes to spare, before any -finline-limit trickery. Implements #342.

@dhalbert dhalbert changed the title redo time.monotonic() to avoid double precision; turn framebuf and nmv on in non-express redo time.monotonic() to avoid double precision Oct 17, 2017
return mp_obj_new_float(common_hal_time_monotonic() / 1000.0);
uint64_t time64 = common_hal_time_monotonic();
// 4294967296 = 2^32
return mp_obj_new_float(((uint32_t) (time64 >> 32) * 4294967296.0f + (uint32_t) (time64 & 0xffffffff)) / 1000.0f);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does precision change with this? Would we get more precision by dividing by 1000.0f earlier?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could distribute the division among the two halves, but the precision is still lost due to single-precision floating point. So I don't believe it will make a difference:

>>> (2.0**22+1)/1000 - (2.0**22+0)/1000 
0.0
>>> (2.0**22+2)/1000 - (2.0**22+1)/1000 
0.00195313
>>> (2.0**22+3)/1000 - (2.0**22+2)/1000 
0.0
>>> (2.0**22+4)/1000 - (2.0**22+3)/1000 
0.00195313
>>> 

@tannewt
Copy link
Member

tannewt commented Oct 17, 2017 via email

@dhalbert
Copy link
Collaborator Author

Deferring is fine with me, to 2.2 or 3.0. Limor would like to change the font in framebuf from 8x8 to 8x5 anyway.

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

Successfully merging this pull request may close these issues.

2 participants