-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Avoid double precision floats in time.monotonic() computation to further increase flash space #342
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
Comments
nice! |
Dan, I'm probably misunderstanding what this is doing, but 2^32 = 4294967296 which requires more precision than can be expressed in a float, correct? So when it is multiplied by the upper portion of the time, isn't information lost? Does this essentially make the time.monotonic value only valid for the lower 32bits of the counter? |
Perhaps I am overthinking this, but the case I am concerned about if when two captures of time.monotonic differ in the lower portion of the upper 32bit word. Will differences of these time tags be valid? |
(I was going to mention this last night, but was too tired.) There is a precision problem with In CPy/MPy, the lower two bits are truncated, and are used for flag bits to differentiate pointers, ints and floats. So its floats are stored in 30 bits: one sign bit, 8 bits of exponent, and 22 preicison bits (21 physically).
Note that 2^22 (4194304) msecs is only about 1.165 hours. @jerryneedell
prints
The @tannewt asked in the pull request (#343) if I could distribute the division among the two halves. The precision is still lost due to single-precision floating point. So I don't believe it will make a difference:
|
Dan, I was concerned that it would add some discontinuity to time.monotonic. |
Okay - You have convinced me that since you really want the value to exactly 4294967296.000000 - you are OK and there will be no issues until the multiplicand gets very large and you get truncation but that is unavoidable. Thanks for the clarifications and all the work to save memory. Clever stuff! |
This sounds perfectly fine to me! If we start changing the millisecond
fraction every other tick after an hour that seems plenty accurate to me.
…On Tue, Oct 17, 2017 at 6:49 AM jerryneedell ***@***.***> wrote:
Okay - You have convinced me that since your really want the value to
exactly 4294967296.000000 - you are OK and there will be no issues until
the multiplicand gets very large and you get truncation but that is
unavoidable. Thanks for the clarifications and all the work to save memory.
Clever stuff!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#342 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADNqU4OWCsfm-huTt5Z5rrfuaSq69G5ks5stLBWgaJpZM4P7irV>
.
|
Implemented in PR #343. |
time.monotonic()
was dividing a 64-bit uint by 1000.0f. This caused the compiled code toinclude_aeabi_u2lf()
, which convertslong long
tofloat
. In the processul2f
calls double-precision routines. I thought I had gotten rid of these by #325, but not completely.I changed the arithmetic to break the 64-bit int into two pieces: multiply the top part by 2.0^32f and add it to the bottom part, then divide by 1000.0f. This avoids
ul2f
and there are no more double routines left in the image except the tiny _aeabi_d2f()`.This gains back 3044 bytes!!
The text was updated successfully, but these errors were encountered: