Skip to content

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

Merged
tannewt merged 2 commits into
adafruit:2.xfrom
dhalbert:2.x_issue_342_time_monotonic
Oct 17, 2017
Merged

tannewt merged 2 commits into
adafruit:2.xfrom
dhalbert:2.x_issue_342_time_monotonic

Conversation

@dhalbert

@dhalbert dhalbert commented Oct 17, 2017 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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

tannewt commented Oct 17, 2017 via email

Copy link
Copy Markdown
Member

@dhalbert

Copy link
Copy Markdown
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