-
Sun 2019.07.28
'I'm too lazy to test the result in JavaScript'
@AkosLukacs perfomed the how proof in #3 and #4
I explained the why in #19
'For me it doesn't look like there's any need to shift ones and zeros'
There isn't any bit masking in that example. It is a division proof using type casting in C.
Will work on the I2C slave example you posted:
Thank you for that suggestion
-
Ah, now I got it. That's why I asked @Robin what is this about. And reading the latest comment, turns out it's just a piece of random code...
Sooooooo, originally Semtech gives users a formula in chapter 4.1.4! you don't need 64 bit integer, or more precise FP, just do the math, and multiply with 0.016384! as @maze1980 already pointed out. And now 915e6 makes sense as well: 915MHz frequency.
Quick aside: a good compiler probably can optimize away the bit shift and division, so the programmer just leaves it there instead of manually calculating / simplifying the formula. And most likely easier to follow the code.
While
((uint64_t)val << 19) / 32000000
does no rounding, but you still have some loss in accuracy unless the number is an integer multiple of "32000000". The final result has only three bytes, as needed for the next steps.I'm too lazy to test the result in JavaScript using a 64 bit math module vs. normal numbers, but in C it is like this:
If you want to see more than "Hello World", "Done" change
b = (__uint64_t)((double)i * 0.016384);
tob = (__uint64_t)((float)i * 0.016384);
.For me it doesn't look like there's any need to shift ones and zeros. Think about it.
@AkosLukacs:
The source is most likely this file here, found by searching for "<< 19) / 32000000".
For the linked code: A 32 bit frequency value is taken as input, converted to 24 bit (three byte values) with a loss in accuracy of 8 bit.